mirror of
https://github.com/GSA/notifications-admin.git
synced 2026-08-21 14:59:47 -04:00
refactor RegisterFromInvite to make auth_type required, and update test fixtures
This commit is contained in:
@@ -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='Can’t 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('Can’t be empty')
|
||||
|
||||
|
||||
|
||||
@@ -43,7 +43,7 @@ def register():
|
||||
@main.route('/register-from-invite', methods=['GET', 'POST'])
|
||||
def register_from_invite():
|
||||
invited_user = session.get('invited_user')
|
||||
form = RegisterUserFromInviteForm(invited_user['auth_type'])
|
||||
form = RegisterUserFromInviteForm()
|
||||
if not invited_user:
|
||||
abort(404)
|
||||
|
||||
@@ -70,7 +70,8 @@ def _do_registration(form, service=None, send_sms=True, send_email=True):
|
||||
user = user_api_client.register_user(form.name.data,
|
||||
form.email_address.data,
|
||||
form.mobile_number.data,
|
||||
form.password.data)
|
||||
form.password.data,
|
||||
form.auth_type.data)
|
||||
|
||||
# TODO possibly there should be some exception handling
|
||||
# for sending sms and email codes.
|
||||
|
||||
Reference in New Issue
Block a user