-
Notifications
You must be signed in to change notification settings - Fork 1
/
create_user.py
executable file
·45 lines (38 loc) · 1.17 KB
/
create_user.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
42
43
44
45
#!/usr/bin/env python
from getpass import getpass
import sys
from flask import current_app
from app.models import User
from app import db, app
from flask_sqlalchemy import SQLAlchemy
from flask_bcrypt import Bcrypt
import flask
app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False
def main():
"""Main entry point for script."""
bcrypt = Bcrypt()
db = SQLAlchemy()
db.init_app(app)
with app.app_context():
db.metadata.create_all(db.engine)
if User.query.all():
print('A user already exists! Create another? (y/n):')
create = input()
if create == 'n':
return
print('Enter username: ')
username = input()
print('Enter email: ')
email = input()
password_hash = getpass()
assert password_hash == getpass('Password (again):')
user = User(
username=username,
email=email,
password_hash=bcrypt.generate_password_hash(password_hash).decode('utf-8'),
authenticated=True)
db.session.add(user)
db.session.commit()
print('User added.')
if __name__ == '__main__':
sys.exit(main())