-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.py
41 lines (33 loc) · 1.08 KB
/
app.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
40
41
from getpass import getpass
from flask.cli import with_appcontext
from solid.cli import cli_bp
from solid.db import User
from solid.extensions import db
from solid.webserver import webserver_bp, create_app
from trompasolid.db import Base
app = create_app()
app.register_blueprint(webserver_bp)
app.register_blueprint(cli_bp)
@app.cli.command("create-db")
def create_database():
"""Create database tables"""
# This doesn't use the Flask-SQLAlchemy create_all method, as we have other
# tables that aren't part of that extension's declarative base
print("Creating database tables...")
db.create_all()
Base.metadata.create_all(db.engine)
print("Done")
@app.cli.command("create-user")
@with_appcontext
def create_user():
"""Create an admin user account"""
username = input("Username: ")
pw = getpass("Password: ")
pw2 = getpass("Again: ")
if pw == pw2:
user = User(username, pw, is_admin=True)
db.session.add(user)
db.session.commit()
print(f"User {username} created")
else:
print("Passwords don't match")