Browse Source
This script adds a user to the database based on it's inputs (prompted for the person running the script). The intention is to add a user to the database easier (especially on a live production server with just the CLI).stable
Craig Oates
2 years ago
1 changed files with 39 additions and 0 deletions
@ -0,0 +1,39 @@ |
|||||||
|
#!/bin/bash |
||||||
|
|
||||||
|
# Create account so user can log-in to the website. Assumes you're using |
||||||
|
# SQLilte3 as the database. |
||||||
|
|
||||||
|
# Moves to the location of the script (regardless of where the script |
||||||
|
# was called from). |
||||||
|
cd "$(dirname "$0")" |
||||||
|
DATABASE="ritherdon-archive.db" |
||||||
|
|
||||||
|
read -p "Username: " USERNAME |
||||||
|
read -p "Display Name: " DISPLAY_NAME |
||||||
|
read -sp "Password: " USER_PASSWORD |
||||||
|
echo |
||||||
|
read -sp "Confirm Password: " PASSWORD_TEST |
||||||
|
echo |
||||||
|
|
||||||
|
if [[ $USERNAME == "" ]] |
||||||
|
|| [[ $DISPLAY_NAME == "" ]] |
||||||
|
|| [[ $USER_PASSWORD == "" ]]; then |
||||||
|
echo "[ERROR] Empty string used." |
||||||
|
else |
||||||
|
if [[ $USER_PASSWORD == $PASSWORD_TEST ]]; then |
||||||
|
echo "[SUCCESS] Password verified." |
||||||
|
if [ -e "../$DATABASE" ]; then |
||||||
|
echo "[INFO] Database found. Adding user to it..." |
||||||
|
SQL="INSERT INTO user (username,display_name,password,created_at,updated_at) \ |
||||||
|
VALUES (\"$USERNAME\",\"$DISPLAY_NAME\",\"$USER_PASSWORD\",(datetime(\"now\")),NULL);" |
||||||
|
cd ../ |
||||||
|
sqlite3 $DATABASE "$SQL" |
||||||
|
|
||||||
|
else |
||||||
|
echo "[ERROR] Cannot find database. Make sure you've ran make build." |
||||||
|
exit |
||||||
|
fi |
||||||
|
else |
||||||
|
echo "[ERROR] Passwords do not match." |
||||||
|
fi |
||||||
|
fi |
Loading…
Reference in new issue