From 606cf6306604eaacef61e9ffdaff74093da5c650 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20P=C3=A9ters?= Date: Tue, 1 Dec 2015 13:45:05 +0100 Subject: [PATCH] profile: use request context to send password reset email (#9166) --- src/authentic2/profile_forms.py | 18 +++++++++++++++--- src/authentic2/profile_views.py | 2 +- .../templates/registration/password_reset_email.html | 2 +- 3 files changed, 17 insertions(+), 5 deletions(-) diff --git a/src/authentic2/profile_forms.py b/src/authentic2/profile_forms.py index a2455ef..5742053 100644 --- a/src/authentic2/profile_forms.py +++ b/src/authentic2/profile_forms.py @@ -1,10 +1,12 @@ import logging +import urllib from django import forms +from django.core.urlresolvers import reverse from django.utils.translation import ugettext as _ from django.utils.http import urlsafe_base64_encode from django.utils.encoding import force_bytes -from django.template import loader, TemplateDoesNotExist +from django.template import loader, RequestContext, TemplateDoesNotExist from django.contrib.auth import get_user_model from django.contrib.auth.tokens import default_token_generator from django.conf import settings @@ -36,7 +38,8 @@ class PasswordResetForm(forms.Form): continue site_name = domain = request.get_host() - c = { + c = RequestContext(request) + c.update({ 'email': user.email, 'domain': domain, 'site_name': site_name, @@ -46,7 +49,16 @@ class PasswordResetForm(forms.Form): 'protocol': 'https' if use_https else 'http', 'request': request, 'expiration_days': settings.PASSWORD_RESET_TIMEOUT_DAYS, - } + }) + + c['reset_url'] = request.build_absolute_uri( + reverse('password_reset_confirm', kwargs={ + 'uidb64': c['uid'], + 'token': c['token']})) + if 'next' in request.GET: + c['reset_url'] += '?' + urllib.urlencode( + {'next': request.GET['next']}) + subject = loader.render_to_string(subject_template_name, c) # Email subject *must not* contain newlines subject = ''.join(subject.splitlines()) diff --git a/src/authentic2/profile_views.py b/src/authentic2/profile_views.py index 098877e..3c3eeff 100644 --- a/src/authentic2/profile_views.py +++ b/src/authentic2/profile_views.py @@ -19,7 +19,7 @@ class PasswordResetView(cbv.NextURLViewMixin, FormView): 'registration/password_reset_email.html', ] html_email_template_name = [ - 'authentic2/password_reset_email_body.txt', + 'authentic2/password_reset_email_body.html', ] subject_template_name = [ 'authentic2/password_reset_email_subject.txt', diff --git a/src/authentic2/templates/registration/password_reset_email.html b/src/authentic2/templates/registration/password_reset_email.html index 6e5ce31..40a5cca 100644 --- a/src/authentic2/templates/registration/password_reset_email.html +++ b/src/authentic2/templates/registration/password_reset_email.html @@ -2,5 +2,5 @@ {% blocktrans %}You requested reset of your password on {{ site_name }}, to proceed please click on the following link{% endblocktrans %}: {% block reset_link %} - {{ protocol }}://{{ domain }}{% url 'password_reset_confirm' uidb64=uid token=token %}?next={{ request.GET.next|urlencode }} + {{ reset_url }} {% endblock %} -- 2.6.2