]> git.ipfire.org Git - thirdparty/patchwork.git/commitdiff
views: Add error handling for user registration
authorStephen Finucane <stephen@that.guru>
Thu, 30 Aug 2018 09:24:33 +0000 (10:24 +0100)
committerStephen Finucane <stephen@that.guru>
Sat, 29 Sep 2018 21:41:16 +0000 (22:41 +0100)
This was already present for registration confirmation but missing for
initial registration. Resolve this.

Signed-off-by: Stephen Finucane <stephen@that.guru>
patchwork/views/user.py

index 21d2744beb879dd3f211b0a9d8549755bdbd843a..4b6b0e6018e154ca20251e1dada723098ea4daeb 100644 (file)
@@ -51,6 +51,8 @@ def register(request):
                                      email=user.email)
             conf.save()
 
+            context['confirmation'] = conf
+
             # send email
             subject = render_to_string(
                 'patchwork/mails/activation-subject.txt')
@@ -58,12 +60,13 @@ def register(request):
                 'patchwork/mails/activation.txt',
                 {'site': Site.objects.get_current(), 'confirmation': conf})
 
-            # TODO(stephenfin): Should this be surrounded by a try-except?
-            send_mail(subject, message, settings.DEFAULT_FROM_EMAIL,
-                      [conf.email])
-
-            # setting 'confirmation' in the template indicates success
-            context['confirmation'] = conf
+            try:
+                send_mail(subject, message, settings.DEFAULT_FROM_EMAIL,
+                          [conf.email])
+            except smtplib.SMTPException:
+                context['confirmation'] = None
+                context['error'] = ('An error occurred during registration. '
+                                    'Please try again later')
     else:
         form = RegistrationForm()