Пример #1
0
def app_login(request):
    #create the form object
    #to hand the inputs
    form = LoginForm()

    #determines if this is get request
    if request.method == "GET":
        """Determines if the user is authenticated.
        Authenticated users are served the index page
        while anonymous users are served the login page"""
        if request.user.is_authenticated():
            #Gets user profile to do checks


            #Only require google login if not inventory
            if request.user.first_name.lower() != 'inventory':

                return check_google_authenticated(request)

            return HttpResponseRedirect('/main')

        else:
            #logout the request
            logout(request)
            #create a new login form
            form = LoginForm()
            return render(request, 'login.html', {'form':form})

    #what to do with a post request
    elif request.method == "POST":
        #initialize form with post data
        form = LoginForm(request.POST)
        #check if form is valid
        if form.is_valid():

            cleanUsername = form.cleaned_data['username']
            cleanPassword = form.cleaned_data['password']

            user = authenticate(username=cleanUsername, password=cleanPassword)

            #checks whether user authennticated
            if user is not None:

                #checks if user is still active
                if user.is_active:

                    #login the user
                    login(request, user)


                    #Only require google login if not inventory
                    if user.first_name.lower() != 'inventory':
                        return check_google_authenticated(request)

                    #Gets user profile to do checks
                    return HttpResponseRedirect('/main')

            return HttpResponseRedirect('/')
Пример #2
0
def login_user(request):
    state = "Please log in below..."
    username = password = ''
    if request.POST:
        form = LoginForm(request.POST)
        if(form.is_valid()):
            user = authenticate(username = form.cleaned_data['pseudo'], password=form.cleaned_data['mdp'])
            if user is not None:
                state = 'logged in'
    else:
        form = LoginForm()
    c = RequestContext(request,{'message':state, 'form':form})
    return render_to_response('login.html',c)
Пример #3
0
def app_login(request):
    #create the form object
    #to hand the inputs
    form = LoginForm()

    #determines if this is get request
    if request.method == "GET":
        """Determines if the user is authenticated.
        Authenticated users are served the index page
        while anonymous users are served the login page"""
        if request.user.is_authenticated():
            #Gets user profile to do checks

            #Only require google login if not inventory
            if request.user.first_name.lower() != 'inventory':

                return check_google_authenticated(request)

            return HttpResponseRedirect('/main')

        else:
            #logout the request
            logout(request)
            #create a new login form
            form = LoginForm()
            return render(request, 'login.html', {'form': form})

    #what to do with a post request
    elif request.method == "POST":
        #initialize form with post data
        form = LoginForm(request.POST)
        #check if form is valid
        if form.is_valid():

            cleanUsername = form.cleaned_data['username']
            cleanPassword = form.cleaned_data['password']

            user = authenticate(username=cleanUsername, password=cleanPassword)

            #checks whether user authennticated
            if user is not None:
                #checks if user is still active
                if user.is_active:

                    #login the user
                    login(request, user)

                    #Check if the password needs to be reset
                    if user.reset_password:
                        return HttpResponseRedirect('/password-reset')

                    #Only require google login if not inventory
                    if user.first_name.lower() != 'inventory':
                        #return HttpResponseRedirect('/main')

                        return check_google_authenticated(request)

                    #Gets user profile to do checks
                    return HttpResponseRedirect('/main')

            return HttpResponseRedirect('/')

        else:

            logger.warn(form.__dict__)

            #create a new login form
            form = LoginForm()
            return render(request, 'login.html', {'form': form})

    else:
        #create a new login form
        form = LoginForm()
        return render(request, 'login.html', {'form': form})