def login(request, next_page=None, required=False): """Forwards to CAS login URL or verifies CAS ticket Modified locally: honour next=??? in query string, don't deliver a message, catch HTTPError and IOError, generate LogEntry """ if not next_page and 'next' in request.GET: next_page = request.GET['next'] if not next_page: next_page = _redirect_url(request) if request.user.is_authenticated: #message = "You are logged in as %s." % request.user.username #messages.success(request, message) return HttpResponseRedirect(next_page) ticket = request.GET.get('ticket') service = _service_url(request, next_page) if ticket: from django.contrib import auth try: user = auth.authenticate(ticket=ticket, service=service, request=request) except IOError as e: # Here we want to catch only: connection reset, timeouts, name or service unknown if e.errno in [104, 110, 'socket error']: user = None # HTTPError is a type of OSError, which IOError is an alias for. # Sometimes, the CAS server seems to just return a 500 internal server error. Let's handle that the # same way as the above case. elif isinstance(e, HTTPError): if e.code == 500: user = None else: # Any other HTTPError should bubble up and let us know something horrible has happened. raise HTTPError( "Got an HTTP Error when authenticating. The error is: {0!s}." .format(e)) else: raise IOError("The errno is %r: %s." % (e.errno, str(e))) except ParseError: user = None if user is not None: auth.login(request, user) #LOG EVENT# l = LogEntry(userid=user.username, description=("logged in as %s from %s") % (user.username, ip.get_ip(request)), related_object=user) l.save() return HttpResponseRedirect(next_page) elif settings.CAS_RETRY_LOGIN or required: return HttpResponseRedirect(_login_url(service)) else: error = "<h1>Forbidden</h1><p>Login failed.</p>" return HttpResponseForbidden(error) else: return HttpResponseRedirect(_login_url(service))
def process_request(self, request): """Logs in the user if a ticket is append as parameter""" ticket = request.GET.get('ticket') if ticket: from django.contrib import auth user = auth.authenticate(ticket=ticket, service=_service_url(request)) if user is not None: auth.login(request, user)
def process_request(self, request): """Logs in the user if a ticket is append as parameter""" ticket = request.REQUEST.get('ticket') if ticket: from django.contrib import auth user = auth.authenticate(ticket=ticket, service=_service_url(request)) if user is not None: auth.login(request, user)
def render_schedule(request, next_page=None, required=True): if request.user.is_authenticated(): # Query the database for a list of ALL events stored per Calendar. all_events = Event.objects.all() data = {'Events': all_events} return render_to_response('schedules/main.html', data) else: logging.error( 'redirecting to login from render_schedule... could not authenticate user ' + request.user.username) service = _service_url(request, next_page) return HttpResponseRedirect(_login_url(service))
def login(request, next_page=None, required=False): """Forwards to CAS login URL or verifies CAS ticket Modified locally: honour next=??? in query string, don't deliver a message, catch HTTPError and IOError, generate LogEntry """ if not next_page and 'next' in request.GET: next_page = request.GET['next'] if not next_page: next_page = _redirect_url(request) if request.user.is_authenticated: #message = "You are logged in as %s." % request.user.username #messages.success(request, message) return HttpResponseRedirect(next_page) ticket = request.GET.get('ticket') service = _service_url(request, next_page) if ticket: from django.contrib import auth try: user = auth.authenticate(ticket=ticket, service=service, request=request) except IOError as e: # Here we want to catch only: connection reset, timeouts, name or service unknown if e.errno in [104, 110, 'socket error']: user = None # HTTPError is a type of OSError, which IOError is an alias for. # Sometimes, the CAS server seems to just return a 500 internal server error. Let's handle that the # same way as the above case. elif isinstance(e, HTTPError): if e.code == 500: user = None else: # Any other HTTPError should bubble up and let us know something horrible has happened. raise HTTPError("Got an HTTP Error when authenticating. The error is: {0!s}.".format(e)) else: raise IOError("The errno is %r: %s." % (e.errno, str(e))) except ParseError: user = None if user is not None: auth.login(request, user) #LOG EVENT# l = LogEntry(userid=user.username, description=("logged in as %s from %s") % (user.username, ip.get_ip(request)), related_object=user) l.save() return HttpResponseRedirect(next_page) elif settings.CAS_RETRY_LOGIN or required: return HttpResponseRedirect(_login_url(service)) else: error = "<h1>Forbidden</h1><p>Login failed.</p>" return HttpResponseForbidden(error) else: return HttpResponseRedirect(_login_url(service))
def process_request(self, request): """Logs in the user if a ticket is append as parameter""" ticket = request.REQUEST.get('ticket') if ticket: from django.contrib import auth # Mihara: This way we ensure that the session ID that auth wants is # free when we try to do this. It seems to work. # This also enforces single-login as a side effect, # so if we want this to get accepted upstream one day, we need to figure out the right # way to deal with it. if request.user and request.user.is_authenticated(): auth.logout(request) # , request.user) user = auth.authenticate(ticket=ticket, service=_service_url(request)) if user is not None: auth.login(request, user)
def login(request, next_page=None, required=False): """Forwards to CAS login URL or verifies CAS ticket Modified locally: honour next=??? in query string, don't deliver a message, catch IOError, generate LogEntry """ if not next_page and 'next' in request.GET: next_page = request.GET['next'] if not next_page: next_page = _redirect_url(request) if request.user.is_authenticated(): #message = "You are logged in as %s." % request.user.username #messages.success(request, message) return HttpResponseRedirect(next_page) ticket = request.GET.get('ticket') service = _service_url(request, next_page) if ticket: from django.contrib import auth try: user = auth.authenticate(ticket=ticket, service=service, request=request) except IOError as e: # Here we want to catch only: connection reset, timeouts, name or service unknown if e.errno in [104, 110, 'socket error']: user = None else: raise IOError, "The errno is %r: %s." % (e.errno, unicode(e)) except ParseError: user = None if user is not None: auth.login(request, user) #LOG EVENT# l = LogEntry(userid=user.username, description=("logged in as %s from %s") % (user.username, ip.get_ip(request)), related_object=user) l.save() return HttpResponseRedirect(next_page) elif settings.CAS_RETRY_LOGIN or required: return HttpResponseRedirect(_login_url(service)) else: error = "<h1>Forbidden</h1><p>Login failed.</p>" return HttpResponseForbidden(error) else: return HttpResponseRedirect(_login_url(service))
def process_request(self, request): """Logs in the user if a ticket is append as parameter""" # print "in process request.." # print "request meta: %s" % request.META ticket = request.REQUEST.get('ticket') # print "ticket = %s" % ticket if ticket: # print "do authenticate ..." from django.contrib import auth user = auth.authenticate(ticket=ticket, service=_service_url(request)) # print "returned user: %s ..." % user if user is not None: auth.login(request, user)
def login(request, next_page=None, required=False): """Forwards to CAS login URL or verifies CAS ticket Modified locally: honour next=??? in query string, don't deliver a message, catch IOError, generate LogEntry """ if not next_page and 'next' in request.GET: next_page = request.GET['next'] if not next_page: next_page = _redirect_url(request) if request.user.is_authenticated(): #message = "You are logged in as %s." % request.user.username #messages.success(request, message) return HttpResponseRedirect(next_page) ticket = request.GET.get('ticket') service = _service_url(request, next_page) if ticket: from django.contrib import auth try: user = auth.authenticate(ticket=ticket, service=service, request=request) except IOError as e: # Here we want to catch only: connection reset, timeouts, name or service unknown if e.errno in [104, 110, 'socket error']: user = None else: raise IOError, "The errno is %r: %s." % (e.errno, unicode(e)) if user is not None: auth.login(request, user) #LOG EVENT# l = LogEntry(userid=user.username, description=("logged in as %s from %s") % (user.username, ip.get_ip(request)), related_object=user) l.save() return HttpResponseRedirect(next_page) elif settings.CAS_RETRY_LOGIN or required: return HttpResponseRedirect(_login_url(service)) else: error = "<h1>Forbidden</h1><p>Login failed.</p>" return HttpResponseForbidden(error) else: return HttpResponseRedirect(_login_url(service))