mirror of
https://github.com/StefBuwalda/cal_counter.git
synced 2025-10-30 11:19:59 +00:00
Refactor login flow to use auth blueprint
Moved login route and logic from app.py to application/auth/routes.py under the 'auth' blueprint. Updated all references to the login route to use 'auth.login'. Added a dedicated login.html template under application/auth/templates. Adjusted login_required utility and default_return logic for consistency.
This commit is contained in:
@@ -1,13 +1,30 @@
|
||||
from flask import (
|
||||
Blueprint,
|
||||
)
|
||||
from application.utils import login_required
|
||||
from flask import Blueprint, request, render_template
|
||||
from flask_login import current_user, login_user
|
||||
from forms import LoginForm
|
||||
from models import User
|
||||
from application.utils import default_return
|
||||
|
||||
bp = Blueprint(
|
||||
"user",
|
||||
"auth",
|
||||
__name__,
|
||||
template_folder="templates",
|
||||
)
|
||||
|
||||
|
||||
bp.before_request(login_required)
|
||||
@bp.route("/login", methods=["GET", "POST"])
|
||||
def login():
|
||||
if current_user.is_authenticated:
|
||||
return default_return()
|
||||
|
||||
form = LoginForm()
|
||||
if form.validate_on_submit():
|
||||
user = User.query.filter_by(username=form.username.data).first()
|
||||
if user and user.check_password(password=form.password.data):
|
||||
# User found and password correct
|
||||
next_page = request.args.get("next") # Get next page if given
|
||||
login_user(user) # Log in the user
|
||||
return default_return(next_page=next_page)
|
||||
else:
|
||||
pass
|
||||
# invalid user
|
||||
return render_template("login.html", form=form)
|
||||
|
||||
Reference in New Issue
Block a user