instant-login/instant-login.yaml

79 lines
2.3 KiB
YAML
Raw Normal View History

2023-01-22 04:11:01 +00:00
type: update
name: Instant Login
description: Login to your WordPress site as an administrator with a single click.
targetNodes:
nodeGroup: cp
onInstall:
cmd [cp]:
- cd /var/www/webroot/ROOT/
- wp package install aaemnnosttv/wp-cli-login-command
- wp login install --yes --activate
setGlobals:
userToLoginAs: 1
actions:
instant_login:
#log: ${placeholders}
cmd [cp]:
- cd /var/www/webroot/ROOT/
- wp login create ${globals.userToLoginAs} --url-only
#- user=$(wp user list --field=user_login --format=csv)
#- wp login create $user --url-only
return:
type: success
message: |
[Click to login](${response.out})
*(Link will expire in 15 minutes)*
save_config:
#empty method to allow userToLoginAs to save
#log: ${placeholders}
# lookup user that was entered
cmd [cp]:
- cd /var/www/webroot/ROOT/
- user=$(wp user get ${settings.userToLoginAs} --field=ID)
# see if number (user ID) returned or not. Return 1 if yes.
- re='^[0-9]+$'
- if ! [[ $user =~ $re ]]; then echo 0; else echo 1; fi
#check if the user was found
# returns ID if so
# returns 'Error: Invalid user ID, email or login: '24342''
if (response.out == 0):
script: |
return {"result": "error", "message": "User not found. Try again."}
else:
- setGlobals:
userToLoginAs: ${settings.userToLoginAs}
- script: |
return {"result": "success", "message": "User saved!"}
settings:
configure:
fields:
- type: string
name: userToLoginAs
caption: User to login as
placeholder: Enter user ID, user email, or user login
buttons:
- caption: Instant Login
loadingText: Generating login...
confirmText: Generate a login link for the configured user? This will log you out of any existing sessions.
action: instant_login
- caption: Configure
action: save_config
settings: configure
# problem - only saves the user name/id/email on initial creation. Since adding custom code to save_config, it will not update with new user value after saving again
# tried to use setGlobals but doesn't seem like that works any better
#SOLUTION: Combine these two options into one button - the button shows the input form, filled out with the username that was previously used. Then upon saving, it checks to see if that's a real user and if so it generates the login for that user.