-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
[esekyi]
committed
Aug 24, 2024
1 parent
1c469d5
commit d1476f7
Showing
1 changed file
with
39 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
from flask import Blueprint, render_template, request, flash, redirect, url_for | ||
from flask_login import login_user, logout_user, login_required, current_user | ||
from werkzeug.security import check_password_hash | ||
from app.models.user import User | ||
from app import db | ||
|
||
"""Route for basic authentication""" | ||
|
||
auth_bp = Blueprint('auth', __name__) | ||
|
||
@auth_bp.route('/login', methods=['GET','POST']) | ||
def login(): | ||
"""Login authentication handler""" | ||
if request.method == 'POST': | ||
email = request.form["email"] | ||
password = request.form["password"] | ||
user = User.query.filter_by(email=email).first() | ||
|
||
if user and check_password_hash(user.password_hash, password): | ||
login_user(user) | ||
return redirect(url_for('main.profile')) | ||
|
||
flash('Invalid Credentials', 'warning') | ||
|
||
return render_template('login.html') | ||
|
||
@auth_bp.route('/logout') | ||
@login_required | ||
def logout(): | ||
"""logout handler""" | ||
logout_user() | ||
return redirect(url_for('auth.login')) | ||
|
||
@auth_bp.route('/register', methods=["GET", "POST"]) | ||
def register(): | ||
if request.method == "POST": | ||
pass | ||
|
||
return render_template('register.html') |