def test_new_user_displayname_is_used_if_first_and_last_are_missing(self): """ Azure AD does not mark the First and Last names as required, only the Display Name. If First and Last are missing, ensure that this information is then obtained from the Display Name """ username = '******' reg_form = RegisterWebUserForm() reg_form.cleaned_data = { 'email': username, 'phone_number': '+15555555555', 'project_name': 'test-vault', 'persona': 'Other', 'persona_other': "for tests", } generator.store_display_name_in_saml_user_data(self.request, 'Vanessa van Beek') AsyncSignupRequest.create_from_registration_form(reg_form) user = auth.authenticate( request=self.request, username=username, idp_slug=self.idp.slug, is_handshake_successful=True, ) self.assertIsNotNone(user) self.assertEqual(user.username, username) self.assertEqual(user.first_name, 'Vanessa') self.assertEqual(user.last_name, 'van Beek') self.assertEqual(self.request.sso_new_user_messages['success'], ["User account for [email protected] created."])
def register_new_user(self, data): reg_form = RegisterWebUserForm(data['data'], show_number=self.ab_show_number) if reg_form.is_valid(): self._create_new_account(reg_form) try: request_new_domain(self.request, reg_form, is_new_user=True) except NameUnavailableException: # technically, the form should never reach this as names are # auto-generated now. But, just in case... logging.error( "There as an issue generating a unique domain name " "for a user during new registration.") return { 'errors': { 'project name unavailable': [], } } return { 'success': True, } logging.error( "There was an error processing a new user registration form." "This shouldn't happen as validation should be top-notch " "client-side. Here is what the errors are: {}".format( reg_form.errors)) return { 'errors': reg_form.errors, }
def test_new_user_created_and_data_is_saved(self): """ SsoBackend should create a new user if the username passed to does not exist and the email domain matches an AuthenticatedEmailDomain for the given IdentityProvider. It should also ensure that any user data from a registration form and/or the samlUserdata are all properly saved to the User model. """ username = '******' reg_form = RegisterWebUserForm() reg_form.cleaned_data = { 'email': username, 'phone_number': '+15555555555', 'project_name': 'test-vault', 'persona': 'Other', 'persona_other': "for tests", } generator.store_full_name_in_saml_user_data(self.request, 'Maarten', 'van der Berg') AsyncSignupRequest.create_from_registration_form(reg_form) user = auth.authenticate( request=self.request, username=username, idp_slug=self.idp.slug, is_handshake_successful=True, ) self.assertIsNotNone(user) self.assertEqual(user.username, username) self.assertEqual(user.first_name, 'Maarten') self.assertEqual(user.last_name, 'van der Berg') web_user = WebUser.get_by_username(user.username) self.assertEqual(web_user.phone_numbers[0], '+15555555555') self.assertEqual(self.request.sso_new_user_messages['success'], ["User account for [email protected] created."])
def register_new_user(self, data): reg_form = RegisterWebUserForm(data['data']) if reg_form.is_valid(): ab_test = ab_tests.SessionAbTest(ab_tests.APPCUES_V3_APP, self.request) appcues_ab_test = ab_test.context['version'] self._create_new_account(reg_form, additional_hubspot_data={ "appcues_test": appcues_ab_test, }) try: request_new_domain( self.request, reg_form, is_new_user=True ) except NameUnavailableException: # technically, the form should never reach this as names are # auto-generated now. But, just in case... logging.error("There as an issue generating a unique domain name " "for a user during new registration.") return { 'errors': { 'project name unavailable': [], } } return { 'success': True, 'appcues_ab_test': appcues_ab_test } logging.error( "There was an error processing a new user registration form." "This shouldn't happen as validation should be top-notch " "client-side. Here is what the errors are: {}".format(reg_form.errors)) return { 'errors': reg_form.errors, }
def test_new_user_displayname_with_one_name_is_used_as_first_name(self): """ Ensure that if the Azure AD "Display Name" has only one name/word in it that only the first name is populated. """ username = '******' reg_form = RegisterWebUserForm() reg_form.cleaned_data = { 'email': username, 'phone_number': '+15555555555', 'project_name': 'test-vault', 'persona': 'Other', 'persona_other': "for tests", } generator.store_display_name_in_saml_user_data(self.request, 'Test') AsyncSignupRequest.create_from_registration_form(reg_form) user = auth.authenticate( request=self.request, username=username, idp_slug=self.idp.slug, is_handshake_successful=True, ) self.assertIsNotNone(user) self.assertEqual(user.username, username) self.assertEqual(user.first_name, 'Test') self.assertEqual(user.last_name, '') self.assertEqual(self.request.sso_new_user_messages['success'], ["User account for [email protected] created."])
def register_new_user(self, data): idp = None if settings.ENFORCE_SSO_LOGIN: idp = IdentityProvider.get_required_identity_provider( data['data']['email']) reg_form = RegisterWebUserForm(data['data'], is_sso=idp is not None) if reg_form.is_valid(): ab_test = ab_tests.SessionAbTest(ab_tests.APPCUES_V3_APP, self.request) appcues_ab_test = ab_test.context['version'] if idp: signup_request = AsyncSignupRequest.create_from_registration_form( reg_form, additional_hubspot_data={ "appcues_test": appcues_ab_test, }) return { 'success': True, 'appcues_ab_test': appcues_ab_test, 'ssoLoginUrl': idp.get_login_url(signup_request.username), 'ssoIdpName': idp.name, } self._create_new_account(reg_form, additional_hubspot_data={ "appcues_test": appcues_ab_test, }) try: request_new_domain(self.request, reg_form.cleaned_data['project_name'], is_new_user=True) except NameUnavailableException: # technically, the form should never reach this as names are # auto-generated now. But, just in case... logging.error( "There as an issue generating a unique domain name " "for a user during new registration.") return { 'errors': { 'project name unavailable': [], } } return { 'success': True, 'appcues_ab_test': appcues_ab_test, } logging.error( "There was an error processing a new user registration form." "This shouldn't happen as validation should be top-notch " "client-side. Here is what the errors are: {}".format( reg_form.errors)) return { 'errors': reg_form.errors, }
def register_new_user(self, data): reg_form = RegisterWebUserForm( data['data'], show_number=self.ab_show_number, ) if reg_form.is_valid(): self._create_new_account(reg_form) try: request_new_domain(self.request, reg_form, is_new_user=True) except NameUnavailableException: # technically, the form should never reach this as names are # auto-generated now. But, just in case... logging.error( "There as an issue generating a unique domain name " "for a user during new registration.") return { 'errors': { 'project name unavailable': [], } } persona_fields = {} if reg_form.cleaned_data['persona']: persona_fields['buyer_persona'] = reg_form.cleaned_data[ 'persona'] if reg_form.cleaned_data['persona_other']: persona_fields[ 'buyer_persona_other'] = reg_form.cleaned_data[ 'persona_other'] couch_user = CouchUser.get_by_username( reg_form.cleaned_data['email']) if couch_user: update_hubspot_properties.delay(couch_user, persona_fields) return { 'success': True, 'is_mobile_experience': (reg_form.cleaned_data.get('is_mobile') and toggles.MOBILE_SIGNUP_REDIRECT_AB_TEST.enabled( reg_form.cleaned_data['email'], toggles.NAMESPACE_USER)) } logging.error( "There was an error processing a new user registration form." "This shouldn't happen as validation should be top-notch " "client-side. Here is what the errors are: {}".format( reg_form.errors)) return { 'errors': reg_form.errors, }
def register_new_user(self, data): reg_form = RegisterWebUserForm( data['data'], show_number=( self.ab.version == ab_tests.NEW_USER_NUMBER_OPTION_SHOW_NUM)) if reg_form.is_valid(): self._create_new_account(reg_form) try: requested_domain = request_new_domain(self.request, reg_form, is_new_user=True) # If user created a form via prelogin demo, create an app for them if reg_form.cleaned_data['xform']: lang = 'en' app = Application.new_app(requested_domain, "Untitled Application") module = Module.new_module(_("Untitled Module"), lang) app.add_module(module) save_xform(app, app.new_form(0, "Untitled Form", lang), reg_form.cleaned_data['xform']) app.save() web_user = WebUser.get_by_username( reg_form.cleaned_data['email']) if web_user: update_hubspot_properties(web_user, { 'signup_via_demo': 'yes', }) except NameUnavailableException: # technically, the form should never reach this as names are # auto-generated now. But, just in case... logging.error( "There as an issue generating a unique domain name " "for a user during new registration.") return { 'errors': { 'project name unavailable': [], } } return { 'success': True, } logging.error( "There was an error processing a new user registration form." "This shouldn't happen as validation should be top-notch " "client-side. Here is what the errors are: {}".format( reg_form.errors)) return { 'errors': reg_form.errors, }
def page_context(self): prefills = { 'email': self.prefilled_email, 'atypical_user': True if self.atypical_user else False } return { 'reg_form': RegisterWebUserForm( initial=prefills, show_number=self.ab_show_number, show_persona=self.ab_show_persona, ), 'reg_form_defaults': prefills, 'hide_password_feedback': settings.ENABLE_DRACONIAN_SECURITY_FEATURES, 'implement_password_obfuscation': settings.OBFUSCATE_PASSWORD_FOR_NIC_COMPLIANCE, 'show_number': self.ab_show_number, 'ab_show_number': self.ab_show_number_context, 'ab_persona_field': self.ab_persona_field.context, }
def page_context(self): prefills = { 'email': self.prefilled_email, 'atypical_user': True if self.atypical_user else False } context = { 'reg_form': RegisterWebUserForm(initial=prefills), 'reg_form_defaults': prefills, 'hide_password_feedback': has_custom_clean_password(), 'professional_features': [ _("Custom mobile app builder"), _("Powerful case management"), _("Field staff reports"), _("Unlimited mobile users"), _("Full suite of data tools"), _("3rd party integrations"), _("2-way SMS workflows"), _("Guaranteed tech support"), _("Access to Dimagi's Customer Success team"), ], 'community_features': [ _("Custom mobile app builder"), _("Basic case management"), _("Field staff reports"), _("5 mobile users"), ], } if settings.IS_SAAS_ENVIRONMENT: context['demo_workflow_ab_v2'] = ab_tests.SessionAbTest( ab_tests.DEMO_WORKFLOW_V2, self.request).context return context
def register_new_user(self, data): reg_form = RegisterWebUserForm( data['data'], show_number=self.ab_show_number, ) if reg_form.is_valid(): self._create_new_account(reg_form) try: request_new_domain(self.request, reg_form, is_new_user=True) except NameUnavailableException: # technically, the form should never reach this as names are # auto-generated now. But, just in case... logging.error( "There as an issue generating a unique domain name " "for a user during new registration.") return { 'errors': { 'project name unavailable': [], } } username = reg_form.cleaned_data['email'] appcues_ab_test = toggles.APPCUES_AB_TEST.enabled( username, toggles.NAMESPACE_USER) return { 'success': True, 'is_mobile_experience': (toggles.MOBILE_SIGNUP_REDIRECT_AB_TEST_CONTROLLER.enabled( username) and toggles.MOBILE_SIGNUP_REDIRECT_AB_TEST.enabled( username, toggles.NAMESPACE_USER)), 'appcues_ab_test': appcues_ab_test, } logging.error( "There was an error processing a new user registration form." "This shouldn't happen as validation should be top-notch " "client-side. Here is what the errors are: {}".format( reg_form.errors)) return { 'errors': reg_form.errors, }
def register_new_user(self, data): reg_form = RegisterWebUserForm(data['data']) if reg_form.is_valid(): self._create_new_account(reg_form) try: requested_domain = request_new_domain( self.request, reg_form, is_new_user=True ) # If user created a form via prelogin demo, create an app for them if reg_form.cleaned_data['xform']: lang = 'en' app = Application.new_app(requested_domain, "Untitled Application") module = Module.new_module(_("Untitled Module"), lang) app.add_module(module) save_xform(app, app.new_form(0, "Untitled Form", lang), reg_form.cleaned_data['xform']) app.save() web_user = WebUser.get_by_username(reg_form.cleaned_data['email']) if web_user: update_hubspot_properties(web_user, { 'signup_via_demo': 'yes', }) except NameUnavailableException: # technically, the form should never reach this as names are # auto-generated now. But, just in case... logging.error("There as an issue generating a unique domain name " "for a user during new registration.") return { 'errors': { 'project name unavailable': [], } } return { 'success': True, } logging.error( "There was an error processing a new user registration form." "This shouldn't happen as validation should be top-notch " "client-side. Here is what the errors are: {}".format(reg_form.errors)) return { 'errors': reg_form.errors, }
def page_context(self): prefills = { 'email': self.prefilled_email, 'xform': self.prefilled_xform, } return { 'reg_form': RegisterWebUserForm( initial=prefills ), 'reg_form_defaults': prefills, 'hide_password_feedback': settings.ENABLE_DRACONIAN_SECURITY_FEATURES, }
def page_context(self): prefills = { 'email': self.prefilled_email, 'atypical_user': True if self.atypical_user else False } context = { 'reg_form': RegisterWebUserForm(initial=prefills), 'reg_form_defaults': prefills, 'hide_password_feedback': settings.ENABLE_DRACONIAN_SECURITY_FEATURES, 'implement_password_obfuscation': settings.OBFUSCATE_PASSWORD_FOR_NIC_COMPLIANCE, } if settings.IS_SAAS_ENVIRONMENT: context['demo_workflow_ab_v2'] = ab_tests.SessionAbTest( ab_tests.DEMO_WORKFLOW_V2, self.request).context return context
def page_context(self): prefills = { 'email': self.prefilled_email, 'atypical_user': True if self.atypical_user else False } return { 'reg_form': RegisterWebUserForm( initial=prefills, show_number=self.ab_show_number, ), 'reg_form_defaults': prefills, 'hide_password_feedback': settings.ENABLE_DRACONIAN_SECURITY_FEATURES, 'show_number': self.ab_show_number, 'ab_test': self.ab_context, }
def page_context(self): prefills = { 'email': self.prefilled_email, 'xform': self.prefilled_xform, 'atypical_user': True if self.atypical_user else False } return { 'reg_form': RegisterWebUserForm( initial=prefills, show_number=(self.ab.version == ab_tests.NEW_USER_NUMBER_OPTION_SHOW_NUM), ), 'reg_form_defaults': prefills, 'hide_password_feedback': settings.ENABLE_DRACONIAN_SECURITY_FEATURES, 'show_number': (self.ab.version == ab_tests.NEW_USER_NUMBER_OPTION_SHOW_NUM), 'ab_test': self.ab.context, }