def process_view(self, request, view_func, view_args, view_kwargs): """ Forwards unauthenticated requests to the admin page to the CAS login URL, as well as calls to django.contrib.auth.views.login and logout. """ if view_func == login: return cas_login(request, *view_args, **view_kwargs) elif view_func == logout: return cas_logout(request, *view_args, **view_kwargs) if settings.CAS_ADMIN_PREFIX: if not request.path.startswith(settings.CAS_ADMIN_PREFIX): return None elif not view_func.__module__.startswith('django.contrib.admin.'): return None if request.user.is_authenticated(): if request.user.is_staff: return None else: error = ('<h1>Forbidden</h1><p>You do not have staff ' 'privileges.</p>') return HttpResponseForbidden(error) params = urlencode({REDIRECT_FIELD_NAME: request.get_full_path()}) return HttpResponseRedirect(reverse(cas_login) + '?' + params)
def login_view(request): """ A view to login a user. """ if settings.DEBUG: login_dummy_user(request, 'dev', admin=True) return HttpResponseRedirect(request.GET.get('next', '/')) return cas_login(request)
def custom_cas_login(request, *args, **kwargs): """If a student has not completed the welcome walkthrough, go there on login.""" response = cas_login(request, *args, **kwargs) # returns HttpResponseRedirect if request.user.is_authenticated(): if not request.user.student.totally_done(): if not request.user.student.completedName: return HttpResponseRedirect(reverse('welcomeName')) elif not request.user.student.completedPrivacy: return HttpResponseRedirect(reverse('welcomePrivacy')) elif not request.user.student.completedMajor: return HttpResponseRedirect(reverse('welcomeMajor')) elif not request.user.completedSocial: return HttpResponseRedirect(reverse('welcomeSocial')) else: # do not 'welcome back' blocked users if not request.user.student.blocked: welcome_back = random.choice(return_messages) messages.add_message(request, messages.INFO, mark_safe(welcome_back)) return response