After successful login, the app tried to redirect to admin.dashboard or dashboard.list routes that don't exist yet (Phase 5 & 6). Changes: - Login now redirects to index page for all users - Logout redirects to index page instead of submission.form - Base template navigation shows "Coming in Phase X" messages instead of broken links to unimplemented routes - Added TODO comments for future dashboard implementation This allows login/logout to work properly in MVP (Phase 3) while dashboard features are pending implementation. Bug: werkzeug.routing.exceptions.BuildError: Could not build url for endpoint 'admin.dashboard' 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
51 lines
1.6 KiB
Python
51 lines
1.6 KiB
Python
"""Authentication routes"""
|
|
from flask import Blueprint, render_template, request, redirect, url_for, flash
|
|
from flask_login import login_user, logout_user, login_required
|
|
from app.models.user import User
|
|
|
|
|
|
bp = Blueprint('auth', __name__, url_prefix='/auth')
|
|
|
|
|
|
@bp.route('/login', methods=['GET', 'POST'])
|
|
def login():
|
|
"""User login page
|
|
|
|
GET: Display login form
|
|
POST: Process login credentials
|
|
"""
|
|
if request.method == 'POST':
|
|
username = request.form.get('username', '').strip()
|
|
password = request.form.get('password', '')
|
|
|
|
if not username or not password:
|
|
flash('Please provide both username and password', 'error')
|
|
return render_template('auth/login.html')
|
|
|
|
user = User.get_by_username(username)
|
|
|
|
if user and user.is_active and user.check_password(password):
|
|
login_user(user)
|
|
flash(f'Welcome back, {user.username}!', 'success')
|
|
|
|
# TODO: Redirect based on role when dashboards are implemented
|
|
# For now, redirect to index page
|
|
# if user.role == 'administrator':
|
|
# return redirect(url_for('admin.dashboard'))
|
|
# elif user.role == 'product_owner':
|
|
# return redirect(url_for('dashboard.list'))
|
|
return redirect(url_for('index'))
|
|
else:
|
|
flash('Invalid username or password', 'error')
|
|
|
|
return render_template('auth/login.html')
|
|
|
|
|
|
@bp.route('/logout')
|
|
@login_required
|
|
def logout():
|
|
"""User logout"""
|
|
logout_user()
|
|
flash('You have been logged out', 'info')
|
|
return redirect(url_for('index'))
|