+ def password_reset(self, request, node=None, extra_context=None, token_generator=password_token_generator):
+ if request.method == 'POST':
+ form = PasswordResetForm(request.POST)
+ if form.is_valid():
+ current_site = Site.objects.get_current()
+ for user in form.users_cache:
+ token = token_generator.make_token(user)
+ link = 'http://%s/%s/%s/' % (current_site.domain, node.get_absolute_url().strip('/'), reverse('password_reset_confirm', urlconf=self, kwargs={'uidb36': int_to_base36(user.id), 'token': token}).strip('/'))
+ context = {
+ 'link': link,
+ 'username': user.username
+ }
+ self.send_confirmation_email('Confirm password reset for account at %s' % current_site.domain, user.email, self.password_reset_confirmation_email, context)
+ messages.add_message(request, messages.SUCCESS, "An email has been sent to the address you provided with details on resetting your password.", fail_silently=True)
+ return HttpResponseRedirect('')
+ else:
+ form = PasswordResetForm()
+
+ context = self.get_context({'form': form})
+ context.update(extra_context or {})
+ return self.password_reset_page.render_to_response(node, request, extra_context=context)
+
+ def password_reset_confirm(self, request, node=None, 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 = SetPasswordForm(user, request.POST)
+
+ if form.is_valid():
+ form.save()
+ messages.add_message(request, messages.SUCCESS, "Password reset successful.")
+ return HttpResponseRedirect('/%s/%s/' % (node.get_absolute_url().strip('/'), reverse('login', urlconf=self).strip('/')))
+ else:
+ form = SetPasswordForm(user)
+
+ context = self.get_context({'form': form})
+ return self.password_set_page.render_to_response(node, request, extra_context=context)
+
+ raise Http404
+
+ def password_change(self, request, node=None, extra_context=None):
+ if request.method == 'POST':
+ form = PasswordChangeForm(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 = PasswordChangeForm(request.user)
+
+ context = self.get_context({'form': form})
+ context.update(extra_context or {})
+ return self.password_change_page.render_to_response(node, request, extra_context=context)