Пример #1
0
def perform_login(request):
    """
        Perform user authentication
    """
    user = None  
    login_failure = None
    if request.method == 'POST':
        username = request.POST["username"]
        password = request.POST["password"]
        user = authenticate(username=username, password=password)
        if user is not None and not user.is_anonymous():
            login(request,user)
        else:
            login_failure = "Invalid username or password"
    
    if request.user.is_authenticated():
        # Try to authenticate with Fermi
        remote_view_util.authenticate(request)
        
        # If we came from a given page and just needed 
        # authentication, go back to that page.
        if "next" in request.GET:
            redirect_url = request.GET["next"]
            return redirect(redirect_url)
        return redirect(reverse(settings.LANDING_VIEW))
    else:
        # Breadcrumbs
        breadcrumbs = Breadcrumbs()
        breadcrumbs.append("login")
        
        template_values = {'breadcrumbs': breadcrumbs,
                           'login_failure': login_failure}
        template_values = fill_template_values(request, **template_values)
        
        return render_to_response('users/authenticate.html', template_values,
                              context_instance=RequestContext(request))
Пример #2
0
def authenticate(request):
    """
        Authenticate and return to the previous page.
        @param request: request object
    """
    redirect_url = reverse(settings.LANDING_VIEW)
    if 'redirect' in request.POST:
        redirect_url = request.POST['redirect']
    if request.method == 'POST':
        form = forms.FermiLoginForm(request.POST, request.FILES)
        if form.is_valid():
            status, reason = remote_view_util.authenticate(request)
            if status is not 200:
                breadcrumbs = Breadcrumbs()                
                message = "Could not authenticate with Fermi"
                if len(reason)>0:
                    message += "<p>Server message: %s" % reason
                template_values = {'message': message,
                                   'back_url': redirect_url,
                                   'breadcrumbs': breadcrumbs,}
                template_values = reduction_server_view_util.fill_template_values(request, **template_values)
                return render_to_response('remote/failed_connection.html',
                                          template_values)
    return redirect(redirect_url)