Fixed the remaining url_for('index') calls that were causing test failures:
- app/routes/auth.py: Updated logout redirect to use landing.index
- app/templates/auth/login.html: Updated "Return to home" link to use landing.index
- app/templates/base.html: Removed administrator placeholder text (cleaned up)
All url_for('index') references have been replaced with url_for('landing.index').
Test results: 57 passed, 1 skipped, 4 errors (pre-existing fixture issues in performance tests)
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <noreply@anthropic.com>
51 lines
1.7 KiB
Python
51 lines
1.7 KiB
Python
"""Authentication routes"""
|
|
from flask import Blueprint, render_template, request, redirect, url_for, flash, current_app
|
|
from flask_login import login_user, logout_user, login_required, current_user
|
|
from app.models.user import User
|
|
|
|
|
|
bp = Blueprint('auth', __name__)
|
|
|
|
|
|
@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:
|
|
current_app.logger.warning('Login attempt with missing credentials')
|
|
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)
|
|
current_app.logger.info(f'User logged in successfully: {username} (role: {user.role})')
|
|
flash(f'Welcome back, {user.username}!', 'success')
|
|
|
|
# Redirect to dashboard for product owners and administrators
|
|
return redirect(url_for('dashboard.list'))
|
|
else:
|
|
current_app.logger.warning(f'Failed login attempt for username: {username}')
|
|
flash('Invalid username or password', 'error')
|
|
|
|
return render_template('auth/login.html')
|
|
|
|
|
|
@bp.route('/logout')
|
|
@login_required
|
|
def logout():
|
|
"""User logout"""
|
|
username = current_user.username
|
|
logout_user()
|
|
current_app.logger.info(f'User logged out: {username}')
|
|
flash('You have been logged out', 'info')
|
|
return redirect(url_for('landing.index'))
|