Verified Commit 527f40e0 authored by Marco Marinello's avatar Marco Marinello
Browse files

Use post_office, set namespace, prefer first name


Signed-off-by: Marco Marinello's avatarMarco Marinello <me@marcomarinello.it>
parent 32b7b371
......@@ -18,6 +18,8 @@ from django.views.decorators.debug import sensitive_post_parameters
from .forms import PasswordRecoveryForm, PasswordResetForm
from .signals import user_recovers_password
from post_office import mail
class SaltMixin(object):
salt = 'password_recovery'
......@@ -56,8 +58,9 @@ class Recover(SaltMixin, generic.FormView):
case_sensitive = True
form_class = PasswordRecoveryForm
template_name = 'password_reset/recovery_form.html'
success_url_name = 'password_reset_sent'
success_url_name = 'password_reset:password_reset_sent'
email_template_name = 'password_reset/recovery_email.txt'
email_html_template_name = 'password_reset/recovery_email.html'
email_subject_template_name = 'password_reset/recovery_email_subject.txt'
search_fields = ['username', 'email']
......@@ -84,15 +87,22 @@ class Recover(SaltMixin, generic.FormView):
'site': self.get_site(),
'user': self.user,
'username': self.user.get_username(),
'full_name': self.user.get_full_name(),
'token': signing.dumps(self.user.pk, salt=self.salt),
'secure': self.request.is_secure(),
}
body = loader.render_to_string(self.email_template_name,
context).strip()
html_body = loader.render_to_string(self.email_html_template_name,
context).strip()
subject = loader.render_to_string(self.email_subject_template_name,
context).strip()
send_mail(subject, body, settings.DEFAULT_FROM_EMAIL,
[self.user.email])
mail.send(
[self.user.email],
subject=subject,
message=body,
html_message=html_body
)
def form_valid(self, form):
self.user = form.cleaned_data['user']
......@@ -117,7 +127,7 @@ class Reset(SaltMixin, generic.FormView):
form_class = PasswordResetForm
token_expires = None
template_name = 'password_reset/reset.html'
success_url = reverse_lazy('password_reset_done')
success_url = reverse_lazy('password_reset:password_reset_done')
def get_token_expires(self):
duration = getattr(settings, 'PASSWORD_RESET_TOKEN_EXPIRES',
......@@ -155,7 +165,7 @@ class Reset(SaltMixin, generic.FormView):
ctx = super(Reset, self).get_context_data(**kwargs)
if 'invalid' not in ctx:
ctx.update({
'username': self.user.get_username(),
'username': self.user.first_name or self.user.get_username(),
'token': self.kwargs['token'],
})
return ctx
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment