def user_save_callback(sender, **kwargs): couch_user = kwargs.get("couch_user", None) if couch_user and couch_user.is_web_user(): properties = {} properties.update(get_subscription_properties_by_user(couch_user)) properties.update(get_domain_membership_properties(couch_user)) identify.delay(couch_user.username, properties) update_hubspot_properties.delay(couch_user, properties)
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 post(self, request, domain, *args, **kwargs): self.domain_object.requested_report_builder_subscription.append( request.user.username) self.domain_object.save() send_mail_async.delay( "Report Builder Subscription Request: {}".format(domain), "User {} in the {} domain has requested a report builder subscription." " Current subscription is '{}'.".format(request.user.username, domain, self.plan_name), settings.DEFAULT_FROM_EMAIL, [settings.REPORT_BUILDER_ADD_ON_EMAIL], ) update_hubspot_properties.delay( request.couch_user, {'report_builder_subscription_request': 'yes'}) return self.get(request, domain, *args, **kwargs)
def post(self, request, domain, *args, **kwargs): self.domain_object.requested_report_builder_subscription.append(request.user.username) self.domain_object.save() send_mail_async.delay( "Report Builder Subscription Request: {}".format(domain), "User {} in the {} domain has requested a report builder subscription." " Current subscription is '{}'.".format( request.user.username, domain, self.plan_name ), settings.DEFAULT_FROM_EMAIL, [settings.REPORT_BUILDER_ADD_ON_EMAIL], ) update_hubspot_properties.delay(request.couch_user, {'report_builder_subscription_request': 'yes'}) return self.get(request, domain, *args, **kwargs)
def __call__(self, request, invitation_id, **kwargs): logging.warning("Don't use this view in more apps until it gets cleaned up.") # add the correct parameters to this instance self.request = request self.inv_id = invitation_id if 'domain' in kwargs: self.domain = kwargs['domain'] if request.GET.get('switch') == 'true': logout(request) return redirect_to_login(request.path) if request.GET.get('create') == 'true': logout(request) return HttpResponseRedirect(request.path) try: invitation = Invitation.get(invitation_id) except ResourceNotFound: messages.error(request, _("Sorry, it looks like your invitation has expired. " "Please check the invitation link you received and try again, or request a " "project administrator to send you the invitation again.")) return HttpResponseRedirect(reverse("login")) if invitation.is_accepted: messages.error(request, _("Sorry, that invitation has already been used up. " "If you feel this is a mistake please ask the inviter for " "another invitation.")) return HttpResponseRedirect(reverse("login")) self.validate_invitation(invitation) if invitation.is_expired: return HttpResponseRedirect(reverse("no_permissions")) context = self.added_context() if request.user.is_authenticated(): is_invited_user = request.couch_user.username.lower() == invitation.email.lower() if self.is_invited(invitation, request.couch_user) and not request.couch_user.is_superuser: if is_invited_user: # if this invite was actually for this user, just mark it accepted messages.info(request, _("You are already a member of {entity}.").format( entity=self.inviting_entity)) invitation.is_accepted = True invitation.save() else: messages.error(request, _("It looks like you are trying to accept an invitation for " "{invited} but you are already a member of {entity} with the " "account {current}. Please sign out to accept this invitation " "as another user.").format( entity=self.inviting_entity, invited=invitation.email, current=request.couch_user.username, )) return HttpResponseRedirect(self.redirect_to_on_success) if not is_invited_user: messages.error(request, _("The invited user {invited} and your user {current} do not match!").format( invited=invitation.email, current=request.couch_user.username)) if request.method == "POST": couch_user = CouchUser.from_django_user(request.user) self._invite(invitation, couch_user) track_workflow(request.couch_user.get_email(), "Current user accepted a project invitation", {"Current user accepted a project invitation": "yes"}) update_hubspot_properties.delay(request.couch_user, {'user_accepted_domain_invitation': 'yes'}) return HttpResponseRedirect(self.redirect_to_on_success) else: mobile_user = CouchUser.from_django_user(request.user).is_commcare_user() context.update({ 'mobile_user': mobile_user, "invited_user": invitation.email if request.couch_user.username != invitation.email else "", }) return render(request, self.template, context) else: if request.method == "POST": form = NewWebUserRegistrationForm(request.POST) if form.is_valid(): # create the new user user = activate_new_user(form) user.save() messages.success(request, _("User account for %s created!") % form.cleaned_data["email"]) self._invite(invitation, user) authenticated = authenticate(username=form.cleaned_data["email"], password=form.cleaned_data["password"]) if authenticated is not None and authenticated.is_active: login(request, authenticated) track_workflow(request.POST['email'], "New User Accepted a project invitation", {"New User Accepted a project invitation": "yes"}) update_hubspot_properties.delay(user, {'new_user_accepted_invitation_created_account': 'yes'}) return HttpResponseRedirect(reverse("domain_homepage", args=[invitation.domain])) else: if CouchUser.get_by_username(invitation.email): return HttpResponseRedirect(reverse("login") + '?next=' + reverse('domain_accept_invitation', args=[invitation.domain, invitation.get_id])) domain = Domain.get_by_name(invitation.domain) form = NewWebUserRegistrationForm(initial={ 'email': invitation.email, 'hr_name': domain.display_name() if domain else invitation.domain, 'create_domain': False, }) context.update({"form": form}) return render(request, self.template, context)