login_or_register_remote_user: Send login emails for mobile.

Fixes #5389
This commit is contained in:
Umair Khan 2017-06-16 09:50:48 +05:00 committed by Tim Abbott
parent 34a91be9a2
commit dc78a7888f
2 changed files with 12 additions and 1 deletions

View File

@ -759,6 +759,7 @@ class GoogleOAuthTest(ZulipTestCase):
headers['HTTP_HOST'] = subdomain + ".testserver"
if mobile_flow_otp is not None:
params['mobile_flow_otp'] = mobile_flow_otp
headers['HTTP_USER_AGENT'] = "ZulipAndroid"
if len(params) > 0:
url += "?%s" % (urllib.parse.urlencode(params))
@ -828,7 +829,9 @@ class GoogleSubdomainLoginTest(GoogleOAuthTest):
emails=[dict(type="account",
value=self.example_email("hamlet"))])
account_response = ResponseMock(200, account_data)
with self.settings(REALMS_HAVE_SUBDOMAINS=True):
self.assertEqual(len(mail.outbox), 0)
with self.settings(REALMS_HAVE_SUBDOMAINS=True,
SEND_LOGIN_EMAILS=True):
# Verify that the right thing happens with an invalid-format OTP
result = self.google_oauth2_test(token_response, account_response, 'zulip',
mobile_flow_otp="1234")
@ -850,6 +853,8 @@ class GoogleSubdomainLoginTest(GoogleOAuthTest):
encrypted_api_key = query_params["otp_encrypted_api_key"][0]
self.assertEqual(self.example_user('hamlet').api_key,
otp_decrypt_api_key(encrypted_api_key, mobile_flow_otp))
self.assertEqual(len(mail.outbox), 1)
self.assertIn('Zulip on Android', mail.outbox[0].body)
def test_log_into_subdomain(self):
# type: () -> None

View File

@ -126,6 +126,12 @@ def login_or_register_remote_user(request, remote_username, user_profile, full_n
# We can't use HttpResponseRedirect, since it only allows HTTP(S) URLs
response = HttpResponse(status=302)
response['Location'] = 'zulip://login?' + urllib.parse.urlencode(params)
# Maybe sending 'user_logged_in' signal is the better approach:
# user_logged_in.send(sender=user_profile.__class__, request=request, user=user_profile)
# Not doing this only because over here we don't add the user information
# in the session. If the signal receiver assumes that we do then that
# would cause problems.
email_on_new_login(sender=user_profile.__class__, request=request, user=user_profile)
return response
login(request, user_profile)