From b65ab8fbb08d6f9eab6b895d63e00d232ebfd6fc Mon Sep 17 00:00:00 2001 From: varun kumar Date: Sat, 18 Nov 2023 17:15:51 +0530 Subject: [PATCH] Add social accounts signals --- allauth/socialaccount/adapter.py | 3 +++ allauth/socialaccount/forms.py | 3 +++ allauth/socialaccount/models.py | 7 +++++++ .../socialaccount/email/social_account_added_message.txt | 4 ++++ .../socialaccount/email/social_account_added_subject.txt | 4 ++++ .../email/social_account_disconnected_message.txt | 4 ++++ .../email/social_account_disconnected_subject.txt | 4 ++++ .../socialaccount/email/social_account_updated_message.txt | 4 ++++ .../socialaccount/email/social_account_updated_subject.txt | 4 ++++ 9 files changed, 37 insertions(+) create mode 100644 allauth/templates/socialaccount/email/social_account_added_message.txt create mode 100644 allauth/templates/socialaccount/email/social_account_added_subject.txt create mode 100644 allauth/templates/socialaccount/email/social_account_disconnected_message.txt create mode 100644 allauth/templates/socialaccount/email/social_account_disconnected_subject.txt create mode 100644 allauth/templates/socialaccount/email/social_account_updated_message.txt create mode 100644 allauth/templates/socialaccount/email/social_account_updated_subject.txt diff --git a/allauth/socialaccount/adapter.py b/allauth/socialaccount/adapter.py index 902c578281..b8d07da959 100644 --- a/allauth/socialaccount/adapter.py +++ b/allauth/socialaccount/adapter.py @@ -287,6 +287,9 @@ def get_app(self, request, provider, client_id=None): elif len(apps) == 0: raise SocialApp.DoesNotExist() return apps[0] + + def send_notification_mail(self, *args, **kwargs): + return get_account_adapter().send_notification_mail(*args, **kwargs) def get_adapter(request=None): diff --git a/allauth/socialaccount/forms.py b/allauth/socialaccount/forms.py index dc810f3417..67507f2135 100644 --- a/allauth/socialaccount/forms.py +++ b/allauth/socialaccount/forms.py @@ -63,3 +63,6 @@ def save(self): signals.social_account_removed.send( sender=SocialAccount, request=self.request, socialaccount=account ) + get_adapter().send_notification_mail( + "socialaccount/email/social_account_disconnected", self.request.user, {} + ) diff --git a/allauth/socialaccount/models.py b/allauth/socialaccount/models.py index 13c53bd98f..dacf28631a 100644 --- a/allauth/socialaccount/models.py +++ b/allauth/socialaccount/models.py @@ -214,6 +214,10 @@ def connect(self, request, user): sender=SocialLogin, request=request, sociallogin=self ) + get_adapter().send_notification_mail( + "socialaccount/email/social_account_added", self.user, {} + ) + def serialize(self): serialize_instance = get_adapter().serialize_instance ret = dict( @@ -299,6 +303,9 @@ def _lookup_by_socialaccount(self): signals.social_account_updated.send( sender=SocialLogin, request=context.request, sociallogin=self ) + get_adapter().send_notification_mail( + "socialaccount/email/social_account_updated", self.user, {} + ) # Update token if app_settings.STORE_TOKENS and self.token: assert not self.token.pk diff --git a/allauth/templates/socialaccount/email/social_account_added_message.txt b/allauth/templates/socialaccount/email/social_account_added_message.txt new file mode 100644 index 0000000000..9a486cf03f --- /dev/null +++ b/allauth/templates/socialaccount/email/social_account_added_message.txt @@ -0,0 +1,4 @@ +{% extends "account/email/base_notification.txt" %} +{% load i18n %} + +{% block notification_message %}{% blocktrans %}A new social account has been added.{% endblocktrans %}{% endblock notification_message %} diff --git a/allauth/templates/socialaccount/email/social_account_added_subject.txt b/allauth/templates/socialaccount/email/social_account_added_subject.txt new file mode 100644 index 0000000000..13f95adf04 --- /dev/null +++ b/allauth/templates/socialaccount/email/social_account_added_subject.txt @@ -0,0 +1,4 @@ +{% load i18n %} +{% autoescape off %} +{% blocktrans %}Social account added{% endblocktrans %} +{% endautoescape %} diff --git a/allauth/templates/socialaccount/email/social_account_disconnected_message.txt b/allauth/templates/socialaccount/email/social_account_disconnected_message.txt new file mode 100644 index 0000000000..951ca8ec3a --- /dev/null +++ b/allauth/templates/socialaccount/email/social_account_disconnected_message.txt @@ -0,0 +1,4 @@ +{% extends "account/email/base_notification.txt" %} +{% load i18n %} + +{% block notification_message %}{% blocktrans %}Your social account has been disconnected{% endblocktrans %}{% endblock notification_message %} diff --git a/allauth/templates/socialaccount/email/social_account_disconnected_subject.txt b/allauth/templates/socialaccount/email/social_account_disconnected_subject.txt new file mode 100644 index 0000000000..fa2604105e --- /dev/null +++ b/allauth/templates/socialaccount/email/social_account_disconnected_subject.txt @@ -0,0 +1,4 @@ +{% load i18n %} +{% autoescape off %} +{% blocktrans %}Social account disconnected{% endblocktrans %} +{% endautoescape %} diff --git a/allauth/templates/socialaccount/email/social_account_updated_message.txt b/allauth/templates/socialaccount/email/social_account_updated_message.txt new file mode 100644 index 0000000000..da4b00b8c8 --- /dev/null +++ b/allauth/templates/socialaccount/email/social_account_updated_message.txt @@ -0,0 +1,4 @@ +{% extends "account/email/base_notification.txt" %} +{% load i18n %} + +{% block notification_message %}{% blocktrans %}Your social account has been updated.{% endblocktrans %}{% endblock notification_message %} diff --git a/allauth/templates/socialaccount/email/social_account_updated_subject.txt b/allauth/templates/socialaccount/email/social_account_updated_subject.txt new file mode 100644 index 0000000000..dc0fc7bd5f --- /dev/null +++ b/allauth/templates/socialaccount/email/social_account_updated_subject.txt @@ -0,0 +1,4 @@ +{% load i18n %} +{% autoescape off %} +{% blocktrans %}Social account updated{% endblocktrans %} +{% endautoescape %}