Permalink
Browse files

Add notification on password change

  • Loading branch information...
jochenklar committed Dec 18, 2018
1 parent f0b4342 commit a12314a2dbdcb10c70f9e4ba583225a896859f57
@@ -5,7 +5,7 @@
from django.dispatch import receiver
from django.db.models.signals import post_save, m2m_changed

from allauth.account.signals import email_confirmed
from allauth.account.signals import email_confirmed, password_changed, password_reset

from .models import Profile

@@ -26,7 +26,8 @@
send_notify_confirmation,
send_notify_rejection,
send_notify_activation,
send_activation
send_activation,
send_notify_password_changed,
)

logger = logging.getLogger(__name__)
@@ -142,3 +143,17 @@ def user_enabled_handler(sender, **kwargs):
user = kwargs['user']

logger.info('user \'%s\' enabled by \'%s\'.' % (user.username, request.user.username))


@receiver(password_changed)
@receiver(password_reset)
def password_changed_handler(sender, **kwargs):
'''
Gets notified when a user was disabled by a manager.
'''
request = kwargs['request']
user = kwargs['user']

logger.info('user \'%s\' changed his/her password.' % user.username)
if settings.AUTH_WORKFLOW == 'confirmation':
send_notify_password_changed(request, user)
@@ -0,0 +1,7 @@
{% load i18n %}
{% blocktrans with site_name=current_site.name %}
Dear {{ site_name }} Team,
{% endblocktrans %}
{% blocktrans trimmed with full_user=user.profile.full_name %}
{{ full_user }} has just updated his/her password.
{% endblocktrans %}
@@ -0,0 +1 @@
{% load i18n %}{% trans 'Account updated' %}
@@ -87,3 +87,14 @@ def send_activation(request, user):
'login_url': request.build_absolute_uri(reverse('account_login'))
}
send_mail(request, 'account/email/activation', context, [user.email])


def send_notify_password_changed(request, user):
'''
Sends an email to the admins once a user updated his/her account.
'''
emails = get_admin_emails()
context = {
'user': user
}
send_mail(request, 'account/email/notify_password_changed', context, emails)

0 comments on commit a12314a

Please sign in to comment.