Flesh out login flow with password checks
This commit is contained in:
parent
5031a7a5e7
commit
d1fcba082f
|
@ -106,11 +106,13 @@ span.signature {
|
||||||
float: inherit;
|
float: inherit;
|
||||||
margin: 5px auto;
|
margin: 5px auto;
|
||||||
}
|
}
|
||||||
div#content {
|
div#content{
|
||||||
|
margin: 5px auto;
|
||||||
|
}
|
||||||
|
div.content-2col {
|
||||||
max-width: 564px;
|
max-width: 564px;
|
||||||
position: static;
|
position: static;
|
||||||
right: inherit;
|
right: inherit;
|
||||||
margin: 5px auto;
|
|
||||||
}
|
}
|
||||||
img#logo {
|
img#logo {
|
||||||
max-width: inherit;
|
max-width: inherit;
|
||||||
|
|
|
@ -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 flask_wtf import FlaskForm
|
||||||
from wtforms import StringField, PasswordField, BooleanField, SubmitField
|
from wtforms import StringField, PasswordField, BooleanField, SubmitField
|
||||||
from wtforms.validators import DataRequired
|
from wtforms.validators import DataRequired
|
||||||
|
@ -9,8 +9,8 @@ import user
|
||||||
|
|
||||||
class LoginForm(FlaskForm):
|
class LoginForm(FlaskForm):
|
||||||
username = StringField('Username', validators=[DataRequired()])
|
username = StringField('Username', validators=[DataRequired()])
|
||||||
#password = PasswordField('Password', validators=[DataRequired()])
|
password = PasswordField('Password', validators=[DataRequired()])
|
||||||
#remember = BooleanField('Remember Me')
|
remember = BooleanField('Stay logged in')
|
||||||
submit = SubmitField('Log in')
|
submit = SubmitField('Log in')
|
||||||
|
|
||||||
def get_bp(login_manager):
|
def get_bp(login_manager):
|
||||||
|
@ -27,15 +27,18 @@ def get_bp(login_manager):
|
||||||
if form.validate_on_submit():
|
if form.validate_on_submit():
|
||||||
username = form.username.data
|
username = form.username.data
|
||||||
uid = user.uid_from_username(username)
|
uid = user.uid_from_username(username)
|
||||||
if uid is None:
|
if uid is not None:
|
||||||
pass
|
|
||||||
u = user.user_from_uid(uid)
|
u = user.user_from_uid(uid)
|
||||||
login_user(u)
|
if u.check_password(form.password.data):
|
||||||
config.logger.info("Logged in user '{}' ({})".format(u.get('username'), u.uid))
|
remember_me = form.remember.data
|
||||||
name = u.get('username')
|
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:
|
else:
|
||||||
name = "guest"
|
pass
|
||||||
return render_template('auth/login.html', form=form, username=name)
|
return render_template('auth/login.html', form=form)
|
||||||
|
|
||||||
@bp.route("/logout/", methods=['GET'])
|
@bp.route("/logout/", methods=['GET'])
|
||||||
@login_required
|
@login_required
|
||||||
|
|
|
@ -11,8 +11,6 @@ def get_bp():
|
||||||
@bp.route('/', methods=['GET'])
|
@bp.route('/', methods=['GET'])
|
||||||
@login_required
|
@login_required
|
||||||
def home():
|
def home():
|
||||||
return render_template(
|
return render_template('home/home.html')
|
||||||
'home/home.html',
|
|
||||||
sidebar_rows=[current_user.get('username'), current_user.get('displayname'), current_user.uid])
|
|
||||||
|
|
||||||
return bp
|
return bp
|
||||||
|
|
|
@ -1,11 +1,22 @@
|
||||||
{% extends "page_1col.html" %}
|
{% extends "page_1col.html" %}
|
||||||
{% block title %}Login | Amanuensis{% endblock %}
|
{% block title %}Login | Amanuensis{% endblock %}
|
||||||
{% block header %}<h2>Login</h2>{% endblock %}
|
{% block header %}<h2>Amanuensis - Login</h2>{% endblock %}
|
||||||
{% block primary_content %}
|
{% block main %}
|
||||||
<h1>Log in</h1>
|
|
||||||
<form action="" method="post" novalidate>
|
<form action="" method="post" novalidate>
|
||||||
{{ form.hidden_tag() }}
|
{{ 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>
|
<p>{{ form.submit() }}</p>
|
||||||
</form>
|
</form>
|
||||||
|
{% for message in get_flashed_messages() %}
|
||||||
|
<span style="color: #ff0000">{{ message }}</span><br>
|
||||||
|
{% endfor %}
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
{% set template_content_blocks = [self.main()] %}
|
|
@ -1,7 +1,10 @@
|
||||||
{% extends "page_2col.html" %}
|
{% extends "page_2col.html" %}
|
||||||
{% block title %}Home | Amanuensis{% endblock %}
|
{% block title %}Home | Amanuensis{% endblock %}
|
||||||
{% block header %}<h2>Amanuensis</h2>{% endblock %}
|
{% block header %}<h2>Amanuensis - Dashboard</h2>{% endblock %}
|
||||||
{% block primary_content %}
|
{% block sb_topline %}<b>{{ current_user.get('displayname') }}</b>{% endblock %}
|
||||||
<p><a href="{{ url_for('home.home') }}">Home</a></p>
|
{% block sb_logout %}<a href="{{ url_for('auth.logout') }}">Log out</a>{% endblock %}
|
||||||
<p><a href="{{ url_for('auth.logout') }}">Logout</a></p>
|
{% set template_sidebar_rows = [self.sb_topline(), self.sb_logout()] %}
|
||||||
|
{% block main %}
|
||||||
|
<h1>Home Page</h1>
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
{% set template_content_blocks = [self.main()] %}
|
|
@ -11,9 +11,9 @@
|
||||||
<div id="header">{% block header %}{% endblock %}</div>
|
<div id="header">{% block header %}{% endblock %}</div>
|
||||||
{% block sidebar %}{% endblock %}
|
{% block sidebar %}{% endblock %}
|
||||||
<div id="content" class="{% block content_class %}{% endblock %}">
|
<div id="content" class="{% block content_class %}{% endblock %}">
|
||||||
<div class="contentblock">
|
{% if not template_content_blocks %}{% set template_content_blocks = [] %}{% endif %}
|
||||||
{% block primary_content %}{% endblock %}</div>{% for content_block in additional_content %}
|
{% if not content_blocks %}{% set content_blocks = [] %}{% endif %}
|
||||||
<div class="contentblock">
|
{% for content_block in template_content_blocks + content_blocks %}<div class="contentblock">
|
||||||
{{ content_block|safe }}</div>
|
{{ content_block|safe }}</div>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -1,8 +1,12 @@
|
||||||
{% extends "page.html" %}
|
{% extends "page.html" %}
|
||||||
{% block sidebar %}<div id="sidebar">
|
{% block sidebar %}
|
||||||
<table>{% for row in sidebar_rows %}
|
<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 %}
|
<tr><td>{{ row|safe }}</td></tr>{% endfor %}
|
||||||
</table>
|
</table>
|
||||||
</div>
|
</div>
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
{% block content_class %}content-2col{% endblock %}
|
{% block content_class %}content-2col{% endblock %}
|
Loading…
Reference in New Issue