Drop auth and replace sign out page

This commit is contained in:
Jordan Stremming
2019-03-22 10:31:46 -05:00
parent 57ecef68c0
commit b310f34c21
6 changed files with 9 additions and 233 deletions

View File

@@ -1,46 +0,0 @@
from flask import render_template, Blueprint, request, flash, redirect, url_for
from flask_login import login_user, login_required, logout_user
from werkzeug.security import check_password_hash
from app.models import User, db
auth_blueprint = Blueprint('auth', __name__)
@auth_blueprint.route('/auth/login', methods=['GET', 'POST'])
def login():
"""Auth: Login Page"""
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 not 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')
@login_required
def logout():
"""Auth: Logout Page"""
logout_user()
return redirect(url_for('auth.logout'))
@auth_blueprint.route('/auth/register')
def register():
"""Auth: Login Page"""
return render_template('auth/register.jinja2')

View File

@@ -35,6 +35,9 @@ USER_APP_NAME = 'Flask-User starter app'
USER_EMAIL_SENDER_NAME = 'Your name'
USER_EMAIL_SENDER_EMAIL = 'yourname@gmail.com'
USER_AFTER_LOGIN_ENDPOINT = "main.index"
USER_AFTER_LOGOUT_ENDPOINT = "main.signed-out"
ADMINS = [
'"Admin One" <admin1@gmail.com>',
]

View File

@@ -25,3 +25,9 @@ def dashboard():
def profile():
"""Profile Page"""
return render_template('main/profile.jinja2')
@main_blueprint.route('/signed-out')
def signed_out():
"""Sign out landing page"""
return render_template('main/signed_out.jinja2')

View File

@@ -1,77 +0,0 @@
{% extends 'base.jinja2' %}
{% set navbar_shadow = True %}
{% block title %}Login{% endblock %}
{% block header %}{% endblock %}
{% block css %}
{{ super() }}
{# override the body and html css to force center #}
<style>
html, body {
height: 100%;
background-color: #777777;
}
</style>
{% endblock %}
{% block content_before %}
<div class="container-fluid h-100">
<div class="row h-100 justify-content-center align-items-center">
<div class="mx-auto" style="max-width: 30em;">
{# Splash card #}
<div class="card shadow rounded border-0 h-100">
<div class="card-header bg-primary pt-4 text-center text-white">
<img class="img-fluid mb-3" src="http://lib.msstate.edu/_assets/img/2015-header-logo-msstate.png"
alt=""/>
<h5>Electronic Thesis and Dissertation System</h5>
</div>
<div class="card-body d-flex flex-column m-2">
<form action="{{ url_for('auth.login') }}" method="post" role="form">
{# CSRF Token #}
<input type="hidden" name="csrf_token" value="{{ csrf_token() }}"/>
<h3>
Login
</h3>
<hr class="mb-4"/>
{# 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>
<input name="netid" class="form-control" id="inputNetID" placeholder="Enter NetID">
</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">
</div>
<button type="submit" class="btn btn-primary">Login</button>
<hr class="mt-4"/>
<a href="#" class="text-secondary">Forgot Password</a> |
<a href="{{ url_for("auth.register") }}" class="text-secondary">Register</a>
</form>
</div>
</div>
</div>
</div>
</div>
{% endblock %}

View File

@@ -1,110 +0,0 @@
{% extends 'base.jinja2' %}
{% set navbar_shadow = True %}
{% block title %}Register{% endblock %}
{% block header %}{% endblock %}
{% block css %}
{{ super() }}
{# override the body and html css to force center #}
<style>
html, body {
height: 100%;
background-color: #777777;
}
</style>
{% endblock %}
{% block content_before %}
<div class="container-fluid h-100">
<div class="row h-100 justify-content-center align-items-center">
<div class="mx-auto" style="max-width: 30em;">
{# Splash card #}
<div class="card shadow rounded border-0 h-100">
<div class="card-header bg-primary pt-4 text-center text-white">
<img class="img-fluid mb-3" src="http://lib.msstate.edu/_assets/img/2015-header-logo-msstate.png"
alt=""/>
<h5>Electronic Thesis and Dissertation System</h5>
</div>
<div class="card-body d-flex flex-column m-2">
<form action="{{ url_for('auth.register') }}" method="post" role="form">
{# CSRF Token #}
<input type="hidden" name="csrf_token" value="{{ csrf_token() }}"/>
<h3>
Register
</h3>
<hr class="mb-4"/>
{# 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">First name</label>
<input class="form-control" id="inputFirstName" placeholder="Enter first name">
</div>
<div class="form-group">
<label class="font-weight-bold">Last name</label>
<input class="form-control" id="inputFirstName" placeholder="Enter last name">
</div>
<hr/>
<div class="form-group">
<label class="font-weight-bold">MSU ID (9-digit, no dashes)</label>
<input class="form-control" id="inputNetID" placeholder="Enter MSU ID">
</div>
<div class="form-group">
<label class="font-weight-bold">NetID</label>
<input class="form-control" id="inputNetID" placeholder="Enter NetID">
</div>
<div class="form-group">
<label class="font-weight-bold">Classification</label>
<select id="inputClass" class="form-control">
<option>Undergraduate, Freshman</option>
<option>Undergraduate, Sophomore</option>
<option>Undergraduate, Junior</option>
<option selected>Undergraduate, Senior</option>
<option>Graduate</option>
</select>
</div>
<div class="form-group">
<label class="font-weight-bold">Major</label>
<input class="form-control" id="inputNetID" placeholder="Enter Major">
</div>
<hr/>
<div class="form-group">
<label class="font-weight-bold">Password</label>
<input class="form-control" id="inputPassword" type="password" placeholder="Enter password">
</div>
<div class="form-group">
<label class="font-weight-bold">Password (again)</label>
<input class="form-control" id="inputPasswordConfirm" type="password" placeholder="Confirm password">
</div>
<button type="submit" class="btn btn-primary">Create account</button>
</form>
</div>
</div>
</div>
</div>
</div>
{% endblock %}