EP_inspection_tool_proto/routes.py
James Devine cb3db118d0 Add Flask app and routes for basic authentication
Implemented a Flask application factory with SQLAlchemy, Flask-Login, and CSRF protection. Added auth and main blueprints providing login, logout, and index routes. Staged new source files, database, and compiled bytecode. Updated configuration to serve over HTTPS in development.
2026-03-07 06:01:28 +01:00

30 lines
964 B
Python

from flask import Blueprint, render_template, redirect, url_for, request, flash
from flask_login import login_user, logout_user, current_user, login_required
# Auth blueprint
auth_bp = Blueprint('auth', __name__, url_prefix='/auth')
@auth_bp.route('/login', methods=['GET', 'POST'])
def login():
if request.method == 'POST':
from models import User
username = request.form.get('username')
password = request.form.get('password')
user = User.query.filter_by(username=username).first()
if user and user.check_password(password):
login_user(user)
return redirect(url_for('main.index'))
flash('Invalid credentials')
return render_template('login.html')
@auth_bp.route('/logout')
def logout():
logout_user()
return redirect(url_for('auth.login'))
# Main blueprint
main_bp = Blueprint('main', __name__)
@main_bp.route('/')
def index():
return render_template('index.html')