Skip to content

Commit 46690a0

Browse files
committed
Fix pre Django 1.10 compatibility with is_authenticated as a method
1 parent 017ebf1 commit 46690a0

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

djangosaml2/views.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,16 @@ def _get_subject_id(session):
6868
return None
6969

7070

71+
def callable_bool(value):
72+
""" A compatibility wrapper for pre Django 1.10 User model API that used
73+
is_authenticated() and is_anonymous() methods instead of attributes
74+
"""
75+
if callable(value):
76+
return value()
77+
else:
78+
return value
79+
80+
7181
def login(request,
7282
config_loader_path=None,
7383
wayf_template='djangosaml2/wayf.html',
@@ -109,7 +119,7 @@ def login(request,
109119
# SAML_IGNORE_AUTHENTICATED_USERS_ON_LOGIN setting. If that setting
110120
# is True (default value) we will redirect him to the came_from view.
111121
# Otherwise, we will show an (configurable) authorization error.
112-
if request.user.is_authenticated:
122+
if callable_bool(request.user.is_authenticated):
113123
redirect_authenticated_user = getattr(settings, 'SAML_IGNORE_AUTHENTICATED_USERS_ON_LOGIN', True)
114124
if redirect_authenticated_user:
115125
return HttpResponseRedirect(came_from)

0 commit comments

Comments
 (0)