-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmanage.py
More file actions
54 lines (44 loc) · 1.63 KB
/
manage.py
File metadata and controls
54 lines (44 loc) · 1.63 KB
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
42
43
44
45
46
47
48
49
50
51
52
53
54
from flask_script import Manager, prompt, prompt_bool, prompt_pass
from flask_migrate import Migrate, MigrateCommand
from flfm import create_app, db
from flfm.models import User
from config import Config
app = create_app(Config)
migrate = Migrate(app, db)
manager = Manager(app)
manager.add_command('db', MigrateCommand)
@manager.option('-u', '--username', dest="username", required=False)
@manager.option('-p', '--password', dest="password", required=False)
@manager.option('-a', '--admin', dest="admin", required=False)
def createuser(username=None, password=None, admin=None):
"""Create a user account for the application.
"""
u_name = username
pw = password
make_admin = admin
if u_name is None:
while True:
u_name = prompt("User Name")
user = User.query.filter(User.name==u_name).first()
if user is not None:
print("{}: USER ALREADY EXISTS!".format(u_name))
else:
break
if pw is None:
pw = prompt_pass("Password")
while True:
pw_again = prompt_pass("Password Again")
if pw != pw_again:
print("PASSWORDS DO NOT MATCH!")
else:
break
if make_admin is None:
make_admin = prompt_bool("Do you wish to make {} an administrator?".\
format(u_name))
user = User(name=u_name, password="", admin=make_admin, enabled=True)
user.set_password(pw)
db.session.add(user)
db.session.commit()
print("Successfully created '{}' with ID: {}.".format(user.name, user.id))
if __name__ == '__main__':
manager.run()