forked from jeffknupp/bull
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcreate_user.py
More file actions
32 lines (26 loc) · 923 Bytes
/
create_user.py
File metadata and controls
32 lines (26 loc) · 923 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
30
31
32
#!/usr/bin/env python
"""Create a new admin user able to view the /reports endpoint."""
from getpass import getpass
import sys
from flask import current_app
from bull import app, Product, Purchase, bcrypt
from bull.models import User, db
def main():
"""Main entry point for script."""
with app.app_context():
db.metadata.create_all(db.engine)
if User.query.all():
print 'A user already exists! Create another? (y/n):',
create = raw_input()
if create == 'n':
return
print 'Enter email address: ',
email = raw_input()
password = getpass()
assert password == getpass('Password (again):')
user = User(email=email, password=bcrypt.generate_password_hash(password))
db.session.add(user)
db.session.commit()
print 'User added.'
if __name__ == '__main__':
sys.exit(main())