Skip to content

Commit

Permalink
amélioration
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexTheGeek committed Jan 31, 2024
1 parent 01fb683 commit 684b126
Showing 1 changed file with 33 additions and 31 deletions.
64 changes: 33 additions & 31 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
import logging
import os


################
### Vars APP ###
################
Expand All @@ -32,6 +31,7 @@

db = SQLAlchemy(app)
migrate = Migrate(app, db)
db.init_app(app)
login_manager = LoginManager(app)

# Openstack API Connection
Expand Down Expand Up @@ -775,35 +775,37 @@ def get_template_info(uuid):
logger.info('Creating DB')
db.create_all()
db.session.commit()
# 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)
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')
app.run(debug=True, host="0.0.0.0", port=5001)

0 comments on commit 684b126

Please sign in to comment.