refactor: introduce app factory + blueprints (auth, core, admin users, invite); add utils and wsgi entrypoint; keep legacy routes for now

This commit is contained in:
2025-09-04 14:25:39 +03:00
parent d54e12123b
commit a3d4fbb31d
9 changed files with 566 additions and 0 deletions

29
app/blueprints/auth.py Normal file
View File

@@ -0,0 +1,29 @@
from flask import Blueprint, render_template, request, redirect, url_for, flash
from flask_login import login_user, logout_user
from werkzeug.security import check_password_hash
from app.models import User
bp = Blueprint('auth', __name__)
@bp.route('/login', methods=['GET', 'POST'], endpoint='login')
def login():
if request.method == 'POST':
username = request.form['username']
password = request.form['password']
user = User.get_or_none(User.username == username)
if user and check_password_hash(user.password_hash, password):
login_user(user)
return redirect(url_for('dashboard' if not user.is_admin else 'manage_surveys'))
else:
flash('Неверный логин или пароль', 'danger')
return render_template('login.html', title='Вход')
@bp.route('/logout', endpoint='logout')
def logout():
logout_user()
return redirect(url_for('choose_survey'))