Merge pull request #269 from alphagov/invite-registration-sms-only

Change new invite registration flow to only need
This commit is contained in:
Adam Shimali
2016-03-14 10:55:31 +00:00
5 changed files with 66 additions and 24 deletions

View File

@@ -150,6 +150,23 @@ class TwoFactorForm(Form):
raise ValidationError(reason)
class VerifySmsForm(Form):
def __init__(self, validate_code_func, *args, **kwargs):
'''
Keyword arguments:
validate_code_func -- Validates the code with the API.
'''
self.validate_code_func = validate_code_func
super(VerifySmsForm, self).__init__(*args, **kwargs)
sms_code = sms_code()
def validate_sms_code(self, field):
is_valid, reason = self.validate_code_func(field.data, 'sms')
if not is_valid:
raise ValidationError(reason)
class VerifyForm(Form):
def __init__(self, validate_code_func, *args, **kwargs):
'''

View File

@@ -9,7 +9,10 @@ from flask_login import login_user
from app.main import main
from app.main.dao import users_dao
from app.main.forms import VerifyForm
from app.main.forms import (
VerifyForm,
VerifySmsForm
)
@main.route('/verify', methods=['GET', 'POST'])
@@ -22,7 +25,11 @@ def verify():
def _check_code(code, code_type):
return users_dao.check_verify_code(user_id, code, code_type)
form = VerifyForm(_check_code)
if session.get('invited_user'):
form = VerifySmsForm(_check_code)
else:
form = VerifyForm(_check_code)
if form.validate_on_submit():
try:
user = users_dao.get_user_by_id(user_id)