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)

View File

@@ -3,30 +3,48 @@
{% from "components/page-footer.html" import page_footer %}
{% block page_title %}
Enter the codes weve sent you GOV.UK Notify
{% if form.email_code %}
Enter the codes weve sent you GOV.UK Notify
{% else %}
Enter the code weve sent you GOV.UK Notify
{% endif %}
{% endblock %}
{% block maincolumn_content %}
<div class="grid-row">
<div class="column-two-thirds">
<h1 class="heading-large">Enter the codes weve sent you</h1>
<p>
Weve sent you confirmation codes by email and text message.
</p>
{% if form.email_code %}
<h1 class="heading-large">Enter the codes weve sent you</h1>
{% else %}
<h1 class="heading-large">Enter the code weve sent you</h1>
{% endif %}
{% if form.email_code %}
<p>
Weve sent you confirmation codes by email and text message.
</p>
{% else %}
<p>
Weve sent you a confirmation code by text message.
</p>
{% endif %}
<form autocomplete="off" method="post">
{% if form.sms_code %}
{{ textbox(
form.sms_code,
width='5em',
help_link=url_for('.check_and_resend_text_code'),
help_link_text='I havent received a text message'
) }}
{{ textbox(
form.email_code,
width='5em',
help_link=url_for('.check_and_resend_email_code'),
help_link_text='I havent received an email'
) }}
form.sms_code,
width='5em',
help_link=url_for('.check_and_resend_text_code'),
help_link_text='I havent received a text message'
) }}
{% endif %}
{% if form.email_code %}
{{ textbox(
form.email_code,
width='5em',
help_link=url_for('.check_and_resend_email_code'),
help_link_text='I havent received an email'
) }}
{% endif %}
{{ page_footer("Continue") }}
</form>
</div>