[PATCH 6/6] views: Add error handling for user registration
Stephen Finucane
stephen at that.guru
Tue Sep 18 00:17:50 AEST 2018
This was already present for registration confirmation but missing for
initial registration. Resolve this.
Signed-off-by: Stephen Finucane <stephen at that.guru>
---
patchwork/views/user.py | 15 +++++++++------
1 file changed, 9 insertions(+), 6 deletions(-)
diff --git a/patchwork/views/user.py b/patchwork/views/user.py
index 6348bed6..9876da96 100644
--- a/patchwork/views/user.py
+++ b/patchwork/views/user.py
@@ -64,6 +64,8 @@ def register(request):
email=user.email)
conf.save()
+ context['confirmation'] = conf
+
# send email
subject = render_to_string(
'patchwork/mails/activation-subject.txt')
@@ -71,12 +73,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()
--
2.17.1
More information about the Patchwork
mailing list