-
Notifications
You must be signed in to change notification settings - Fork 0
/
ins-into-db.sh
48 lines (37 loc) · 1.69 KB
/
ins-into-db.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#!/bin/bash
isDataBaseOn=$(./is-this-thing-on.sh project1-db)
if [ $isDataBaseOn -eq 0 ]; then
echo "cannot connect to database. Check to see if it is running."
echo "Cancelling registration."
exit 1
fi
echo "Please enter the following information"
read -p "First name: " fName;
read -p "Last name: " lName;
read -p "Email: " email;
read -p "Username: " uName;
read -p "Password: " pWord;
read -r -p "Role " role;
# Check to see if the provided email is already taken in the database
emailTaken=$(./is-email-available.sh $email)
# If it is, have the user provide a different email (loop until an available one is given)
while [ $emailTaken -ne 0 ]; do
echo "A user is already registered with that email, please enter another or type \q to cancel"
read -r -p "Email address: " email
if [ $email = "\q" ]; then
echo "Cancelling registration"
exit 0
else
emailTaken=$(./is-email-available.sh $email)
fi
done
# Check to see if the provided username is already taken in the database
usernameTaken=$(./is-username-available.sh $uName)
#If it is, have the user provide a different username (loop until an available one is given)
while [ $usernameTaken -ne 0 ]; do
echo "A user is already registered with that username, please choose another"
read -p "Username: " uName
usernameTaken=$(./is-username-available.sh $uName)
done
winpty docker exec -it project1-db psql -U postgres -h localhost -c "insert into store_app.app_users (first_name, last_name, email, username, password, role_id) values ('$fName', '$lName', '$email', '$uName', '$pWord', '$role');"
# echo "$insert" | winpty docker exec -it project1-db psql -U postgres -h localhost -c