+
+ if page.template.mimetype == 'text/html':
+ msg = EmailMultiAlternatives(subject, striptags(text_content), from_email, [email])
+ msg.attach_alternative(text_content, 'text/html')
+ msg.send()
+ else:
+ send_mail(subject, text_content, from_email, [email])
+
+ 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 = self.password_reset_form(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, secure=request.is_secure()),
+ 'user': user,
+ 'site': current_site,
+ 'request': request,
+
+ # Deprecated... leave in for backwards-compatibility
+ '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 = self.password_reset_form()
+
+ 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)
+
+ 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