[damned-lies] Catch SMTP exceptions during registration process



commit 84c8d778c1c69ef1288d5fe23e221272a233077d
Author: Claude Paroz <claude 2xlibre net>
Date:   Wed Jan 22 08:29:16 2020 +0100

    Catch SMTP exceptions during registration process

 common/views.py | 13 +++++++++++--
 1 file changed, 11 insertions(+), 2 deletions(-)
---
diff --git a/common/views.py b/common/views.py
index 24f60b80..2c6beff6 100644
--- a/common/views.py
+++ b/common/views.py
@@ -1,4 +1,5 @@
 from pathlib import Path
+from smtplib import SMTPException
 from threading import Thread
 
 from django.conf import settings
@@ -11,6 +12,7 @@ from django.template.loader import get_template, TemplateDoesNotExist
 from django.urls import reverse
 from django.utils.translation import gettext as _
 from django.views.decorators.csrf import csrf_exempt
+from django.views.decorators.debug import sensitive_variables
 
 from people.models import Person, obfuscate_email
 from teams.models import Role
@@ -73,12 +75,19 @@ class LoginView(AuthLoginView):
         return super().form_invalid(form)
 
 
+@sensitive_variables('password1', 'password2')
 def site_register(request):
     if request.method == 'POST':
         form = RegistrationForm(data=request.POST)
         if form.is_valid():
-            form.save(request)
-            return HttpResponseRedirect(reverse('register_success'))
+            try:
+                form.save(request)
+            except SMTPException as exc:
+                messages.error(request, _("An error occurred while sending mail to {email} ({err})".format(
+                    email=form.cleaned_data['email'], err=str(exc)
+                )))
+            else:
+                return HttpResponseRedirect(reverse('register_success'))
     else:
         form = RegistrationForm()
     context = {


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]