-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathrun.py
More file actions
42 lines (34 loc) · 1.27 KB
/
run.py
File metadata and controls
42 lines (34 loc) · 1.27 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
from flask import render_template
from app import create_app, db
from app.models.users import User
from werkzeug.security import generate_password_hash
from datetime import datetime
from flask import render_template, request, jsonify
import sys, os
import os
from werkzeug.utils import secure_filename
from app.models.users import User, StudentProfile
# Create the Flask app by calling the factory function
app = create_app()
def create_admin():
admin_email = 'admin@gmail.com'
admin_password = 'Fyp//&em7861'
existing_admin = User.query.filter_by(email=admin_email, role='admin').first()
if not existing_admin:
admin = User(
email=admin_email,
password_hash=generate_password_hash(admin_password),
role='admin',
reg_date=datetime.utcnow(),
is_active=True
)
db.session.add(admin)
db.session.commit()
print('✅ Admin user created.')
else:
print('ℹ️ Admin user already exists.')
if __name__ == '__main__':
with app.app_context(): # Make sure to use the app's context
db.create_all() # Create tables
create_admin() # Create the admin account if not exists
app.run(debug=True) # Run the app