-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsetup_admin.py
39 lines (36 loc) · 1.11 KB
/
setup_admin.py
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
# setup_admin.py
# Jake Malley
# Adds a new administrator to the database.
# Application Imports
from peri2organise import db
from peri2organise.models import User
# User Configuration Required:
FIRST_NAME = 'Admin'
LAST_NAME = 'Admin'
EMAIL_ADDRESS = '[email protected]'
PASSWORD = 'password1'
TELEPHONE_NUMBER = '01373465353'
SPECIALITY = 'Admin'
# -------------------------- #
# This script can only be run if there are no other admins!
if not User.query.filter(User.role == 'STA').all():
# Create a new user object.
admin_user = User()
# Create a password hash of the desired password.
password_hash = admin_user.create_password_hash(PASSWORD)
# Update the admin user's details.
admin_user.update_user_details(
first_name=FIRST_NAME,
last_name=LAST_NAME,
email_address=EMAIL_ADDRESS,
password=password_hash,
role='STA',
telephone_number=TELEPHONE_NUMBER,
speciality=SPECIALITY
)
# Add the new object to the database.
db.session.add(admin_user)
# Commit changes.
db.session.commit()
else:
print("An admin already exists")