-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.py
More file actions
50 lines (43 loc) · 1.64 KB
/
Copy pathapp.py
File metadata and controls
50 lines (43 loc) · 1.64 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
43
44
45
46
47
48
49
50
from flask import Flask, render_template, request, redirect, url_for, session, flash, send_from_directory
from werkzeug.utils import secure_filename
import os
from functools import wraps
from models import init_db
app = Flask(__name__)
app.secret_key = 'your-secret-key-here-change-in-production'
app.config['UPLOAD_FOLDER'] = 'static/uploads'
app.config['MAX_CONTENT_LENGTH'] = 16 * 1024 * 1024 # 16MB max file size
# Khởi tạo database
init_db()
# Decorator kiểm tra đăng nhập
def login_required(f):
@wraps(f)
def decorated_function(*args, **kwargs):
if 'user_id' not in session:
return redirect(url_for('login'))
return f(*args, **kwargs)
return decorated_function
# Decorator kiểm tra quyền admin
def admin_required(f):
@wraps(f)
def decorated_function(*args, **kwargs):
if 'user_id' not in session or session.get('role') != 'admin':
flash('Bạn không có quyền truy cập trang này', 'error')
return redirect(url_for('dashboard'))
return f(*args, **kwargs)
return decorated_function
# Decorator kiểm tra quyền teacher
def teacher_required(f):
@wraps(f)
def decorated_function(*args, **kwargs):
if 'user_id' not in session or session.get('role') not in ['admin', 'teacher']:
flash('Bạn không có quyền truy cập trang này', 'error')
return redirect(url_for('dashboard'))
return f(*args, **kwargs)
return decorated_function
# Import routes
from routes import *
from admin_routes import *
from quiz_routes import *
if __name__ == '__main__':
app.run(debug=True, host='0.0.0.0', port=5000)