def verify():
    form = VerifyCodeForm()
    if request.method == 'POST':
        if form.validate_on_submit():
            user = User.query.filter(User.email == form.email.data).first()

            if user == None:
                form.email.errors.append(account_verification_flask.utilities.User_Not_Found_For_Given_Email)
                return view('verify_registration_code', form)

            if user.phone_number_confirmed:
                form.email.errors.append(User_Already_Confirmed)
                return view('verify_registration_code', form)

            authy_services = AuthyServices()
            if authy_services.confirm_phone_number(user, form.verification_code.data):
                user.phone_number_confirmed = True
                db.session.commit()
                login_user(user, remember=True)
                twilio_services = TwilioServices()
                twilio_services.send_registration_success_sms("+{0}{1}".format(user.country_code, user.phone_number))
                return redirect_to('status')
            else:
                form.email.errors.append(account_verification_flask.utilities.Verification_Unsuccessful)
                return view('verify_registration_code', form)
    else:
        form.email.data = request.args.get('email')
    return view('verify_registration_code', form)
def verify():
    form = VerifyCodeForm()
    if request.method == 'POST':
        if form.validate_on_submit():
            user = User.query.filter(User.email == form.email.data).first()

            if user == None:
                form.email.errors.append(account_verification_flask.utilities.
                                         User_Not_Found_For_Given_Email)
                return view('verify_registration_code', form)

            if user.phone_number_confirmed:
                form.email.errors.append(User_Already_Confirmed)
                return view('verify_registration_code', form)

            authy_services = AuthyServices()
            if authy_services.confirm_phone_number(
                    user, form.verification_code.data):
                user.phone_number_confirmed = True
                db.session.commit()
                login_user(user, remember=True)
                twilio_services = TwilioServices()
                twilio_services.send_registration_success_sms("+{0}{1}".format(
                    user.country_code, user.phone_number))
                return redirect_to('status')
            else:
                form.email.errors.append(account_verification_flask.utilities.
                                         Verification_Unsuccessful)
                return view('verify_registration_code', form)
    else:
        form.email.data = request.args.get('email')
    return view('verify_registration_code', form)
 def _get_authy_wrong_code_validator(self):
     authy_service_mock = AuthyServices()
     authy_service_mock.confirm_phone_number = MagicMock(
         return_value=True,
         side_effect=self._confirm_phone_number_wrong_side_effect)
     return authy_service_mock
 def _get_authy_wrong_code_validator(self):
     authy_service_mock = AuthyServices()
     authy_service_mock.confirm_phone_number = MagicMock(
         return_value=True, side_effect=self._confirm_phone_number_wrong_side_effect
     )
     return authy_service_mock