-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
executable file
·40 lines (29 loc) · 1.47 KB
/
main.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
from flask.ext.security import current_user, login_required, roles_required, roles_accepted, RoleMixin, Security, \
SQLAlchemyUserDatastore, UserMixin, utils
from __init__ import app, db
from models import *
# Executes before the first request is processed.
@app.before_first_request
def before_first_request():
# Create any database tables that don't exist yet.
db.create_all()
# Create the Roles "admin" and "end-user" -- unless they already exist
user_datastore.find_or_create_role(name='admin', description='Administrator')
# Create two Users for testing purposes -- unless they already exists.
# In each case, use Flask-Security utility function to encrypt the password.
encrypted_password = utils.encrypt_password('test')
if not user_datastore.get_user('admin@admin.no'):
user_datastore.create_user(email='admin@admin.no', password=encrypted_password)
# Commit any database changes; the User and Roles must exist before we can add a Role to the User
db.session.commit()
# Give one User has the "end-user" role, while the other has the "admin" role. (This will have no effect if the
# Users already have these Roles.) Again, commit any database changes.
user_datastore.add_role_to_user('admin@admin.no', 'admin')
db.session.commit()
# If running locally, listen on all IP addresses, port 8080
if __name__ == '__main__':
app.run(
host='0.0.0.0',
port=int('8080'),
debug=app.config['DEBUG']
)