25 lines
894 B
Python
25 lines
894 B
Python
from click import command, option, prompt, confirm
|
|
from roc_fnb.website.database import Database
|
|
from roc_fnb.website.models.user import User
|
|
|
|
|
|
@command
|
|
@option('--name', '-n', type=str, required=True)
|
|
@option('--email', '-e', type=str, required=True)
|
|
def bootstrap_first_admin(name: str, email: str):
|
|
password = prompt('Enter the account password',
|
|
hide_input=True, prompt_suffix=': ')
|
|
confirmation = prompt('Confirm the account password',
|
|
hide_input=True, prompt_suffix=': ')
|
|
if password != confirmation:
|
|
raise ValueError('passwords did not match')
|
|
admin = User.create(email, name, password, moderator=True, admin=True)
|
|
db = Database.from_env()
|
|
db.store_user(admin)
|
|
if confirm('Display an auth token for testing?', default=False):
|
|
print(admin.jwt)
|
|
|
|
|
|
if __name__ == '__main__':
|
|
bootstrap_first_admin()
|