示例#1
0
 def test_redirect_ok(self):
     """
     Tests to validate the redirect URL.
     """
     request = self.factory.get('/?next=/example/')
     url = validate_redirect(request)
     self.assertTrue(url == "/example/")
示例#2
0
 def get(self, request, *args, **kwargs):
     verification_key = self.kwargs.get('verification_key')
     #pylint: disable=maybe-no-member
     user = User.objects.find_user(verification_key)
     if user:
         if user.has_invalid_password:
             messages.info(self.request,
                 _("Please set a password to protect your account."))
             url = reverse('registration_password_confirm',
                           args=(user.email_verification_key,
                                 self.token_generator.make_token(user)))
         else:
             user = User.objects.activate_user(verification_key)
             # XXX Should we directly login user here?
             signals.user_activated.send(
                 sender=__name__, user=user, request=self.request)
             messages.info(self.request,
                 _("Thank you. Your account is now active." \
                       " You can sign in at your convienience."))
             url = reverse('login')
         next_url = validate_redirect(self.request)
         if next_url:
             success_url = "%s?%s=%s" % (url, REDIRECT_FIELD_NAME, next_url)
         else:
             success_url = url
         return _redirect_to(success_url)
     context = self.get_context_data(**kwargs)
     return self.render_to_response(context)
示例#3
0
 def test_redirect_ok(self):
     """
     Tests to validate the redirect URL.
     """
     request = self.factory.get('/?next=/example/')
     url = validate_redirect(request)
     self.assertTrue(url == "/example/")
示例#4
0
 def get(self, request, *args, **kwargs):
     verification_key = self.kwargs.get('verification_key')
     #pylint: disable=maybe-no-member
     user = User.objects.find_user(verification_key)
     if user:
         if user.has_invalid_password:
             messages.info(self.request,
                 _("Please set a password to protect your account."))
             url = reverse('registration_password_confirm',
                           args=(user.email_verification_key,
                                 self.token_generator.make_token(user)))
         else:
             user = User.objects.activate_user(verification_key)
             # XXX Should we directly login user here?
             signals.user_activated.send(
                 sender=__name__, user=user, request=self.request)
             messages.info(self.request,
                 _("Thank you. Your account is now active." \
                       " You can sign in at your convienience."))
             url = reverse('login')
         next_url = validate_redirect(self.request)
         if next_url:
             success_url = "%s?%s=%s" % (url, REDIRECT_FIELD_NAME, next_url)
         else:
             success_url = url
         return _redirect_to(success_url)
     context = self.get_context_data(**kwargs)
     return self.render_to_response(context)
示例#5
0
 def test_redirect_fail1(self):
     """
     Tests to validate the redirect URL.
     """
     request = self.factory.get('/?next=http://example.com/example/')
     url = validate_redirect(request)
     if '*' in settings.ALLOWED_HOSTS:
         self.assertTrue(url == "/example/")
     else:
         self.assertTrue(url is None)
示例#6
0
 def test_redirect_fail1(self):
     """
     Tests to validate the redirect URL.
     """
     request = self.factory.get('/?next=http://example.com/example/')
     url = validate_redirect(request)
     if '*' in settings.ALLOWED_HOSTS:
         self.assertTrue(url == "/example/")
     else:
         self.assertTrue(url is None)
示例#7
0
 def form_valid(self, form):
     users = User.objects.filter(email__iexact=form.cleaned_data['email'])
     if users.exists():
         user = users.get()
         if user.is_active and user.has_usable_password():
             # Make sure that no email is sent to a user that actually has
             # a password marked as unusable
             uid = urlsafe_base64_encode(force_bytes(user.pk))
             token = self.token_generator.make_token(user)
             back_url = self.request.build_absolute_uri(
                 reverse('password_reset_confirm', args=(uid, token)))
             next_url = validate_redirect(self.request)
             if next_url:
                 back_url += '?%s=%s' % (REDIRECT_FIELD_NAME, next_url)
             signals.user_reset_password.send(
                 sender=__name__, user=user, request=self.request,
                 back_url=back_url, expiration_days=settings.KEY_EXPIRATION)
     return super(PasswordResetBaseView, self).form_valid(form)
示例#8
0
 def get_success_url(self):
     next_url = validate_redirect(self.request)
     if not next_url:
         next_url = reverse('product_default_start')
     return next_url
示例#9
0
 def get_success_url(self):
     next_url = validate_redirect(self.request)
     if not next_url:
         next_url = reverse('contact')
     return next_url
示例#10
0
 def get_context_data(self, **kwargs):
     context = super(RedirectFormMixin, self).get_context_data(**kwargs)
     next_url = validate_redirect(self.request)
     if next_url:
         context.update({REDIRECT_FIELD_NAME: next_url})
     return context
示例#11
0
 def get_success_url(self):
     next_url = validate_redirect(self.request)
     if not next_url:
         next_url = super(RedirectFormMixin, self).get_success_url()
     return next_url
示例#12
0
 def get_context_data(self, **kwargs):
     context = super(RedirectFormMixin, self).get_context_data(**kwargs)
     next_url = validate_redirect(self.request)
     if next_url:
         context.update({REDIRECT_FIELD_NAME: next_url})
     return context
示例#13
0
 def get_success_url(self):
     next_url = validate_redirect(self.request)
     if not next_url:
         next_url = super(RedirectFormMixin, self).get_success_url()
     return next_url