-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added magento 2 auto admin login feature
- Loading branch information
Showing
7 changed files
with
122 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
#!/bin/bash | ||
[[ ! ${ROLL_DIR} ]] && >&2 echo -e "\033[31mThis script is not intended to be run directly!\033[0m" && exit 1 | ||
|
||
ROLL_ENV_PATH="$(locateEnvPath)" || exit $? | ||
loadEnvConfig "${ROLL_ENV_PATH}" || exit $? | ||
assertDockerRunning | ||
|
||
## allow return codes from sub-process to bubble up normally | ||
trap '' ERR | ||
|
||
if [[ "${ROLL_ENV_TYPE}" != "magento2" ]]; then | ||
boxerror "This command is only working for Magento 2 projects" && exit 1 | ||
fi | ||
|
||
echo "Confirming n98-magerun2 is installed..." | ||
"${ROLL_DIR}/bin/roll" magerun > /dev/null 2>&1 | ||
|
||
|
||
LOCALADMIN_EXISTS=$("${ROLL_DIR}/bin/roll" magerun admin:user:list | grep "localadmin") | ||
|
||
|
||
if [[ -z "$LOCALADMIN_EXISTS" ]]; then | ||
echo "Setup user account localadmin..." | ||
"${ROLL_DIR}/bin/roll" magerun admin:user:create --admin-user "localadmin" --admin-password "admin123" --admin-email "localadmin@roll.test" --admin-firstname "Local" --admin-lastname "Admin" | ||
fi | ||
|
||
echo "Force google as default TFA Provider" | ||
"${ROLL_DIR}/bin/roll" magento config:set twofactorauth/general/force_providers google | ||
|
||
echo "Setting autologin 2fa code" | ||
"${ROLL_DIR}/bin/roll" magento security:tfa:google:set-secret localadmin "LAJWZZTAI4KAHY7NBS6NOM3BDZK62IPDT3U5ARGXCJ4WVG7PJSG37FC4XODYWV2UNYMQG3LVMEUTIHO52FQGZU4Z462VNWYKPOM23M2YZNWAJW732RTNAVTQ2APUV64BPBJZKT7I4CAT62KLFEP5DZLWINPZ3JVOWJ6CPOAA77RSFK2PAG6YPS4VP55WYX5BPTX4Z7P6EZ4CY" | ||
|
||
echo -e "\n-------------------------------" | ||
printf "\n\nDone!\n\nNow you need to set\n\n ROLL_ADMIN_AUTOLOGIN=1\n\nin your .env.roll configuration\n\n!!!!!\nIf you executed this command due to the admin popup modal\nthen just refresh the login page!\n!!!!!\n\n\n" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
#!/usr/bin/env bash | ||
[[ ! ${ROLL_DIR} ]] && >&2 echo -e "\033[31mThis script is not intended to be run directly!\033[0m" && exit 1 | ||
|
||
ROLL_USAGE=$(cat <<EOF | ||
\033[33mUsage:\033[0m | ||
setup-autologin - setup autologin to magento admin when visiting admin url | ||
\033[33mOptions:\033[0m | ||
-h, --help Display this help menu | ||
EOF | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,3 @@ | ||
# Change Log | ||
# Change Log | ||
|
||
See the full change log in GitHub: [https://github.com/dockergiant/rolldev/releases](https://github.com/dockergiant/rolldev/releases) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
# Setup Admin Auto Login in Magento 2 | ||
|
||
|
||
|
||
Enabling admin auto-login in Magento 2 can be a great time-saver for developers. By setting a specific environment variable and using a command-line tool, you can bypass the manual login process. This guide will walk you through enabling this feature safely in a development environment. | ||
|
||
#### Prerequisites | ||
|
||
- Access to the command line or terminal. | ||
- Administrative access to your Magento 2 project files. | ||
- The `roll` command-line tool installed in your development environment. | ||
|
||
#### Step 1: Configure Your Environment File | ||
|
||
1. **Locate Your `.env.roll` File**: This file should be in the root of your Magento 2 project. | ||
|
||
2. **Set the ROLL_ADMIN_AUTOLOGIN Variable**: | ||
- Open the `.env.roll` file in your text editor. | ||
- Add or modify the following line: | ||
``` | ||
ROLL_ADMIN_AUTOLOGIN=1 | ||
``` | ||
- Save the changes. This tells the auto-login mechanism to activate within your development environment. | ||
3. restart containers by executing this in your project root | ||
``` | ||
roll env up | ||
``` | ||
#### Step 2: Generate a Local User for Auto-Login | ||
1. **Open Your Terminal**: Navigate to the root directory of your Magento 2 project. | ||
2. **Run the Setup Command**: Execute the following command: | ||
``` | ||
roll setup-autologin | ||
``` | ||
This command generates a local user in your Magento 2 database, configured for auto-login. Follow any prompts to complete the setup, which may involve specifying a username or password, though typically it will create a default user for you. | ||
#### Step 3: Verify Auto-Login Functionality | ||
- After completing the setup, navigate to your Magento 2 admin URL in your web browser. If configured correctly, you should be logged into the admin dashboard automatically without the need to enter login credentials. | ||
#### Step 4: Disable Auto-Login (Important for Production) | ||
- **For Security Reasons**: Remember to disable this feature before moving your project to a staging or production environment. You can disable it by setting: | ||
``` | ||
ROLL_ADMIN_AUTOLOGIN=0 | ||
``` | ||
in your `.env.roll` file, then running any necessary deployment commands for your environment. | ||
#### Security Considerations | ||
- **Development Only**: This auto-login method should only be used in a local or secure development environment. Never use or enable auto-login in production, as it poses a significant security risk. | ||
- **Access Control**: Ensure that your development environment is not accessible from the internet or by unauthorized users. | ||
This tutorial assumes you're familiar with basic Magento 2 and shell/command line operations. Adjustments may be necessary based on your specific development setup or Magento version. Always consult your development team or Magento documentation for best practices tailored to your project. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters