Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed the admin role business #12

Merged
merged 3 commits into from
Oct 3, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,4 @@ htmlcov/
dist/
build/
*.egg-info/
*.db
4 changes: 3 additions & 1 deletion ecsopendata/database.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,10 @@
Base = declarative_base()
Base.query = db_session.query_property()

from models import *
def init_db():
import models
# import models
# from models import *
Base.metadata.create_all(bind=engine)
if not os.path.exists(DATABASE_PATH):
# replace this if statement with sqlalchemy if table doesn't exist in master table:
Expand Down
21 changes: 19 additions & 2 deletions ecsopendata/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,30 @@
@app.before_first_request
def create_user():
init_db()

# Check if admin role exists, create new role if not
admin_role = user_datastore.find_or_create_role(name='admin')

# Check if admin user exists, create new user if not
if not user_datastore.get_user('admin'):
print("creating new 'admin' user with password 'password'")
admin_user = user_datastore.create_user(email='admin', password='password')
user_datastore.add_role_to_user(user=admin_user, role='admin')
admin_user = user_datastore.create_user(email='admin',
password='password')
user_datastore.add_role_to_user(user=admin_user, role=admin_role)

# Check if user exists, create if not
if not user_datastore.get_user('user'):
user_datastore.create_user(email='user', password='password')
db_session.commit()
#def create_user():
# init_db()
# if not user_datastore.get_user('admin'):
# print("creating new 'admin' user with password 'password'")
# admin_user = user_datastore.create_user(email='admin', password='password')
## user_datastore.add_role_to_user(user=admin_user, role='admin')
## if not user_datastore.get_user('user'):
## user_datastore.create_user(email='user', password='password')
## db_session.commit()

# Views
@app.route('/')
Expand Down