Created
October 7, 2021 13:27
-
-
Save lananovikova10/0b9decc7b12c508165ee9f702536473d to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from getpass import getpass | |
import sys | |
from webapp import create_app | |
from webapp.model import User, db | |
app = create_app() | |
with app.app_context(): | |
username = input('Введите имя пользователя: ') | |
if User.query.filter(User.username == username).count(): | |
print('Такой пользователь уже есть') | |
sys.exit(0) | |
password = getpass('Введите пароль: ') | |
password2 = getpass('Повторите пароль: ') | |
if not password == password2: | |
sys.exit(0) | |
new_user = User(username=username, role='admin') | |
new_user.set_password(password) | |
db.session.add(new_user) | |
db.session.commit() | |
print('User with id {} added'.format(new_user.id)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment