mirror of
https://github.com/shouptech/humulus.git
synced 2026-02-03 16:09:44 +00:00
Add check box to stay logged in.
This commit is contained in:
parent
42799be7bc
commit
a3c219b5a3
3 changed files with 14 additions and 2 deletions
|
|
@ -19,7 +19,7 @@ import functools
|
|||
from flask import (Blueprint, current_app, flash, redirect, render_template,
|
||||
session, url_for)
|
||||
from flask_wtf import FlaskForm
|
||||
from wtforms import(PasswordField)
|
||||
from wtforms import PasswordField, BooleanField
|
||||
from wtforms.validators import DataRequired
|
||||
|
||||
|
||||
|
|
@ -29,6 +29,7 @@ bp = Blueprint('auth', __name__)
|
|||
class LoginForm(FlaskForm):
|
||||
"""Form for login."""
|
||||
password = PasswordField('Password', validators=[DataRequired()])
|
||||
permanent = BooleanField('Stay logged in')
|
||||
|
||||
|
||||
def login_required(view):
|
||||
|
|
@ -51,6 +52,7 @@ def login():
|
|||
if form.validate_on_submit():
|
||||
if form.password.data == current_app.config['HUMULUS_PASSWORD']:
|
||||
session.clear()
|
||||
session.permanent = form.permanent.data
|
||||
session['logged_in'] = True
|
||||
return redirect(url_for('index'))
|
||||
flash('Password is invalid.', category='warning')
|
||||
|
|
|
|||
|
|
@ -21,7 +21,8 @@
|
|||
<form method="POST" action_url="{{ url_for('auth.login') }}">
|
||||
{{ form.hidden_tag() }}
|
||||
<div class="row">
|
||||
{{ render_field_with_errors(form.password) }}
|
||||
<div>{{ render_field_with_errors(form.password) }}</div>
|
||||
<div class="pl-2">{{ render_field_with_errors(form.permanent, base_class='form-check') }}</div>
|
||||
</div>
|
||||
<div class="row">
|
||||
<button type="submit" class="btn btn-primary">Login</button>
|
||||
|
|
|
|||
|
|
@ -32,7 +32,16 @@ def test_login(client, auth):
|
|||
assert response.status_code == 302
|
||||
with client.session_transaction() as session:
|
||||
assert session['logged_in']
|
||||
assert not session.permanent
|
||||
session.clear()
|
||||
|
||||
# Test permanent login
|
||||
data = {'password': 'password', 'permanent': 'y'}
|
||||
response = client.post('/login', data=data)
|
||||
assert response.status_code == 302
|
||||
with client.session_transaction() as session:
|
||||
assert session['logged_in']
|
||||
assert session.permanent
|
||||
|
||||
def test_logout(client, auth):
|
||||
# Login
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue