Example #1
0
 def save(self, commit=True):
     user = super(RegistrationForm, self).save(commit=False)
     user.email = user.username
     user.set_password(self.cleaned_data['password'])
     if commit:
         user.save()
         if self.cleaned_data.get('subscribe'):
             newsletter.create_or_update_subscription(user, list_id=newsletter.DEFAULT_LIST_ID)
     return user
Example #2
0
 def save(self, commit=True):
     user = super(RegistrationForm, self).save(commit=False)
     user.email = user.username
     user.set_password(self.cleaned_data['password'])
     if commit:
         user.save()
         if self.cleaned_data.get('subscribe'):
             newsletter.create_or_update_subscription(
                 user, list_id=newsletter.DEFAULT_LIST_ID)
     return user
Example #3
0
    def put(self, request, user):
        """
        Update Account Subscriptionsoptions
        `````````````````````````````````

        Update account subscriptions to newsletter

        :param int listId: id of newsletter list
        :param boolean subscribed: should be subscribed to newsletter
        :auth: required
        """

        email = UserEmail.get_primary_email(user)

        # Can't handle subscriptions without a verified email
        if not email.is_verified:
            return Response(
                {
                    'details':
                    'Must have verified email to subscribe to newsletter.'
                },
                status=status.HTTP_400_BAD_REQUEST)

        subscribed = request.DATA.get('subscribed')
        try:
            list_id = int(request.DATA.get('listId', ''))
        except ValueError:
            return Response(status=status.HTTP_400_BAD_REQUEST)

        kwargs = {
            'list_id': list_id,
            'subscribed': subscribed,
            'verified': email.is_verified,
        }
        if not subscribed:
            kwargs['unsubscribed_date'] = timezone.now()
        else:
            kwargs['subscribed_date'] = timezone.now()

        newsletter.create_or_update_subscription(user, **kwargs)
        return Response(status=status.HTTP_204_NO_CONTENT)
Example #4
0
def manage_subscriptions(request):
    user = request.user
    email = UserEmail.get_primary_email(user)

    if request.method == 'GET':
        context = csrf(request)
        context.update({
            'page': 'subscriptions',
            'email': email,
            'AUTH_PROVIDERS': auth.get_auth_providers(),
            'has_newsletters': newsletter.is_enabled,
            'subscriptions': newsletter.get_subscriptions(user),
        })
        return render_to_response('sentry/account/subscriptions.html', context, request)

    subscribed = request.POST.get('subscribed') == '1'
    try:
        list_id = int(request.POST.get('listId', ''))
    except ValueError:
        return HttpResponse('bad request', status=400)

    kwargs = {
        'list_id': list_id,
        'subscribed': subscribed,
        'verified': email.is_verified,
    }
    if not subscribed:
        kwargs['unsubscribed_date'] = timezone.now()
    else:
        kwargs['subscribed_date'] = timezone.now()

    newsletter.create_or_update_subscription(
        user,
        **kwargs
    )
    return HttpResponse()