Implemented comprehensive Flask-Login authentication with single-user support. New Features: - Flask-Login integration with User model - Bcrypt password hashing via PasswordManager - Login, logout, and initial password setup routes - @login_required and @api_auth_required decorators - All API endpoints now require authentication - Bootstrap 5 dark theme UI templates - Dashboard with navigation - Remember me and next parameter redirect support Files Created (12): - web/auth/__init__.py, models.py, decorators.py, routes.py - web/routes/__init__.py, main.py - web/templates/login.html, setup.html, dashboard.html, scans.html, scan_detail.html - tests/test_authentication.py (30+ tests) Files Modified (6): - web/app.py: Added Flask-Login initialization and main routes - web/api/scans.py: Protected all endpoints with @api_auth_required - web/api/settings.py: Protected all endpoints with @api_auth_required - web/api/schedules.py: Protected all endpoints with @api_auth_required - web/api/alerts.py: Protected all endpoints with @api_auth_required - tests/conftest.py: Added authentication test fixtures Security: - Session-based authentication for both web UI and API - Secure password storage with bcrypt - Protected routes redirect to login page - Protected API endpoints return 401 Unauthorized - Health check endpoints remain accessible for monitoring Testing: - User model authentication and properties - Login success/failure flows - Logout and session management - Password setup workflow - API endpoint authentication requirements - Session persistence and remember me functionality - Next parameter redirect behavior Total: ~1,200 lines of code added 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
69 lines
1.3 KiB
Python
69 lines
1.3 KiB
Python
"""
|
|
Main web routes for SneakyScanner.
|
|
|
|
Provides dashboard and scan viewing pages.
|
|
"""
|
|
|
|
import logging
|
|
|
|
from flask import Blueprint, current_app, redirect, render_template, url_for
|
|
|
|
from web.auth.decorators import login_required
|
|
|
|
logger = logging.getLogger(__name__)
|
|
|
|
bp = Blueprint('main', __name__)
|
|
|
|
|
|
@bp.route('/')
|
|
def index():
|
|
"""
|
|
Root route - redirect to dashboard.
|
|
|
|
Returns:
|
|
Redirect to dashboard
|
|
"""
|
|
return redirect(url_for('main.dashboard'))
|
|
|
|
|
|
@bp.route('/dashboard')
|
|
@login_required
|
|
def dashboard():
|
|
"""
|
|
Dashboard page - shows recent scans and statistics.
|
|
|
|
Returns:
|
|
Rendered dashboard template
|
|
"""
|
|
# TODO: Phase 5 - Add dashboard stats and recent scans
|
|
return render_template('dashboard.html')
|
|
|
|
|
|
@bp.route('/scans')
|
|
@login_required
|
|
def scans():
|
|
"""
|
|
Scans list page - shows all scans with pagination.
|
|
|
|
Returns:
|
|
Rendered scans list template
|
|
"""
|
|
# TODO: Phase 5 - Implement scans list page
|
|
return render_template('scans.html')
|
|
|
|
|
|
@bp.route('/scans/<int:scan_id>')
|
|
@login_required
|
|
def scan_detail(scan_id):
|
|
"""
|
|
Scan detail page - shows full scan results.
|
|
|
|
Args:
|
|
scan_id: Scan ID to display
|
|
|
|
Returns:
|
|
Rendered scan detail template
|
|
"""
|
|
# TODO: Phase 5 - Implement scan detail page
|
|
return render_template('scan_detail.html', scan_id=scan_id)
|