예제 #1
0
def login(request):
    if request.user.is_authenticated():
        return redirect(reverse_lazy('hello'))
    else:
        form = AuthenticationForm(data=request.POST or None)
        if form.is_valid():
            login_function(request, form.get_user())
            return redirect(reverse_lazy('hello'))
        else:
            return render(request, 'accounts/login_form.html', {'form': form})
    return response
예제 #2
0
def login(request):
    msg = ''
    if request.user and request.user.is_authenticated():
        logout_function(request)
    if request.REQUEST.has_key('next') and request.REQUEST['next']:
        next_url = request.REQUEST['next']
    else:
        next_url = reverse('home')
    username, password = request.POST.get('username'), request.POST.get('password')
    if username and password:
        user = authenticate(username=username, password=password)
        if user:
            login_function(request, user)
            return HttpResponseRedirect(next_url)
        else:
            msg = u'Usuario/contraseña inexistente'
    return render_to_response('iSM/login.html', {'msg': msg}, context_instance=RequestContext(request))
예제 #3
0
def login(request):
    msg = u''
    if request.user and request.user.is_authenticated():
        return redirect(reverse('home'))

    if request.REQUEST.has_key('next') and request.REQUEST['next']:
        next_url = request.REQUEST['next']
    else:
        next_url = reverse('home')
    username, password = request.POST.get('username'), request.POST.get('password')
    if username and password:
        user = authenticate(username=username, password=password)
        if user:
            login_function(request, user)
            return redirect(next_url)
        else:
            msg = u'Invalid username/password'
    return render_to_response('tracker/login.html', {'msg': msg}, context_instance=RequestContext(request))
예제 #4
0
def login(request):
    msg = ''
    if request.user and request.user.is_authenticated():
        logout_function(request)
    if request.REQUEST.has_key('next') and request.REQUEST['next']:
        next_url = request.REQUEST['next']
    else:
        next_url = reverse('home')
    username, password = request.POST.get('username'), request.POST.get(
        'password')
    if username and password:
        user = authenticate(username=username, password=password)
        if user:
            login_function(request, user)
            return HttpResponseRedirect(next_url)
        else:
            msg = u'Usuario/contraseña inexistente'
    return render_to_response('iSM/login.html', {'msg': msg},
                              context_instance=RequestContext(request))
예제 #5
0
파일: views.py 프로젝트: azdkj532/arcane
def login(request, id=None):
    if request.user.is_authenticated():
        return redirect('home')
    if not request.POST:
        form = LoginForm()
        return render(request, "user/login.html", locals())
    else:
        username = id
        password = request.POST.get("password", '')
        user = authenticate(username=username, password=password)
        if user is not None:
            if user.is_active:
                login_function(request, user)
                return redirect('home')
            else:
                error = "奇怪的錯誤"
                return render(request, "user/login.html", locals())
        else:
            error = "錯誤的PIN碼"
            return render(request, "user/login.html", locals())
예제 #6
0
def q_register(request):

    context = add_parameters_to_context(request)
    next_page = context.get("next")

    if request.method == "GET":

        registration_form = QUserRegistrationForm()

    else:  # request.method == "POST":

        data = request.POST
        registration_form = QUserRegistrationForm(data=data)

        if registration_form.is_valid():

            registration_form.save()
            new_username = registration_form.cleaned_data["username"]
            new_user_pwd = registration_form.cleaned_data["password1"]

            # need to authenticate new_user before logging in (Django is weird like that)
            new_user = authenticate(username=new_username, password=new_user_pwd)
            if new_user is not None:
                login_function(request, new_user)

                if next_page:
                    return HttpResponseRedirect(next_page)
                else:
                    return HttpResponseRedirect("/users/%s" % (new_username))

        # no need to do additional processing; the forms will sort themselves out w/ errors
        # else:
        #     pass

    # gather all the extra information required by the template
    _dict = {
        "form": registration_form,
    }

    return render_to_response('questionnaire/q_register.html', _dict, context_instance=context)
예제 #7
0
def q_login(request):

    context = add_parameters_to_context(request)
    next_page = context.get("next")

    if request.method == "GET":

        login_form = QUserLoginForm(request)

    else:  # request.method == "POST":

        data = request.POST
        login_form = QUserLoginForm(request, data=data)

        if login_form.is_valid():
            username = login_form.cleaned_data["username"]
            user_pwd = login_form.cleaned_data["password"]
            user = authenticate(username=username, password=user_pwd)
            if user is not None:
                if user.is_active:
                    login_function(request, user)

                    if next_page:
                        return HttpResponseRedirect(next_page)
                    else:
                        return HttpResponseRedirect("/")

        # no need to do additional processing; the forms will sort themselves out w/ errors
        # else:
        #     pass

    # gather all the extra information required by the template
    _dict = {
        "form": login_form,
    }

    return render_to_response('questionnaire/q_login.html', _dict, context_instance=context)
예제 #8
0
파일: crud.py 프로젝트: aldeka/gentlerobots
def login_view(request):
    if request.method == 'POST':
        if request.POST['form-type'] == 'signup':
            print "signup form"
            print request.POST
            username = request.POST['username']
            password = request.POST['password1']
            if not Human.objects.filter(username=username):
                a = Address(username=username, domain='localhost')
                a.save()
                h = Human(username=username, password=make_password(password), address=a)
                h.save()
                print h
                user = authenticate(username=username, password=password)
                print "auth worked"
                login_function(request, user)
                print "logged in!"
                return redirect('home')
            else:
                try:
                    user = authenticate(username=username, password=password)
                    if user is not None:
                        login_function(request, user)
                        print "logged in!"
                        return redirect('home')
                except:
                    pass
            return redirect('home')
        else:
            form = AuthenticationForm(request.POST)
            username = request.POST['username']
            password = request.POST['password']
            user = authenticate(username=username, password=password)
            if user is not None:
                login_function(request, user)
                return redirect('home')
    return redirect('home')