Skip to content

Commit

Permalink
init db ok
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexTheGeek committed Feb 1, 2024
1 parent 387030d commit f0325b5
Showing 1 changed file with 40 additions and 1 deletion.
41 changes: 40 additions & 1 deletion Docker/API/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -819,4 +819,43 @@ def get_template_info(uuid):
db.session.commit()
logger.info("Default etudiant user created with password: "+random_password)
logger.info('API started')
app.run(debug=True, host="0.0.0.0", port=5001)
app.run(debug=True, host="0.0.0.0", port=5001)
else:
logger.info('Starting API')
with app.app_context():
logger.info('Creating DB')
db.create_all()
db.session.commit()
user = User.query.first()
if not user:
# Create default admin user
if not User.query.filter_by(email="admin@admin.fr").first():
logger.info('Creating default admin user')
random_password = "admin"
hashed_password = PasswordHasher().hash(random_password)
new_user = User(id="2", email="admin@admin.fr", first_name="Admin", last_name="VDI",
password=hashed_password, role="admin", cas=False)
db.session.add(new_user)
db.session.commit()
logger.info("Default admin user created with password: "+random_password)
# Create default prof user
if not User.query.filter_by(email="prof@prof.fr").first():
logger.info('Creating default prof user')
random_password = "prof"
hashed_password = PasswordHasher().hash(random_password)
new_user = User(id="3", email="prof@prof.fr", first_name="Prof", last_name="VDI",
password=hashed_password, role="prof", cas=False)
db.session.add(new_user)
db.session.commit()
logger.info("Default prof user created with password: "+random_password)
# Create default etudiant user
if not User.query.filter_by(email="etudiant@etudiant.fr").first():
logger.info('Creating default etudiant user')
random_password = "etudiant"
hashed_password = PasswordHasher().hash(random_password)
new_user = User(id="4", email="etudiant@etudiant.fr", first_name="Etudiant", last_name="VDI",
password=hashed_password, role="user", cas=False)
db.session.add(new_user)
db.session.commit()
logger.info("Default etudiant user created with password: "+random_password)
logger.info('API started')

0 comments on commit f0325b5

Please sign in to comment.