mirror of
https://github.com/GSA/notifications-admin.git
synced 2026-09-05 23:38:25 -04:00
Remember me functionality added and tested.
Merge extra. Fixed comment.
This commit is contained in:
committed by
Adam Shimali
parent
bcf21f5ab2
commit
c959678c49
@@ -7,7 +7,8 @@ from wtforms import (
|
||||
ValidationError,
|
||||
TextAreaField,
|
||||
FileField,
|
||||
RadioField
|
||||
RadioField,
|
||||
BooleanField
|
||||
)
|
||||
from wtforms.fields.html5 import EmailField, TelField
|
||||
from wtforms.validators import DataRequired, Email, Length, Regexp
|
||||
@@ -110,6 +111,7 @@ class TwoFactorForm(Form):
|
||||
super(TwoFactorForm, self).__init__(*args, **kwargs)
|
||||
|
||||
sms_code = sms_code()
|
||||
remember_me = BooleanField("Remember me")
|
||||
|
||||
def validate_sms_code(self, field):
|
||||
is_valid, reason = self.validate_code_func(field.data)
|
||||
|
||||
@@ -7,10 +7,10 @@ from flask import (
|
||||
flash
|
||||
)
|
||||
|
||||
from flask.ext.login import current_user
|
||||
from flask.ext.login import (current_user, login_fresh, confirm_login)
|
||||
|
||||
from app.main import main
|
||||
from app.main.dao import users_dao
|
||||
from app.main.dao import (users_dao, services_dao)
|
||||
from app.main.forms import LoginForm
|
||||
|
||||
|
||||
@@ -18,11 +18,24 @@ from app.main.forms import LoginForm
|
||||
def sign_in():
|
||||
if current_user and current_user.is_authenticated():
|
||||
return redirect(url_for('main.choose_service'))
|
||||
|
||||
form = LoginForm()
|
||||
if form.validate_on_submit():
|
||||
user = users_dao.get_user_by_email(form.email_address.data)
|
||||
user = _get_and_verify_user(user, form.password.data)
|
||||
if user:
|
||||
# Remember me login
|
||||
if not login_fresh() and \
|
||||
not current_user.is_anonymous() and \
|
||||
current_user.id == user.id and \
|
||||
user.is_active():
|
||||
confirm_login()
|
||||
services = services_dao.get_services(user.id).get('data', [])
|
||||
if (len(services) == 1):
|
||||
return redirect(url_for('main.service_dashboard', service_id=services[0]['id']))
|
||||
else:
|
||||
return redirect(url_for('main.choose_service'))
|
||||
|
||||
session['user_details'] = {"email": user.email_address, "id": user.id}
|
||||
if user.state == 'pending':
|
||||
return redirect(url_for('.verify'))
|
||||
|
||||
@@ -6,8 +6,7 @@ from app.main import main
|
||||
|
||||
|
||||
@main.route('/sign-out', methods=(['GET']))
|
||||
@login_required
|
||||
def sign_out():
|
||||
session.clear()
|
||||
logout_user()
|
||||
return redirect(url_for('main.index'))
|
||||
return redirect(url_for('main.sign_in'))
|
||||
|
||||
@@ -12,7 +12,10 @@ from app.main.forms import TwoFactorForm
|
||||
@main.route('/two-factor', methods=['GET', 'POST'])
|
||||
def two_factor():
|
||||
# TODO handle user_email not in session
|
||||
user_id = session['user_details']['id']
|
||||
try:
|
||||
user_id = session['user_details']['id']
|
||||
except KeyError:
|
||||
return redirect('main.sign_in')
|
||||
|
||||
def _check_code(code):
|
||||
return users_dao.check_verify_code(user_id, code, "sms")
|
||||
@@ -27,7 +30,7 @@ def two_factor():
|
||||
if 'password' in session['user_details']:
|
||||
user.set_password(session['user_details']['password'])
|
||||
users_dao.update_user(user)
|
||||
login_user(user)
|
||||
login_user(user, remember=form.remember_me.data if form.remember_me.data else False)
|
||||
finally:
|
||||
del session['user_details']
|
||||
if (len(services) == 1):
|
||||
|
||||
Reference in New Issue
Block a user