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

Make views.login compatible with django 1.4 by updating messaging #7

Open
wants to merge 4 commits into
base: master
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
6 changes: 4 additions & 2 deletions django_cas/backends.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,8 +131,10 @@ def authenticate(self, ticket, service):
if not username:
return None

user, created = User.objects.get_or_create(username=username)
if created:
try:
user = User.objects.get(username=username)
except User.DoesNotExist:
user = User(username=username, email=username)
user.set_unusable_password()

if authentication_response and _CAS_USER_DETAILS_RESOLVER:
Expand Down
13 changes: 7 additions & 6 deletions django_cas/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@
from urllib import urlencode
from urlparse import urljoin

from django.http import get_host, HttpResponseRedirect, HttpResponseForbidden, HttpResponse
from django.http import HttpResponseRedirect, HttpResponseForbidden, HttpResponse
from django.conf import settings
from django.contrib import messages
from django.contrib.auth import REDIRECT_FIELD_NAME
from django_cas.models import PgtIOU

Expand All @@ -14,7 +15,7 @@ def _service_url(request, redirect_to=None):
"""Generates application service URL for CAS"""

protocol = ('http://', 'https://')[request.is_secure()]
host = get_host(request)
host = request.get_host()
service = protocol + host + request.path
if redirect_to:
if '?' in service:
Expand All @@ -37,7 +38,7 @@ def _redirect_url(request):
else:
next = request.META.get('HTTP_REFERER', settings.CAS_REDIRECT_URL)
prefix = (('http://', 'https://')[request.is_secure()] +
get_host(request))
request.get_host())
if next.startswith(prefix):
next = next[len(prefix):]
return next
Expand All @@ -62,7 +63,7 @@ def _logout_url(request, next_page=None):
url = urljoin(settings.CAS_SERVER_URL, 'logout')
if next_page:
protocol = ('http://', 'https://')[request.is_secure()]
host = get_host(request)
host = request.get_host()
url += '?' + urlencode({'url': protocol + host + next_page})
return url

Expand All @@ -74,7 +75,7 @@ def login(request, next_page=None, required=False):
next_page = _redirect_url(request)
if request.user.is_authenticated():
message = "You are logged in as %s." % request.user.username
request.user.message_set.create(message=message)
messages.success(request, message)
return HttpResponseRedirect(next_page)
ticket = request.GET.get('ticket')
service = _service_url(request, next_page)
Expand All @@ -86,7 +87,7 @@ def login(request, next_page=None, required=False):
auth.login(request, user)
name = user.first_name or user.username
message = "Login succeeded. Welcome, %s." % name
user.message_set.create(message=message)
messages.success(request, message)
return HttpResponseRedirect(next_page)
elif settings.CAS_RETRY_LOGIN or required:
return HttpResponseRedirect(_login_url(service, ticket))
Expand Down