forked from 296452965/flask_bulletin_board
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcommands.py
25 lines (21 loc) · 861 Bytes
/
commands.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
from bulletin_board import app, db
import click
from department.models import Department
@app.cli.command()
@click.option('--username', prompt=True, help='The username used to login.')
@click.option('--password', prompt=True, hide_input=True, confirmation_prompt=True, help='The password used to login.')
def admin(username, password):
"""Create user."""
db.create_all()
admin = Department.query.filter_by('role' == 1).first()
if admin is not None:
click.echo('Updating admin...')
admin.username = username
admin.set_password(password) # 设置密码
else:
click.echo('Creating admin...')
admin = Department(username=username)
admin.set_password(password) # 设置密码
db.session.add(admin)
db.session.commit() # 提交数据库会话
click.echo('Create Admin Done.')