77
88from hypha .core .mail import MarkdownMail
99
10+ from .utils import get_zoneinfo
11+
1012HIJACK_VIEW_NAMES = {
1113 "hijack-become" ,
1214 "users:hijack" ,
@@ -20,10 +22,18 @@ def send_login_notification(sender, request, user, **kwargs):
2022 if not settings .SEND_MESSAGES or not user .email :
2123 return
2224
25+ if getattr (user , "backend" , "" ).startswith ("social_core." ):
26+ return
27+
2328 if request and getattr (request , "resolver_match" , None ):
2429 if request .resolver_match .view_name in HIJACK_VIEW_NAMES :
2530 return
2631
32+ tz_name = (
33+ getattr (request , "session" , {}).get ("user_timezone" , "" ) if request else ""
34+ )
35+ user_tz = get_zoneinfo (tz_name )
36+
2737 subject = _ ("Successful login to %(org)s" ) % {"org" : settings .ORG_LONG_NAME }
2838 if settings .EMAIL_SUBJECT_PREFIX :
2939 subject = str (settings .EMAIL_SUBJECT_PREFIX ) + str (subject )
@@ -35,7 +45,9 @@ def send_login_notification(sender, request, user, **kwargs):
3545 from_email = settings .DEFAULT_FROM_EMAIL ,
3646 context = {
3747 "user" : user ,
38- "login_time" : formats .date_format (timezone .now (), "SHORT_DATETIME_FORMAT" ),
48+ "login_time" : formats .date_format (
49+ timezone .localtime (timezone = user_tz ), "SHORT_DATETIME_FORMAT"
50+ ),
3951 "site" : Site .find_for_request (request ) if request else None ,
4052 "ORG_EMAIL" : settings .ORG_EMAIL ,
4153 },
0 commit comments