-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcreate_admin.py
More file actions
29 lines (21 loc) · 858 Bytes
/
create_admin.py
File metadata and controls
29 lines (21 loc) · 858 Bytes
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
from getpass import getpass
import sys
from webapp import create_app
from webapp.db import db
from webapp.manuals.models import User
app = create_app()
with app.app_context():
username = input('Введите имя:')
if User.query.filter(User.username == username).count():
print('Пользователь с таким именем уже существует')
sys.exit(0)
password1 = getpass('Введите пароль:')
password2 = getpass('Повторите пароль:')
if not password1 == password2:
print('Пароли не совпадают!')
sys.exit(0)
new_user = User(username=username, role='admin')
new_user.set_password(password1)
db.session.add(new_user)
db.session.commit()
print('Создан пользователь с id={}'.format(new_user.id))