diff --git a/app/main/dao/users_dao.py b/app/main/dao/users_dao.py index 0a6e3e891..0b9432943 100644 --- a/app/main/dao/users_dao.py +++ b/app/main/dao/users_dao.py @@ -57,8 +57,8 @@ def request_password_reset(user): user_api_client.update_user(user) -def send_verify_code(user_id, code_type, to=None): - return user_api_client.send_verify_code(user_id, code_type, to=to) +def send_verify_code(user_id, code_type, to): + return user_api_client.send_verify_code(user_id, code_type, to) def check_verify_code(user_id, code, code_type): diff --git a/app/main/views/code_not_received.py b/app/main/views/code_not_received.py index 5c4ef76b6..41d071754 100644 --- a/app/main/views/code_not_received.py +++ b/app/main/views/code_not_received.py @@ -43,5 +43,5 @@ def verification_code_not_received(): def check_and_resend_verification_code(): # TODO there needs to be a way to generate a new session id user = users_dao.get_user_by_email(session['user_details']['email']) - users_dao.send_verify_code(user.id, 'sms') + users_dao.send_verify_code(user.id, 'sms', user.mobile_number) return redirect(url_for('main.two_factor')) diff --git a/app/main/views/new_password.py b/app/main/views/new_password.py index 23cd5c981..4b28a8504 100644 --- a/app/main/views/new_password.py +++ b/app/main/views/new_password.py @@ -21,7 +21,7 @@ def new_password(token): form = NewPasswordForm() if form.validate_on_submit(): - users_dao.send_verify_code(user.id, 'sms') + users_dao.send_verify_code(user.id, 'sms', user.mobile_number) session['user_details'] = { 'id': user.id, 'email': user.email_address, diff --git a/app/main/views/register.py b/app/main/views/register.py index 1e9d488bf..25c1e0e78 100644 --- a/app/main/views/register.py +++ b/app/main/views/register.py @@ -45,8 +45,8 @@ def register(): # How do we report to the user there is a problem with # sending codes apart from service unavailable? # at the moment i believe http 500 is fine. - users_dao.send_verify_code(user.id, 'sms') - users_dao.send_verify_code(user.id, 'email') + users_dao.send_verify_code(user.id, 'sms', user.mobile_number) + users_dao.send_verify_code(user.id, 'email', user.email_address) session['expiry_date'] = str(datetime.now() + timedelta(hours=1)) session['user_details'] = {"email": user.email_address, "id": user.id} return redirect(url_for('main.verify')) diff --git a/app/main/views/sign_in.py b/app/main/views/sign_in.py index 376451cd9..fc27a366e 100644 --- a/app/main/views/sign_in.py +++ b/app/main/views/sign_in.py @@ -27,7 +27,7 @@ def sign_in(): if user.state == 'pending': return redirect(url_for('.verify')) elif user.is_active(): - users_dao.send_verify_code(user.id, 'sms') + users_dao.send_verify_code(user.id, 'sms', user.mobile_number) return redirect(url_for('.two_factor')) # Vague error message for login in case of user not known, locked, inactive or password not verified flash('Username or password is incorrect') diff --git a/app/main/views/user_profile.py b/app/main/views/user_profile.py index 1d230ee6a..394baf775 100644 --- a/app/main/views/user_profile.py +++ b/app/main/views/user_profile.py @@ -74,7 +74,7 @@ def user_profile_email_authenticate(): if form.validate_on_submit(): session[NEW_EMAIL_PASSWORD_CONFIRMED] = True - send_verify_code(current_user.id, 'email', to=session[NEW_EMAIL]) + send_verify_code(current_user.id, 'email', session[NEW_EMAIL]) return redirect(url_for('.user_profile_email_confirm')) return render_template( @@ -142,7 +142,7 @@ def user_profile_mobile_number_authenticate(): if form.validate_on_submit(): session[NEW_MOBILE_PASSWORD_CONFIRMED] = True - send_verify_code(current_user.id, 'sms', to=session[NEW_MOBILE]) + send_verify_code(current_user.id, 'sms', session[NEW_MOBILE]) return redirect(url_for('.user_profile_mobile_number_confirm')) return render_template( diff --git a/app/notify_client/user_api_client.py b/app/notify_client/user_api_client.py index 169b61bac..d340430bb 100644 --- a/app/notify_client/user_api_client.py +++ b/app/notify_client/user_api_client.py @@ -64,8 +64,8 @@ class UserApiClient(BaseAPIClient): return user[0] return None - def send_verify_code(self, user_id, code_type, to=None): - data = {'to': to} if to else {} + def send_verify_code(self, user_id, code_type, to): + data = {'to': to} endpoint = '/user/{0}/{1}-code'.format(user_id, code_type) resp = self.post(endpoint, data=data)