소스 검색

Added the ability to create a customer

Evgeniy Zverev 1 년 전
부모
커밋
6d1118b0de
2개의 변경된 파일85개의 추가작업 그리고 24개의 파일을 삭제
  1. 0 24
      compose/bin/admin-user-create
  2. 85 0
      compose/bin/create-user

+ 0 - 24
compose/bin/admin-user-create

@@ -1,24 +0,0 @@
-#!/usr/bin/env bash
-
-USERNAME="admin"
-EMAIL="admin@example.com"
-FIRSTNAME="Admin"
-LASTNAME="Admin"
-PASSWORD="Admin123"
-
-bin/magento admin:user:create \
-    --admin-user=${USERNAME} \
-    --admin-password=${PASSWORD} \
-    --admin-email=${EMAIL} \
-    --admin-firstname=${FIRSTNAME} \
-    --admin-lastname=${LASTNAME}
-
-if [ $? -eq 0 ]; then
-    echo "Username: ${USERNAME}"
-    echo "Email: ${EMAIL}"
-    echo "Firstname: ${FIRSTNAME}"
-    echo "Lastname: ${LASTNAME}"
-    echo "Password: ${PASSWORD}"
-else
-    echo "Error creating admin user."
-fi

+ 85 - 0
compose/bin/create-user

@@ -0,0 +1,85 @@
+#!/usr/bin/env bash
+
+# Function to create admin user
+create_admin_user() {
+  USERNAME="admin"
+  EMAIL="admin@example.com"
+  FIRSTNAME="Admin"
+  LASTNAME="Admin"
+  PASSWORD="Admin123"
+
+  bin/magento admin:user:create \
+      --admin-user=${USERNAME} \
+      --admin-password=${PASSWORD} \
+      --admin-email=${EMAIL} \
+      --admin-firstname=${FIRSTNAME} \
+      --admin-lastname=${LASTNAME}
+
+  if [ $? -eq 0 ]; then
+      echo "Admin account created successfully."
+      echo "Username: ${USERNAME}"
+      echo "Email: ${EMAIL}"
+      echo "Firstname: ${FIRSTNAME}"
+      echo "Lastname: ${LASTNAME}"
+      echo "Password: ${PASSWORD}"
+  else
+      echo "Error creating admin user."
+  fi
+}
+
+# Function to create customer account
+create_customer_account() {
+  EMAIL=${EMAIL:-"customer@example.com"}
+  PASSWORD=${PASSWORD:-"customer123QWERTY"}
+  FIRSTNAME=${FIRSTNAME:-"Customer"}
+  LASTNAME=${LASTNAME:-"Customer"}
+
+  bin/n98-magerun2 customer:create ${EMAIL} ${PASSWORD} ${FIRSTNAME} ${LASTNAME} ${WEBSITE}
+
+  if [ $? -eq 0 ]; then
+      echo "Customer account created successfully."
+      echo "Email: ${EMAIL}"
+      echo "Firstname: ${FIRSTNAME}"
+      echo "Lastname: ${LASTNAME}"
+      echo "Password: ${PASSWORD}"
+  else
+      echo "Error creating customer account."
+  fi
+}
+
+# Check if n98-magerun2.phar exists, if not download and install
+if ! bin/cliq ls bin/n98-magerun2; then
+  echo "Checking if n98-magerun2.phar exists, just a moment..."
+  bin/clinotty curl -sS -O https://files.magerun.net/n98-magerun2.phar
+  bin/clinotty curl -sS -o n98-magerun2.phar.sha256 https://files.magerun.net/sha256.php?file=n98-magerun2.phar
+  bin/clinotty shasum -a 256 -c n98-magerun2.phar.sha256
+  [ $? != 0 ] && echo "sha256 checksum do not match!" && exit
+
+  bin/cliq chmod +x n98-magerun2.phar
+  bin/cliq mkdir -p bin
+  bin/cliq mv n98-magerun2.phar bin
+fi
+
+# Prompt user for type of account to create
+read -p "Do you want to create an admin (A) or a customer (C) account? [A/C]: " account_type
+
+if [[ "$account_type" == "A" || "$account_type" == "a" ]]; then
+    create_admin_user
+elif [[ "$account_type" == "C" || "$account_type" == "c" ]]; then
+    read -p "Do you want to use default values for customer account? (Y/N): " use_defaults
+    if [[ "$use_defaults" == "Y" || "$use_defaults" == "y" ]]; then
+        create_customer_account
+    elif [[ "$use_defaults" == "N" || "$use_defaults" == "n" ]]; then
+        read -p "Enter customer email: " EMAIL
+        read -p "Enter customer password: " PASSWORD
+        read -p "Enter customer firstname: " FIRSTNAME
+        read -p "Enter customer lastname: " LASTNAME
+        read -p "Enter customer website: " WEBSITE
+        create_customer_account
+    else
+        echo "Invalid option. Please choose either Y or N."
+    fi
+else
+    echo "Invalid option. Please choose either A or C."
+fi
+