diff options
| author | Gertjan van den Burg <gertjanvandenburg@gmail.com> | 2019-03-18 18:29:39 +0000 |
|---|---|---|
| committer | Gertjan van den Burg <gertjanvandenburg@gmail.com> | 2019-03-18 18:29:47 +0000 |
| commit | 38795c9a464fb6bcb778c655ab1469fa933a54c3 (patch) | |
| tree | 16b59d0ccb35ac5acd712a1636bdd369254e81c5 /app | |
| parent | Add admin flag (diff) | |
| download | AnnotateChange-38795c9a464fb6bcb778c655ab1469fa933a54c3.tar.gz AnnotateChange-38795c9a464fb6bcb778c655ab1469fa933a54c3.zip | |
Add command line interface for admin tasks
Diffstat (limited to 'app')
| -rw-r--r-- | app/cli.py | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/app/cli.py b/app/cli.py new file mode 100644 index 0000000..e128c35 --- /dev/null +++ b/app/cli.py @@ -0,0 +1,34 @@ +# -*- coding: utf-8 -*- + +import getpass + +from email_validator import validate_email + +from app import db +from app.models import User + + +def register(app): + @app.cli.group(help="Perform admin commands") + def admin(): + pass + + @admin.command() + def add(): + username = input("Enter username: ") + email = input("Enter email address: ") + password = getpass.getpass() + assert password == getpass.getpass("Repeat password: ") + + user = User.query.filter_by(username=username).first() + if user is not None: + raise ValueError("User already exists") + + validate_email(email) + + user = User(username=username, email=email, is_admin=True) + user.set_password(password) + db.session.add(user) + db.session.commit() + + print("Admin user %r added successfully." % username) |
