image created
This commit is contained in:
20
init_db.py
Normal file
20
init_db.py
Normal file
@@ -0,0 +1,20 @@
|
||||
import os
|
||||
from app import app, db, User, bcrypt
|
||||
|
||||
def create_admin_user():
|
||||
admin_username = os.getenv('ADMIN_USER', 'admin')
|
||||
admin_password = os.getenv('ADMIN_PASSWORD', 'admin')
|
||||
hashed_password = bcrypt.generate_password_hash(admin_password).decode('utf-8')
|
||||
|
||||
if not User.query.filter_by(username=admin_username).first():
|
||||
admin_user = User(username=admin_username, password=hashed_password, role='admin')
|
||||
db.session.add(admin_user)
|
||||
db.session.commit()
|
||||
print(f"Admin user '{admin_username}' created with password '{admin_password}'")
|
||||
else:
|
||||
print(f"Admin user '{admin_username}' already exists")
|
||||
|
||||
if __name__ == '__main__':
|
||||
with app.app_context():
|
||||
db.create_all()
|
||||
create_admin_user()
|
||||
Reference in New Issue
Block a user