Skip to content

Commit

Permalink
Add messages and signals
Browse files Browse the repository at this point in the history
Add "Password is expired" message.
Add `password_expired` signal.
Update signals documentation.
  • Loading branch information
grahamu committed Sep 13, 2016
1 parent 527b9cc commit f69f798
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 0 deletions.
7 changes: 7 additions & 0 deletions account/middleware.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
from __future__ import unicode_literals

from django.contrib import messages
from django.core.urlresolvers import resolve
from django.shortcuts import redirect
from django.utils import translation, timezone
from django.utils.cache import patch_vary_headers
from django.utils.translation import ugettext_lazy as _

from account.conf import settings
from account.models import Account
Expand Down Expand Up @@ -64,6 +66,11 @@ def process_request(self, request):
# All users must be allowed to access "change password" url.
if url_name not in settings.ACCOUNT_PASSWORD_CHANGE_REDIRECT_URL:
if check_password_expired(request.user):
messages.add_message(
request,
messages.WARNING,
_("Password is expired.")
)
return redirect(
settings.ACCOUNT_PASSWORD_CHANGE_REDIRECT_URL
)
1 change: 1 addition & 0 deletions account/signals.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,4 @@
email_confirmed = django.dispatch.Signal(providing_args=["email_address"])
email_confirmation_sent = django.dispatch.Signal(providing_args=["confirmation"])
password_changed = django.dispatch.Signal(providing_args=["user"])
password_expired = django.dispatch.Signal(providing_args=["user"])
7 changes: 7 additions & 0 deletions docs/signals.rst
Original file line number Diff line number Diff line change
Expand Up @@ -66,4 +66,11 @@ password_changed
----------------

Triggered when a user changes his password. Providing argument ``user``
(User instance).


password_expired
----------------

Triggered when a user password is expired. Providing argument ``user``
(User instance).

0 comments on commit f69f798

Please sign in to comment.