From b72874226fac37631424678db568f5929ac0ef9a Mon Sep 17 00:00:00 2001 From: Vishnu Ks Date: Mon, 30 Apr 2018 21:10:59 +0530 Subject: [PATCH] enails: Pass new login details as separate variables. Refactored by tabbott to eliminate some unnecessary complexity. --- .../zerver/emails/notify_new_login.source.html | 6 +++--- templates/zerver/emails/notify_new_login.subject | 2 +- templates/zerver/emails/notify_new_login.txt | 6 +++--- zerver/signals.py | 16 +++++----------- 4 files changed, 12 insertions(+), 18 deletions(-) diff --git a/templates/zerver/emails/notify_new_login.source.html b/templates/zerver/emails/notify_new_login.source.html index b6ed841c33..f581711bc1 100644 --- a/templates/zerver/emails/notify_new_login.source.html +++ b/templates/zerver/emails/notify_new_login.source.html @@ -11,9 +11,9 @@

Server: {{ realm_uri }}

Account: {{ user_email }}

-

Time: {{ device_info.login_time }}

-

Device: {{ device_info.device_browser if device_info.device_browser else 'An unknown browser' }} on {{ device_info.device_os if device_info.device_os else 'an unknown operating system' }}.

-

IP Address: {{ device_info.device_ip }}

+

Time: {{ login_time }}

+

Device: {{ device_browser if device_browser else 'An unknown browser' }} on {{ device_os if device_os else 'an unknown operating system' }}.

+

IP Address: {{ device_ip }}

If you do not recognize this login activity, or think your account may have been compromised, please contact us immediately at {{ support_email }}.

If you recognize this login activity, you can archive this notice.

diff --git a/templates/zerver/emails/notify_new_login.subject b/templates/zerver/emails/notify_new_login.subject index 0f740dc8ed..cc06f742a1 100644 --- a/templates/zerver/emails/notify_new_login.subject +++ b/templates/zerver/emails/notify_new_login.subject @@ -1 +1 @@ -New login from {{ device_info.device_browser if device_info.device_browser else 'an unknown browser' }} on {{ device_info.device_os if device_info.device_os else 'an unknown operating system' }} +New login from {{ device_browser if device_browser else 'an unknown browser' }} on {{ device_os if device_os else 'an unknown operating system' }} diff --git a/templates/zerver/emails/notify_new_login.txt b/templates/zerver/emails/notify_new_login.txt index b44b56053c..00dce992a0 100644 --- a/templates/zerver/emails/notify_new_login.txt +++ b/templates/zerver/emails/notify_new_login.txt @@ -5,9 +5,9 @@ This is a notification that a new login to your Zulip account has just occurred. Login details: Server: {{ realm_uri }} Account: {{ user_email }} -Time: {{ device_info.login_time }} -Device: {{ device_info.device_browser if device_info.device_browser else 'an unknown browser' }} on {{ device_info.device_os if device_info.device_os else 'an unknown operating system' }}. -IP Address: {{ device_info.device_ip }} +Time: {{ login_time }} +Device: {{ device_browser if device_browser else 'an unknown browser' }} on {{ device_os if device_os else 'an unknown operating system' }}. +IP Address: {{ device_ip }} If you do not recognize this login activity, or think your account may have been compromised, please contact us immediately at {{ support_email }}. diff --git a/zerver/signals.py b/zerver/signals.py index 36107e5845..68cd1ee722 100644 --- a/zerver/signals.py +++ b/zerver/signals.py @@ -67,21 +67,15 @@ def email_on_new_login(sender: Any, user: UserProfile, request: Any, **kwargs: A 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() user_agent = request.META.get('HTTP_USER_AGENT', "").lower() - device_browser = get_device_browser(user_agent) - device_os = get_device_os(user_agent) - device_ip = request.META.get('REMOTE_ADDR') or "Uknown IP address" - device_info = {"device_browser": device_browser, - "device_os": device_os, - "device_ip": device_ip, - "login_time": login_time - } context = common_context(user) - context['device_info'] = device_info context['user_email'] = user.email + context['login_time'] = timezone_now().strftime('%A, %B %d, %Y at %I:%M%p ') + \ + timezone_get_current_timezone_name() + context['device_ip'] = request.META.get('REMOTE_ADDR') or "Uknown IP address" + context['device_os'] = get_device_os(user_agent) + context['device_browser'] = get_device_browser(user_agent) email_dict = { 'template_prefix': 'zerver/emails/notify_new_login',