Ejemplo n.º 1
0
def authentication(request):
    context = RequestContext(request)
    if request.method == 'POST':
        username = request.REQUEST["username"]
        password = request.REQUEST["passwd"]
        authenticate = ldapAuth(request, username, password)
        if authenticate == 'VALID':
            userType = request.session.get('userType')
            if userType == 'f':
                return redirect('/instructor')
            else:
                return redirect('/student')
        else:
            return render_to_response('authentication/index.html', {'logged': False}, context)
    else:
        return redirect('authentication.views.index')
Ejemplo n.º 2
0
def authentication(request):
    print("13")
    context = RequestContext(request)
    if request.method == 'POST':
        print("16")
        Username = request.POST["username"]
        Password = request.POST["passwd"]
        authenticate = ldapAuth(request, Username, Password)
        if authenticate=='VALID':
            print("20")
            if User.objects.filter(username=Username).exists() :
                print("user exists")               
                user=User.objects.all().filter(username=Username)
                user=auth.authenticate(username=Username,password='******')
            else:
                print("new user made it")
                new_user=User.objects.create_user( Username, Username+"@cse.iitb.ac.in", 'libpassword')
                profile=new_user.profile
                new_user.save()
                user=auth.authenticate(username=Username,password='******')
            if user and user.is_active :
                print("37")

                auth.login(request, user)
                if request.user.is_authenticated():
                    print(str(request.session.get('username'))+"nice work")
                request.session['username']=Username
                #print(request.GET['next'])
                return redirect('/search/')
            else:
                print("error authentication") 
            return render_to_response('authentication/index.html', {'logged': 4,'ecomment':"worong username or password"}, context)   
            print("36")
             
        else:
            return render_to_response('authentication/index.html', {'logged': 4,'ecomment':"worong username or password"}, context)
    else:       
        return render_to_response('authentication/index.html', {'logged': 4}, context)