Add root redirect to /login (fix 404 on http://localhost:5010)
This commit is contained in:
@@ -0,0 +1,34 @@
|
|||||||
|
from flask import Blueprint, render_template, redirect, url_for, request, flash
|
||||||
|
from flask_login import login_user, logout_user, login_required, current_user
|
||||||
|
from app import db
|
||||||
|
from app.models import User
|
||||||
|
from werkzeug.security import generate_password_hash, check_password_hash
|
||||||
|
|
||||||
|
bp = Blueprint('auth', __name__)
|
||||||
|
|
||||||
|
@bp.route('/')
|
||||||
|
def index():
|
||||||
|
return redirect(url_for('auth.login'))
|
||||||
|
|
||||||
|
@bp.route('/login', methods=['GET', 'POST'])
|
||||||
|
def login():
|
||||||
|
if request.method == 'POST':
|
||||||
|
email = request.form['email']
|
||||||
|
password = request.form['password']
|
||||||
|
user = User.query.filter_by(email=email).first()
|
||||||
|
|
||||||
|
if user and check_password_hash(user.password_hash, password):
|
||||||
|
login_user(user)
|
||||||
|
if user.role == 'admin':
|
||||||
|
return redirect(url_for('admin.dashboard'))
|
||||||
|
else:
|
||||||
|
return redirect(url_for('owner.dashboard'))
|
||||||
|
else:
|
||||||
|
flash('Credenciales inválidas')
|
||||||
|
return render_template('login.html')
|
||||||
|
|
||||||
|
@bp.route('/logout')
|
||||||
|
@login_required
|
||||||
|
def logout():
|
||||||
|
logout_user()
|
||||||
|
return redirect(url_for('auth.login'))
|
||||||
Reference in New Issue
Block a user