From 0c859025ab3f4f55edc3d1d2fea0631be0be0e71 Mon Sep 17 00:00:00 2001 From: rohan-chaturvedi Date: Mon, 9 Oct 2023 19:33:47 +0530 Subject: [PATCH] fix: update auth provider in email alerts --- backend/api/emails.py | 4 ++-- backend/api/views.py | 7 +++---- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/backend/api/emails.py b/backend/api/emails.py index e68c01800..86d3e36df 100644 --- a/backend/api/emails.py +++ b/backend/api/emails.py @@ -26,14 +26,14 @@ def send_email(subject, recipient_list, template_name, context): ) -def send_login_email(request, email): +def send_login_email(request, email, provider): user_agent = request.META.get('HTTP_USER_AGENT', 'Unknown') ip_address = get_client_ip(request) timestamp = datetime.now().strftime('%Y-%m-%d %H:%M:%S') # Creating context dictionary context = { - 'auth': 'GitHub', + 'auth': provider, 'email': email, 'ip': ip_address, 'user_agent': user_agent, diff --git a/backend/api/views.py b/backend/api/views.py index 09e071350..e15bfdef0 100644 --- a/backend/api/views.py +++ b/backend/api/views.py @@ -96,7 +96,7 @@ def complete_login(self, request, app, token, response, **kwargs): print(f"Error notifying Slack: {e}") try: - send_login_email(request, email) + send_login_email(request, email, 'Google') except Exception as e: print(f"Error sending email: {e}") @@ -137,7 +137,7 @@ def complete_login(self, request, app, token, **kwargs): print(f"Error notifying Slack: {e}") try: - send_login_email(request, email) + send_login_email(request, email, 'GitHub') except Exception as e: print(f"Error sending email: {e}") @@ -158,7 +158,6 @@ class CustomGitLabOAuth2Adapter(OAuth2Adapter): provider_base_url, provider_api_version) def complete_login(self, request, app, token, response): - print('logging in') response = requests.get(self.profile_url, params={ "access_token": token.token}) data = _check_errors(response) @@ -175,7 +174,7 @@ def complete_login(self, request, app, token, response): print(f"Error notifying Slack: {e}") try: - send_login_email(request, email) + send_login_email(request, email, 'GitLab') except Exception as e: print(f"Error sending email: {e}")