mirror of https://github.com/zulip/zulip.git
auth: Improve robustness of not sending duplicate login emails.
Previously, we had a very not-robust check on the URL, which might have caused cases like Google auth registration to not do the right thing.
This commit is contained in:
parent
50ad679342
commit
7c37fc8909
|
@ -64,13 +64,9 @@ def email_on_new_login(sender, user, request, **kwargs):
|
|||
return
|
||||
|
||||
if request:
|
||||
# Login emails are for returning users, not new registrations.
|
||||
# Determine if login request was from new registration.
|
||||
path = request.META.get('PATH_INFO', None)
|
||||
|
||||
if path:
|
||||
if path == "/accounts/register/":
|
||||
return
|
||||
# If the user's account was just created, avoid sending an email.
|
||||
if getattr(user, "just_registered", False):
|
||||
return
|
||||
|
||||
login_time = timezone_now().strftime('%A, %B %d, %Y at %I:%M%p ') + \
|
||||
timezone_get_current_timezone_name()
|
||||
|
|
|
@ -47,9 +47,9 @@ class SendLoginEmailTest(ZulipTestCase):
|
|||
with self.settings(SEND_LOGIN_EMAILS=True):
|
||||
self.register("test@zulip.com", "test")
|
||||
|
||||
for email in mail.outbox:
|
||||
subject = 'New login from an unknown browser on an unknown operating system'
|
||||
self.assertNotEqual(email.subject, subject)
|
||||
# Verify that there's just 1 email for new user registration.
|
||||
self.assertEqual(mail.outbox[0].subject, "Activate your Zulip account")
|
||||
self.assertEqual(len(mail.outbox), 1)
|
||||
|
||||
def test_without_path_info_dont_send_login_emails_for_new_user_registration_logins(self):
|
||||
# type: () -> None
|
||||
|
|
|
@ -244,6 +244,9 @@ def accounts_register(request):
|
|||
logging.error("Subdomain mismatch in registration %s: %s" % (
|
||||
realm.subdomain, user_profile.email,))
|
||||
return redirect('/')
|
||||
|
||||
# Mark the user as having been just created, so no login email is sent
|
||||
auth_result.just_registered = True
|
||||
login(request, auth_result)
|
||||
return HttpResponseRedirect(realm.uri + reverse('zerver.views.home.home'))
|
||||
|
||||
|
|
Loading…
Reference in New Issue