Beispiel #1
0
def lost_password(request):
    username = request.POST.get("username", "")
    if username:
        try:
            person = DjangoPerson.objects.get(user__username=username)
        except DjangoPerson.DoesNotExist:
            return render(request, "lost_password.html", {"message": "That was not a valid username."})
        path = utils.lost_url_for_user(username)
        from django.core.mail import send_mail
        import smtplib

        body = render_to_string("recovery_email.txt", {"path": path, "person": person})
        try:
            send_mail(
                "Django People account recovery",
                body,
                settings.RECOVERY_EMAIL_FROM,
                [person.user.email],
                fail_silently=False,
            )
        except smtplib.SMTPException:
            return render(request, "lost_password.html", {"message": "Could not e-mail you a recovery link."})
        return render(
            request,
            "lost_password.html",
            {
                "message": (
                    "An e-mail has been sent with instructions for "
                    "recovering your account. Don't forget to check your spam "
                    "folder!"
                )
            },
        )
    return render(request, "lost_password.html")
 def save(self):
     path = utils.lost_url_for_user(self.cleaned_data['username'])
     person = self.cleaned_data['person']
     body = render_to_string('recovery_email.txt', {
         'path': path,
         'person': person,
     })
     send_mail(
         'Django People account recovery', body,
         settings.RECOVERY_EMAIL_FROM, [person.user.email],
         fail_silently=False
     )