示例#1
0
 def test_expiration(self):
     token = email.build_email_change_token(self.user, '*****@*****.**')
     time.sleep(1.1)
     try:
         email.verify_email_change_token(self.user, token, max_age=1)
         self.fail('Should have thrown exception')
     except ValueError as e:
         self.assertTrue('Signature age' in str(e))
示例#2
0
 def test_expiration(self):
     token = email.build_email_change_token(self.user, '*****@*****.**')
     time.sleep(1.1)
     try:
         email.verify_email_change_token(self.user, token, max_age=1)
         self.fail('Should have thrown exception')
     except ValueError as e:
         self.assertTrue('Signature age' in str(e))
示例#3
0
def notifications(request):
    # TODO(mikey): Dynamically add settings forms for other e-mail
    # backends (currently hardcoded to email backend).

    context = {}
    existing_settings = models.NotificationSettings.objects.get_or_create(
        user=request.user,
        backend="pykeg.notification.backends.email.EmailNotificationBackend"
    )[0]

    if request.method == "POST":
        if "submit-settings" in request.POST:
            form = NotificationSettingsForm(request.POST,
                                            instance=existing_settings)
            if form.is_valid():
                instance = form.save(commit=False)
                instance.user = request.user
                instance.backend = "pykeg.notification.backends.email.EmailNotificationBackend"
                instance.save()
                messages.success(request, "Settings updated")
                existing_settings = instance

        elif "submit-email" in request.POST:
            form = forms.ChangeEmailForm(request.POST)
            if form.is_valid():
                new_email = form.cleaned_data["email"]
                if new_email == request.user.email:
                    messages.warning(request, "E-mail address unchanged.")
                else:
                    token = email.build_email_change_token(
                        request.user, new_email)
                    url = models.KegbotSite.get().reverse_full(
                        "account-confirm-email",
                        args=(),
                        kwargs={"token": token})

                    email_context = {
                        "url": url,
                        "site_name": request.kbsite.title
                    }
                    message = email.build_message(
                        new_email,
                        "registration/email_confirm_email_change.html",
                        email_context)
                    message.send()
                    messages.success(
                        request,
                        "An e-mail confirmation has been sent to {}".format(
                            new_email))

        else:
            messages.error(request, "Unknown request.")

    context["form"] = NotificationSettingsForm(instance=existing_settings)
    context["email_form"] = forms.ChangeEmailForm(
        initial={"email": request.user.email})

    return render(request, "account/notifications.html", context=context)
示例#4
0
def notifications(request):
    # TODO(mikey): Dynamically add settings forms for other e-mail
    # backends (currently hardcoded to email backend).

    context = RequestContext(request)
    existing_settings = models.NotificationSettings.objects.get_or_create(
        user=request.user,
        backend='pykeg.notification.backends.email.EmailNotificationBackend'
    )[0]

    if request.method == 'POST':
        if 'submit-settings' in request.POST:
            form = NotificationSettingsForm(request.POST,
                                            instance=existing_settings)
            if form.is_valid():
                instance = form.save(commit=False)
                instance.user = request.user
                instance.backend = 'pykeg.notification.backends.email.EmailNotificationBackend'
                instance.save()
                messages.success(request, 'Settings updated')
                existing_settings = instance

        elif 'submit-email' in request.POST:
            form = forms.ChangeEmailForm(request.POST)
            if form.is_valid():
                new_email = form.cleaned_data['email']
                if new_email == request.user.email:
                    messages.warning(request, 'E-mail address unchanged.')
                else:
                    token = email.build_email_change_token(
                        request.user, new_email)
                    url = models.KegbotSite.get().reverse_full(
                        'account-confirm-email',
                        args=(),
                        kwargs={'token': token})

                    message = email.build_message(
                        new_email,
                        'registration/email_confirm_email_change.html',
                        {'url': url})
                    message.send()
                    messages.success(
                        request,
                        'An e-mail confirmation has been sent to {}'.format(
                            new_email))

        else:
            messages.error(request, 'Unknown request.')

    context['form'] = NotificationSettingsForm(instance=existing_settings)
    context['email_form'] = forms.ChangeEmailForm(
        initial={'email': request.user.email})

    return render_to_response('account/notifications.html',
                              context_instance=context)
示例#5
0
def notifications(request):
    # TODO(mikey): Dynamically add settings forms for other e-mail
    # backends (currently hardcoded to email backend).

    context = RequestContext(request)
    existing_settings = models.NotificationSettings.objects.get_or_create(user=request.user,
        backend='pykeg.notification.backends.email.EmailNotificationBackend')[0]

    if request.method == 'POST':
        if 'submit-settings' in request.POST:
            form = NotificationSettingsForm(request.POST, instance=existing_settings)
            if form.is_valid():
                instance = form.save(commit=False)
                instance.user = request.user
                instance.backend = 'pykeg.notification.backends.email.EmailNotificationBackend'
                instance.save()
                messages.success(request, 'Settings updated')
                existing_settings = instance

        elif 'submit-email' in request.POST:
            form = forms.ChangeEmailForm(request.POST)
            if form.is_valid():
                new_email = form.cleaned_data['email']
                if new_email == request.user.email:
                    messages.warning(request, 'E-mail address unchanged.')
                else:
                    token = email.build_email_change_token(request.user, new_email)
                    url = models.KegbotSite.get().reverse_full(
                        'account-confirm-email', args=(), kwargs={'token': token})

                    message = email.build_message(new_email, 'registration/email_confirm_email_change.html',
                        {'url': url})
                    message.send()
                    messages.success(request, 'An e-mail confirmation has been sent to {}'.format(new_email))

        else:
            messages.error(request, 'Unknown request.')

    context['form'] = NotificationSettingsForm(instance=existing_settings)
    context['email_form'] = forms.ChangeEmailForm(initial={'email': request.user.email})

    return render_to_response('account/notifications.html', context_instance=context)
示例#6
0
 def test_build_email_change_token(self):
     token = email.build_email_change_token(self.user, '*****@*****.**')
     uid, new_address = email.verify_email_change_token(self.user, token)
     self.assertEqual(self.user.id, uid)
     self.assertEqual('*****@*****.**', new_address)
示例#7
0
 def test_build_email_change_token(self):
     token = email.build_email_change_token(self.user, '*****@*****.**')
     uid, new_address = email.verify_email_change_token(self.user, token)
     self.assertEqual(self.user.id, uid)
     self.assertEqual('*****@*****.**', new_address)