refactor RegisterFromInvite to make auth_type required, and update test fixtures

This commit is contained in:
Leo Hemsted
2017-11-13 13:39:31 +00:00
parent 79393c97ef
commit 65ba7e88c8
8 changed files with 61 additions and 98 deletions

View File

@@ -171,13 +171,11 @@ class RegisterUserForm(Form):
email_address = email_address()
mobile_number = international_phone_number()
password = password()
# always register as sms type
auth_type = HiddenField('auth_type', default='sms_auth')
class RegisterUserFromInviteForm(Form):
def __init__(self, auth_type, *args, **kwargs):
self.auth_type = auth_type
super().__init__(*args, **kwargs)
name = StringField(
'Full name',
validators=[DataRequired(message='Cant be empty')]
@@ -186,9 +184,10 @@ class RegisterUserFromInviteForm(Form):
password = password()
service = HiddenField('service')
email_address = HiddenField('email_address')
auth_type = HiddenField('auth_type', validators=[DataRequired()])
def validate_mobile_number(self, field):
if self.auth_type == 'sms_auth' and not field.data:
if self.auth_type.data == 'sms_auth' and not field.data:
raise ValidationError('Cant be empty')