diff options
| author | Jules Laplace <julescarbon@gmail.com> | 2021-03-05 18:08:17 +0100 |
|---|---|---|
| committer | Jules Laplace <julescarbon@gmail.com> | 2021-03-05 18:08:17 +0100 |
| commit | d5b6a4ea27f8c905e613363aab365066ad6d9cda (patch) | |
| tree | 7cbb6a3a94cb9079800023d0bf06f7bd1b1bc55c /animism-align/cli/commands/admin/createuser.py | |
| parent | 9893a6e30f8fdbb95fc7066db851579e2a9bfe69 (diff) | |
auth stuff. generate secret and create user from the cli
Diffstat (limited to 'animism-align/cli/commands/admin/createuser.py')
| -rw-r--r-- | animism-align/cli/commands/admin/createuser.py | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/animism-align/cli/commands/admin/createuser.py b/animism-align/cli/commands/admin/createuser.py new file mode 100644 index 0000000..ef90f1e --- /dev/null +++ b/animism-align/cli/commands/admin/createuser.py @@ -0,0 +1,28 @@ +import click + +@click.command('createuser') +@click.pass_context +def cli(ctx): + from getpass import getpass + from app.utils.auth_utils import encrypt_password + from app.sql.common import db, Session, User + + username = input("Username: ") + session = Session() + user_exists = session.query(User).filter(User.username == username).first() + if user_exists: + session.close() + raise ValueError("User already exists") + + password = encrypt_password(getpass()) + is_admin = input("Is admin? (y/n): ") == 'y' + + user = User( + username=username, + password=password, + is_admin=is_admin, + settings={} + ) + session.add(user) + session.commit() + session.close() |
