Skip to content

Commit

Permalink
Merge pull request #12 from nealde/master
Browse files Browse the repository at this point in the history
Fixed the admin role business
  • Loading branch information
nealde authored Oct 3, 2018
2 parents 94456a0 + b9716b4 commit 3008f51
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 3 deletions.
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

0 comments on commit 3008f51

Please sign in to comment.