mirror of
https://github.com/aronwk-aaron/MSState-Library-ETD.git
synced 2026-04-28 23:19:12 -05:00
Login function yay
This commit is contained in:
@@ -41,8 +41,6 @@ def create_app():
|
||||
|
||||
app.jinja_env.globals['bootstrap_is_hidden_field'] = is_hidden_field_filter
|
||||
|
||||
|
||||
|
||||
return app
|
||||
|
||||
|
||||
|
||||
+25
-2
@@ -1,4 +1,8 @@
|
||||
from flask import render_template, Blueprint
|
||||
from flask import render_template, Blueprint, request, flash, redirect, url_for
|
||||
from flask_login import login_user
|
||||
from werkzeug.security import check_password_hash
|
||||
|
||||
from app.models import User, db
|
||||
|
||||
auth_blueprint = Blueprint('auth', __name__)
|
||||
|
||||
@@ -6,7 +10,26 @@ auth_blueprint = Blueprint('auth', __name__)
|
||||
@auth_blueprint.route('/auth/login', methods=['GET', 'POST'])
|
||||
def login():
|
||||
"""Auth: Login Page"""
|
||||
return render_template('auth/login.jinja2')
|
||||
if request.method == 'GET':
|
||||
return render_template('auth/login.jinja2')
|
||||
|
||||
db.create_all()
|
||||
netid = request.form['netid']
|
||||
password = request.form['password']
|
||||
|
||||
registered_user = User.query.filter_by(netid=netid).first()
|
||||
|
||||
if registered_user is None:
|
||||
flash('Username or Password is invalid', 'error')
|
||||
return redirect(url_for('auth.login'))
|
||||
|
||||
if check_password_hash(password, registered_user.password):
|
||||
flash('Username or Password is invalid', 'error')
|
||||
return redirect(url_for('auth.login'))
|
||||
|
||||
login_user(registered_user)
|
||||
flash('Logged in successfully')
|
||||
return redirect(request.args.get('next') or url_for('index'))
|
||||
|
||||
|
||||
@auth_blueprint.route('/auth/logout')
|
||||
|
||||
@@ -30,16 +30,23 @@
|
||||
|
||||
<div class="card-body d-flex flex-column m-2">
|
||||
|
||||
<form>
|
||||
<form action="{{ url_for('auth.login') }}" method="post" role="form">
|
||||
<input type="hidden" name="csrf_token" value="{{ csrf_token() }}"/>
|
||||
|
||||
<h3>
|
||||
Login
|
||||
</h3>
|
||||
|
||||
<hr class="mb-4"/>
|
||||
|
||||
<div class="alert alert-warning" role="alert" hidden>
|
||||
<b>Invalid username or password</b>
|
||||
</div>
|
||||
{# Show any errors #}
|
||||
{% with messages = get_flashed_messages() %}
|
||||
{% for message in messages %}
|
||||
<div class="alert alert-warning" role="alert">
|
||||
{{ message }}
|
||||
</div>
|
||||
{% endfor %}
|
||||
{% endwith %}
|
||||
|
||||
<div class="form-group">
|
||||
<label class="font-weight-bold">NetID</label>
|
||||
@@ -47,7 +54,8 @@
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label class="font-weight-bold">Password</label>
|
||||
<input name="password" class="form-control" id="inputPassword" type="password" placeholder="Enter password">
|
||||
<input name="password" class="form-control" id="inputPassword" type="password"
|
||||
placeholder="Enter password">
|
||||
</div>
|
||||
<button type="submit" class="btn btn-primary">Login</button>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user