+ def password_reset_confirm(self, request, extra_context=None, uidb36=None, token=None, token_generator=password_token_generator):
+ """
+ Checks that a given hash in a password reset link is valid. If so,
+ displays the password set form.
+ """
+ assert uidb36 is not None and token is not None
+ try:
+ uid_int = base36_to_int(uidb36)
+ except:
+ raise Http404
+
+ user = get_object_or_404(User, id=uid_int)
+
+ if token_generator.check_token(user, token):
+ if request.method == 'POST':
+ form = self.password_set_form(user, request.POST)
+
+ if form.is_valid():
+ form.save()
+ messages.add_message(request, messages.SUCCESS, "Password reset successful.")
+ return HttpResponseRedirect(self.reverse('login', node=request.node))
+ else:
+ form = self.password_set_form(user)
+
+ context = self.get_context()
+ context.update(extra_context or {})
+ context.update({
+ 'form': form
+ })
+ return self.password_set_page.render_to_response(request, extra_context=context)
+
+ raise Http404
+
+ def password_change(self, request, extra_context=None):
+ if request.method == 'POST':
+ form = self.password_change_form(request.user, request.POST)
+ if form.is_valid():
+ form.save()
+ messages.add_message(request, messages.SUCCESS, 'Password changed successfully.', fail_silently=True)
+ return HttpResponseRedirect('')
+ else:
+ form = self.password_change_form(request.user)
+
+ context = self.get_context()
+ context.update(extra_context or {})
+ context.update({
+ 'form': form
+ })
+ return self.password_change_page.render_to_response(request, extra_context=context)
+
+ class Meta:
+ abstract = True
+
+
+class RegistrationMultiView(PasswordMultiView):
+ """Adds on the pages necessary for letting new users register."""
+ register_page = models.ForeignKey(Page, related_name='%(app_label)s_%(class)s_register_related', blank=True, null=True)
+ register_confirmation_email = models.ForeignKey(Page, related_name='%(app_label)s_%(class)s_register_confirmation_email_related', blank=True, null=True)
+ registration_form = RegistrationForm
+
+ @property
+ def urlpatterns(self):
+ urlpatterns = super(RegistrationMultiView, self).urlpatterns
+ if self.register_page and self.register_confirmation_email:
+ urlpatterns += patterns('',
+ url(r'^register$', csrf_protect(self.register), name='register'),
+ url(r'^register/(?P<uidb36>\w+)/(?P<token>[^/]+)$', self.register_confirm, name='register_confirm')
+ )
+ return urlpatterns
+
+ def register(self, request, extra_context=None, token_generator=registration_token_generator):
+ if request.user.is_authenticated():
+ return HttpResponseRedirect(request.node.get_absolute_url())
+
+ if request.method == 'POST':
+ form = self.registration_form(request.POST)