Skip to content
Snippets Groups Projects
Commit c8adbed3 authored by Jae's avatar Jae
Browse files

Add 'Remember me' button, fixes #57

parent c197e14c
No related branches found
No related tags found
1 merge request!20Add 'remember me' button
Pipeline #1965 canceled
...@@ -4,10 +4,10 @@ from flask_babel import lazy_gettext as _ ...@@ -4,10 +4,10 @@ from flask_babel import lazy_gettext as _
import flask_wtf import flask_wtf
class LoginForm(flask_wtf.FlaskForm): class LoginForm(flask_wtf.FlaskForm):
username = fields.StringField(_('Username'), [validators.DataRequired()]) username = fields.StringField(_('Username'), [validators.DataRequired()])
password = fields.PasswordField(_('Password'), [validators.DataRequired()]) password = fields.PasswordField(_('Password'), [validators.DataRequired()])
remember_me = fields.BooleanField("Remember me", default=False)
submit = fields.SubmitField(_('Sign in')) submit = fields.SubmitField(_('Sign in'))
......
from hiboo import models, utils, security from hiboo import models, utils, security
from hiboo.account import blueprint, forms from hiboo.account import blueprint, forms
from flask_babel import lazy_gettext as _ from flask_babel import lazy_gettext as _
from flask import session
import datetime import datetime
import flask_login import flask_login
import flask import flask
import sys
@blueprint.route("/signin", methods=["GET", "POST"]) @blueprint.route("/signin", methods=["GET", "POST"])
def signin(): def signin():
...@@ -14,6 +15,8 @@ def signin(): ...@@ -14,6 +15,8 @@ def signin():
user = models.User.login(form.username.data, form.password.data) user = models.User.login(form.username.data, form.password.data)
if user: if user:
flask_login.login_user(user) flask_login.login_user(user)
if form.remember_me.data == True:
session.permanent = True
return flask.redirect(utils.url_or_intent(".home")) return flask.redirect(utils.url_or_intent(".home"))
else: else:
flask.flash(_("Wrong credentials"), "danger") flask.flash(_("Wrong credentials"), "danger")
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment