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:
29
app/blueprints/auth.py
Normal file
29
app/blueprints/auth.py
Normal 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'))
|
||||
|
||||
Reference in New Issue
Block a user