Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handles exceptions thrown by incorrectly configured email #434

Merged
merged 1 commit into from
Jun 12, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 12 additions & 6 deletions aurora/bag_transfer/users/views.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from socket import gaierror

from bag_transfer.lib.RAC_CMD import set_server_password
from bag_transfer.mixins.authmixins import (ArchivistMixin,
ManagingArchivistMixin,
Expand All @@ -9,6 +11,7 @@
UserPasswordResetForm,
UserSetPasswordForm)
from braces.views import AnonymousRequiredMixin
from django.contrib import messages
from django.contrib.auth.forms import PasswordResetForm
from django.contrib.auth.views import (PasswordChangeView,
PasswordResetCompleteView,
Expand Down Expand Up @@ -65,12 +68,15 @@ def post(self, request, *args, **kwargs):
random password."""
post = super(UsersCreateView, self).post(request, *args, **kwargs)
form = PasswordResetForm({"email": request.POST.get("email")})
form.is_valid()
form.save(
request=self.request,
subject_template_name="users/password_initial_set_subject.txt",
email_template_name="users/password_initial_set_email.html",
)
if form.is_valid():
try:
form.save(
request=self.request,
subject_template_name="users/password_initial_set_subject.txt",
email_template_name="users/password_initial_set_email.html",
)
except gaierror:
messages.error(request, "Unable to send email to new user because SMTP settings are not properly configured.")
return post


Expand Down