+ def password_reset(self, request, extra_context=None, token_generator=password_token_generator):
+ if request.user.is_authenticated():
+ return HttpResponseRedirect(request.node.get_absolute_url())
+
+ if request.method == 'POST':
+ form = PasswordResetForm(request.POST)
+ if form.is_valid():
+ current_site = Site.objects.get_current()
+ for user in form.users_cache:
+ context = {
+ 'link': self.make_confirmation_link('password_reset_confirm', token_generator, user, request.node),
+ '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()
+ context.update(extra_context or {})
+ context.update({
+ 'form': form
+ })
+ return self.password_reset_page.render_to_response(request, extra_context=context)