예제 #1
0
 def form_valid(self, request, form):
     """If the form is valid, try subscribing the email to our MailChimp newsletters."""
     email = form.cleaned_data['email']
     list_ = form.cleaned_data['list']
     default = form.cleaned_data['default']
     default_list = settings.MAILCHIMP_LIST_DEFAULT if default else None
     # First try subscribing the user to the list they are signing up for.
     path = request.GET.get('next', request.path)
     url = u'{}{}'.format(settings.MUCKROCK_URL, path)
     primary_error = mailchimp_subscribe(
         request,
         email,
         list_,
         source='Newsletter Sign Up Form',
         url=url,
     )
     # Add the user to the default list if they want to be added.
     # If an error occurred with the first subscription,
     # don't try signing up for the default list.
     # If an error occurs with this subscription, don't worry about it.
     if default_list is not None and default_list != list_ and not primary_error:
         mailchimp_subscribe(
             request,
             email,
             default_list,
             suppress_msg=True,
             source='Newsletter Sign Up Form',
             url=url,
         )
     return self.redirect_url(request)
예제 #2
0
파일: mixins.py 프로젝트: WPMedia/muckrock
    def miniregister(self, form, full_name, email, newsletter=False):
        """Create a new user from their full name and email"""
        full_name = full_name.strip()

        user_json = self._create_squarelet_user(form, {
            "name": full_name,
            "preferred_username": full_name,
            "email": email
        })

        user, _ = Profile.objects.squarelet_update_or_create(
            user_json["uuid"], user_json)
        login(self.request,
              user,
              backend="muckrock.accounts.backends.SquareletBackend")

        if newsletter:
            mailchimp_subscribe(
                self.request,
                user.email,
                source="Mini-Register: {}".format(self.minireg_source),
                url="{}{}".format(settings.MUCKROCK_URL, self.request.path),
            )

        mixpanel_event(
            self.request,
            "Sign Up",
            {
                "Source": "Mini-Register: {}".format(self.minireg_source),
                "Newsletter": newsletter,
            },
            signup=True,
        )
        return user
예제 #3
0
    def miniregister(self, full_name, email, newsletter=False):
        """Create a new user from their full name and email and login"""
        password = generate_key(12)
        full_name = full_name.strip()
        username = unique_username(full_name)
        first_name, last_name = split_name(full_name)
        # create a new User
        user = User.objects.create_user(username,
                                        email,
                                        password,
                                        first_name=first_name,
                                        last_name=last_name)
        # create a new Profile
        Profile.objects.create(user=user,
                               acct_type='basic',
                               monthly_requests=settings.MONTHLY_REQUESTS.get(
                                   'basic', 0),
                               date_update=date.today())
        # send the new user a welcome email
        welcome_miniregister.delay(user)
        user = authenticate(
            username=user.username,
            password=password,
        )
        login(self.request, user)
        if newsletter:
            mailchimp_subscribe(
                self.request,
                user.email,
                source='Mini-Register: {}'.format(self.minireg_source),
                url='https://{}{}'.format(settings.MUCKROCK_URL,
                                          self.request.path),
            )

        mixpanel_event(
            self.request,
            'Sign Up',
            {
                'Source': 'Mini-Register: {}'.format(self.minireg_source),
                'Newsletter': newsletter,
            },
            signup=True,
        )
        return user
예제 #4
0
    def miniregister(self, form, full_name, email, newsletter=False):
        """Create a new user from their full name and email"""
        full_name = full_name.strip()

        user_json = self._create_squarelet_user(
            form,
            {
                'name': full_name,
                'preferred_username': full_name,
                'email': email,
            },
        )

        user, _ = Profile.objects.squarelet_update_or_create(
            user_json['uuid'], user_json
        )
        login(
            self.request,
            user,
            backend='muckrock.accounts.backends.SquareletBackend',
        )

        if newsletter:
            mailchimp_subscribe(
                self.request,
                user.email,
                source='Mini-Register: {}'.format(self.minireg_source),
                url='{}{}'.format(settings.MUCKROCK_URL, self.request.path),
            )

        mixpanel_event(
            self.request,
            'Sign Up',
            {
                'Source': 'Mini-Register: {}'.format(self.minireg_source),
                'Newsletter': newsletter,
            },
            signup=True,
        )
        return user