From: Stephen Finucane Date: Thu, 30 Aug 2018 09:24:33 +0000 (+0100) Subject: views: Add error handling for user registration X-Git-Tag: v2.2.0-rc1~266 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=6c007280e59db1914a9b4217b746fdc9e66b3ff2;p=thirdparty%2Fpatchwork.git views: Add error handling for user registration This was already present for registration confirmation but missing for initial registration. Resolve this. Signed-off-by: Stephen Finucane --- diff --git a/patchwork/views/user.py b/patchwork/views/user.py index 21d2744b..4b6b0e60 100644 --- a/patchwork/views/user.py +++ b/patchwork/views/user.py @@ -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()