Skip to content

Commit

Permalink
Logging related errors fixed | #7
Browse files Browse the repository at this point in the history
  • Loading branch information
eshaan7 committed Jul 31, 2019
1 parent e05338e commit fc490f3
Showing 1 changed file with 41 additions and 36 deletions.
77 changes: 41 additions & 36 deletions src/create_db.py
Original file line number Diff line number Diff line change
@@ -1,43 +1,48 @@
import datetime
from datetime import datetime

from FlaskRTBCTF import create_app, db, bcrypt
from FlaskRTBCTF.models import User, Score, Notification
from FlaskRTBCTF.config import organization
from FlaskRTBCTF.models import User, Score, Notification, Logs
from FlaskRTBCTF.config import organization, LOGGING

app = create_app()

# create_app().app_context().push()
with app.app_context():
db.create_all()

# NOTE: CHANGE DEFAULT CREDENTIALS !!!
admin_user = User(
username='admin',
email='[email protected]',
password=bcrypt.generate_password_hash('admin').decode('utf-8'),
confirmed_at=datetime.datetime.now(),
isAdmin = True,
visitedMachine = True
)
admin_score = Score(user=admin_user, userHash=False, rootHash=False, points=0)
db.session.add(admin_user)
db.session.add(admin_score)

notif = Notification(
title=f"Welcome to {organization['ctfname']}",
body = "The CTF is live now. Please read rules!"
)
db.session.add(notif)

'''
test = User(
username='test',
email='[email protected]',
password=bcrypt.generate_password_hash('test').decode('utf-8'),
)
testscore = Score(user=test, userHash=False, rootHash=False, points=0)
db.session.add(test)
db.session.add(testscore)
'''

db.session.commit()
db.create_all()

default_time = datetime.utcnow()

# NOTE: CHANGE DEFAULT CREDENTIALS !!!
admin_user = User(
username='admin',
email='[email protected]',
password=bcrypt.generate_password_hash('admin').decode('utf-8'),
isAdmin = True
)
admin_score = Score(user=admin_user, userHash=False, rootHash=False, points=0)
db.session.add(admin_user)
db.session.add(admin_score)

notif = Notification(
title=f"Welcome to {organization['ctfname']}",
body = "The CTF is live now. Please read rules!"
)
db.session.add(notif)

test_user = User(
username='test',
email='[email protected]',
password=bcrypt.generate_password_hash('test').decode('utf-8')
)
test_score = Score(user=test_user, userHash=False, rootHash=False, points=0)
db.session.add(test_user)
db.session.add(test_score)

if LOGGING:
admin_log = Logs(user=admin_user, accountCreationTime=default_time,
visitedMachine=True, machineVisitTime=default_time)
db.session.add(admin_log)
test_log = Logs(user=test_user, accountCreationTime=default_time)
db.session.add(test_log)

db.session.commit()

0 comments on commit fc490f3

Please sign in to comment.