コード例 #1
0
 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,
     }
コード例 #2
0
 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
コード例 #3
0
 def dispatch(self, request, *args, **kwargs):
     if request.user.is_authenticated:
         # Redirect to a page which lets user choose whether or not to create a new account
         domains_for_user = Domain.active_for_user(request.user)
         if len(domains_for_user) == 0:
             return redirect("registration_domain")
         else:
             return redirect("homepage")
     response = super(UserRegistrationView,
                      self).dispatch(request, *args, **kwargs)
     if settings.IS_SAAS_ENVIRONMENT:
         ab_tests.SessionAbTest(ab_tests.DEMO_WORKFLOW,
                                request).update_response(response)
         ab_tests.SessionAbTest(ab_tests.SIGNUP_ALT_UX,
                                request).update_response(response)
     return response
コード例 #4
0
ファイル: views.py プロジェクト: dankohn/commcare-hq
def _login(req, domain_name, custom_login_page, extra_context=None):
    extra_context = extra_context or {}
    if req.user.is_authenticated and req.method == "GET":
        redirect_to = req.GET.get('next', '')
        if redirect_to:
            return HttpResponseRedirect(redirect_to)
        if not domain_name:
            return HttpResponseRedirect(reverse('homepage'))
        else:
            return HttpResponseRedirect(reverse('domain_homepage', args=[domain_name]))

    if req.method == 'POST' and domain_name and '@' not in req.POST.get('auth-username', '@'):
        with mutable_querydict(req.POST):
            req.POST['auth-username'] = format_username(req.POST['auth-username'], domain_name)

    if 'auth-username' in req.POST:
        couch_user = CouchUser.get_by_username(req.POST['auth-username'].lower())
        if couch_user:
            new_lang = couch_user.language
            old_lang = req.session.get(LANGUAGE_SESSION_KEY)
            update_session_language(req, old_lang, new_lang)

    req.base_template = settings.BASE_TEMPLATE

    context = {}
    template_name = custom_login_page if custom_login_page else 'login_and_password/login.html'
    if not custom_login_page and domain_name:
        domain_obj = Domain.get_by_name(domain_name)
        req_params = req.GET if req.method == 'GET' else req.POST
        context.update({
            'domain': domain_name,
            'hr_name': domain_obj.display_name(),
            'next': req_params.get('next', '/a/%s/' % domain_name),
            'allow_domain_requests': domain_obj.allow_domain_requests,
            'current_page': {'page_name': _('Welcome back to %s!') % domain_obj.display_name()},
        })
    else:
        commcare_hq_name = commcare_hq_names(req)['commcare_hq_names']["COMMCARE_HQ_NAME"]
        context.update({
            'current_page': {'page_name': _('Welcome back to %s!') % commcare_hq_name},
        })
    if settings.SERVER_ENVIRONMENT in settings.ICDS_ENVS:
        auth_view = CloudCareLoginView
    else:
        auth_view = HQLoginView if not domain_name else CloudCareLoginView

    demo_workflow_ab_v2 = ab_tests.SessionAbTest(ab_tests.DEMO_WORKFLOW_V2, req)

    if settings.IS_SAAS_ENVIRONMENT:
        context['demo_workflow_ab_v2'] = demo_workflow_ab_v2.context

    context.update(extra_context)
    response = auth_view.as_view(template_name=template_name, extra_context=context)(req)

    if settings.IS_SAAS_ENVIRONMENT:
        demo_workflow_ab_v2.update_response(response)

    return response
コード例 #5
0
ファイル: views.py プロジェクト: soitun/commcare-hq
    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,
        }
コード例 #6
0
 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'] = ab_tests.SessionAbTest(
             ab_tests.DEMO_WORKFLOW, self.request).context
         context['signup_ux_ab'] = ab_tests.SessionAbTest(
             ab_tests.SIGNUP_ALT_UX, self.request).context
     return context