aboutsummaryrefslogtreecommitdiff
path: root/web/app/auth.py
blob: 88bc18167cb234081338dd9815b14f77c01fe1d4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
from flask import Blueprint, render_template, request, redirect, url_for
from flask_login import login_user
from .models import User

auth = Blueprint('auth', __name__)

@auth.route('/login', methods=['GET', 'POST'])
def login():
    error = None
    if request.method == 'POST':
        username = request.form['username']
        password = request.form['password']

        user = User.validate_login(username, password)
        if user:
            login_user(user)
            return redirect(url_for('main.home'))
        
        error = "Invalid credentials"
        
    return render_template('login.html', error=error)