Skip to content

Commit

Permalink
Add social accounts signals
Browse files Browse the repository at this point in the history
  • Loading branch information
varun kumar committed Nov 18, 2023
1 parent 2901daf commit b65ab8f
Show file tree
Hide file tree
Showing 9 changed files with 37 additions and 0 deletions.
3 changes: 3 additions & 0 deletions allauth/socialaccount/adapter.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
3 changes: 3 additions & 0 deletions allauth/socialaccount/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -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, {}
)
7 changes: 7 additions & 0 deletions allauth/socialaccount/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -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 %}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{% load i18n %}
{% autoescape off %}
{% blocktrans %}Social account added{% endblocktrans %}
{% endautoescape %}
Original file line number Diff line number Diff line change
@@ -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 %}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{% load i18n %}
{% autoescape off %}
{% blocktrans %}Social account disconnected{% endblocktrans %}
{% endautoescape %}
Original file line number Diff line number Diff line change
@@ -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 %}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{% load i18n %}
{% autoescape off %}
{% blocktrans %}Social account updated{% endblocktrans %}
{% endautoescape %}

0 comments on commit b65ab8f

Please sign in to comment.