aboutsummaryrefslogtreecommitdiff
path: root/web/app/auth.py
diff options
context:
space:
mode:
Diffstat (limited to 'web/app/auth.py')
-rw-r--r--web/app/auth.py21
1 files changed, 21 insertions, 0 deletions
diff --git a/web/app/auth.py b/web/app/auth.py
new file mode 100644
index 0000000..88bc181
--- /dev/null
+++ b/web/app/auth.py
@@ -0,0 +1,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)