Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for User models with renamed username field. #79

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion cas/backends.py
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ def authenticate(self, request, ticket, service):
return None

try:
user = User.objects.get(username__iexact=username)
user = User._default_manager.get_by_natural_key(username)
except User.DoesNotExist:
# user will have an "unusable" password
if settings.CAS_AUTO_CREATE_USER:
Expand Down
8 changes: 5 additions & 3 deletions cas/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,13 +85,15 @@ def get_tgt_for(user):
if not settings.CAS_PROXY_CALLBACK:
raise CasConfigException("No proxy callback set in settings")

username = user.get_username()

try:
return Tgt.objects.get(username=user.username)
return Tgt.objects.get(username=username)
except ObjectDoesNotExist:
logger.warning('No ticket found for user {user}'.format(
user=user.username
user=username
))
raise CasTicketException("no ticket found for user " + user.username)
raise CasTicketException("no ticket found for user " + username)


def delete_old_tickets(**kwargs):
Expand Down
2 changes: 1 addition & 1 deletion cas/tests/test_backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,4 @@ def test_user_auto_create(self, verify):

with self.settings(CAS_AUTO_CREATE_USER=True):
user = backend.authenticate('fake', 'fake')
self.assertEquals(user.username, username)
self.assertEquals(user.get_username(), username)