Flesh out login flow with password checks

This commit is contained in:
Tim Van Baak 2020-01-14 19:08:54 -08:00
parent 5031a7a5e7
commit d1fcba082f
7 changed files with 55 additions and 34 deletions

View File

@ -106,11 +106,13 @@ span.signature {
float: inherit;
margin: 5px auto;
}
div#content {
div#content{
margin: 5px auto;
}
div.content-2col {
max-width: 564px;
position: static;
right: inherit;
margin: 5px auto;
}
img#logo {
max-width: inherit;

View File

@ -1,4 +1,4 @@
from flask import Blueprint, render_template, redirect, url_for
from flask import Blueprint, render_template, redirect, url_for, flash
from flask_wtf import FlaskForm
from wtforms import StringField, PasswordField, BooleanField, SubmitField
from wtforms.validators import DataRequired
@ -9,8 +9,8 @@ import user
class LoginForm(FlaskForm):
username = StringField('Username', validators=[DataRequired()])
#password = PasswordField('Password', validators=[DataRequired()])
#remember = BooleanField('Remember Me')
password = PasswordField('Password', validators=[DataRequired()])
remember = BooleanField('Stay logged in')
submit = SubmitField('Log in')
def get_bp(login_manager):
@ -27,15 +27,18 @@ def get_bp(login_manager):
if form.validate_on_submit():
username = form.username.data
uid = user.uid_from_username(username)
if uid is None:
pass
if uid is not None:
u = user.user_from_uid(uid)
login_user(u)
config.logger.info("Logged in user '{}' ({})".format(u.get('username'), u.uid))
name = u.get('username')
if u.check_password(form.password.data):
remember_me = form.remember.data
login_user(u, remember=remember_me)
config.logger.info("Logged in user '{}' ({})".format(
u.get('username'), u.uid))
return redirect(url_for('home.home'))
flash("Login not recognized")
else:
name = "guest"
return render_template('auth/login.html', form=form, username=name)
pass
return render_template('auth/login.html', form=form)
@bp.route("/logout/", methods=['GET'])
@login_required

View File

@ -11,8 +11,6 @@ def get_bp():
@bp.route('/', methods=['GET'])
@login_required
def home():
return render_template(
'home/home.html',
sidebar_rows=[current_user.get('username'), current_user.get('displayname'), current_user.uid])
return render_template('home/home.html')
return bp

View File

@ -1,11 +1,22 @@
{% extends "page_1col.html" %}
{% block title %}Login | Amanuensis{% endblock %}
{% block header %}<h2>Login</h2>{% endblock %}
{% block primary_content %}
<h1>Log in</h1>
{% block header %}<h2>Amanuensis - Login</h2>{% endblock %}
{% block main %}
<form action="" method="post" novalidate>
{{ form.hidden_tag() }}
<p>{{ form.username.label }}<br>{{ form.username(size=32) }}</p>
<p>{{ form.username.label }}<br>{{ form.username(size=32) }}
{% for error in form.username.errors %}
<br><span style="color: #ff0000">{{ error }}</span>
{% endfor %}</p>
<p>{{ form.password.label }}<br>{{ form.password(size=32) }}
{% for error in form.password.errors %}
<br><span style="color: #ff0000">{{ error }}</span>
{% endfor %}</p>
<p>{{ form.remember }} {{ form.remember.label }}</p>
<p>{{ form.submit() }}</p>
</form>
{% for message in get_flashed_messages() %}
<span style="color: #ff0000">{{ message }}</span><br>
{% endfor %}
{% endblock %}
{% set template_content_blocks = [self.main()] %}

View File

@ -1,7 +1,10 @@
{% extends "page_2col.html" %}
{% block title %}Home | Amanuensis{% endblock %}
{% block header %}<h2>Amanuensis</h2>{% endblock %}
{% block primary_content %}
<p><a href="{{ url_for('home.home') }}">Home</a></p>
<p><a href="{{ url_for('auth.logout') }}">Logout</a></p>
{% block header %}<h2>Amanuensis - Dashboard</h2>{% endblock %}
{% block sb_topline %}<b>{{ current_user.get('displayname') }}</b>{% endblock %}
{% block sb_logout %}<a href="{{ url_for('auth.logout') }}">Log out</a>{% endblock %}
{% set template_sidebar_rows = [self.sb_topline(), self.sb_logout()] %}
{% block main %}
<h1>Home Page</h1>
{% endblock %}
{% set template_content_blocks = [self.main()] %}

View File

@ -11,9 +11,9 @@
<div id="header">{% block header %}{% endblock %}</div>
{% block sidebar %}{% endblock %}
<div id="content" class="{% block content_class %}{% endblock %}">
<div class="contentblock">
{% block primary_content %}{% endblock %}</div>{% for content_block in additional_content %}
<div class="contentblock">
{% if not template_content_blocks %}{% set template_content_blocks = [] %}{% endif %}
{% if not content_blocks %}{% set content_blocks = [] %}{% endif %}
{% for content_block in template_content_blocks + content_blocks %}<div class="contentblock">
{{ content_block|safe }}</div>
{% endfor %}
</div>

View File

@ -1,8 +1,12 @@
{% extends "page.html" %}
{% block sidebar %}<div id="sidebar">
<table>{% for row in sidebar_rows %}
{% block sidebar %}
<div id="sidebar">
{% if not template_sidebar_rows %}{% set template_sidebar_rows = [] %}{% endif %}
{% if not sidebar_rows %}{% set sidebar_rows = [] %}{% endif %}
<table>
{% for row in template_sidebar_rows + sidebar_rows %}
<tr><td>{{ row|safe }}</td></tr>{% endfor %}
</table>
</div>
</div>
{% endblock %}
{% block content_class %}content-2col{% endblock %}