Removed exceptions, found a better way to handle them.

Refactored the forms so that fields like email_address can be used in multiple forms.
Refactored form validation so that a query function is passed into the form to be run, this
way the form is not exposed to the dao layer and the query is more efficient.

This PR still requires some frontend attention. Will work with Chris to update the templates.
This commit is contained in:
Rebecca Law
2016-01-08 15:12:14 +00:00
parent ceb78f49b4
commit c858869a52
13 changed files with 96 additions and 121 deletions

View File

@@ -57,9 +57,8 @@ class LoginForm(Form):
class RegisterUserForm(Form):
def __init__(self, existing_email_addresses, existing_mobile_numbers, *args, **kwargs):
def __init__(self, existing_email_addresses, *args, **kwargs):
self.existing_emails = existing_email_addresses
self.existing_mobiles = existing_mobile_numbers
super(RegisterUserForm, self).__init__(*args, **kwargs)
name = StringField('Full name',
@@ -70,16 +69,9 @@ class RegisterUserForm(Form):
def validate_email_address(self, field):
# Validate email address is unique.
if field.data in self.existing_emails:
if self.existing_emails(field.data):
raise ValidationError('Email address already exists')
def validate_mobile_number(self, field):
# Validate mobile number is unique
# Code to re-added later
# if field.data in self.existing_mobiles:
# raise ValidationError('Mobile number already exists')
pass
class TwoFactorForm(Form):
def __init__(self, user_codes, *args, **kwargs):
@@ -132,6 +124,14 @@ class AddServiceForm(Form):
class ForgotPasswordForm(Form):
email_address = email_address()
def __init__(self, q, *args, **kwargs):
self.query_function = q
super(ForgotPasswordForm, self).__init__(*args, *kwargs)
def validate_email_address(self, a):
if not self.query_function(a.data):
raise ValidationError('The email address is not recognized. Enter the password you registered with.')
class NewPasswordForm(Form):
new_password = password()