Example #1
0
def login(request):
    print "this is test"
    if request.method == 'POST':
        username = request.REQUEST.get('log_un', None)
        pwd = request.REQUEST.get('log_pwd', None)
        code = request.REQUEST.get('log_code', None)
        if username is None:
            form = LoginForm(request.POST)
            if form.is_valid():
                cd = form.clean()
                username = cd['username']
                pwd = cd['password']
                code = cd['vcode']
                i = user_auth(request, username, pwd, code)
                if i == 1:
                    a = request.REQUEST.get('next', None)
                    if a:
                        return HttpResponseRedirect(a)
                    else:
                        return HttpResponseRedirect(reverse('search_result_m'))
                else:
                    form.valiatetype(i)
                    return render_to_response('login_m.html', {'form': form, },
                                              context_instance=RequestContext(request))
            else:
                return render_to_response('login_m.html', {'form': form, },
                                          context_instance=RequestContext(request))

        return refresh_header(request, user_auth(request, username, pwd, code))
    else:
        form = LoginForm()
        next = request.GET.get('next', None)
        return render_to_response('login_m.html', {'form': form, 'next': next},
                                  context_instance=RequestContext(request))
Example #2
0
def login(request):
    if request.method == 'POST':
        username = request.REQUEST.get('log_un', None)
        pwd = request.REQUEST.get('log_pwd', None)
        code = request.REQUEST.get('log_code', None)
        if username is None:
            form = LoginForm(request.POST)
            print(form)
            if form.is_valid():
                cd = form.clean()
                print(cd)
                username = cd['username']
                pwd = cd['password']
                code = cd['vcode']
                i = user_auth(request, username, pwd, code)
                if i == 1:
                    a = request.REQUEST.get('next', None)
                    if a:
                        return HttpResponseRedirect(a)
                    else:
                        return HttpResponseRedirect(reverse('searchindex'))
                else:
                    form.valiatetype(i)
                    return render_to_response('login.html', {'form': form, },
                                              context_instance=RequestContext(request))
            else:
                return render_to_response('login.html', {'form': form, },
                                          context_instance=RequestContext(request))

        return refresh_header(request, user_auth(request, username, pwd, code))
    else:
        form = LoginForm()
        next = request.GET.get('next', None)
        return render_to_response('login.html', {'form': form, 'next': next},
                                  context_instance=RequestContext(request))
Example #3
0
def login(request):
    if request.method == 'POST':
        username = request.REQUEST.get('log_un', None)
        pwd = request.REQUEST.get('log_pwd', None)
        code = request.REQUEST.get('log_code', None)
        if username is None:
            form = LoginForm(request.POST)
            if form.is_valid():
                cd = form.clean()
                username = cd['username']
                pwd = cd['password']
                code = cd['vcode']
                i = user_auth(request, username, pwd, code)
                if i == 1:
                    a = request.REQUEST.get('next', None)
                    if a:
                        return HttpResponseRedirect(a)
                    else:
                        user = User.objects.get(username=username)
                        login_times = user.userinformation.login_times
                        if login_times:
                            user.userinformation.login_times = int(
                                login_times) + 1
                        else:
                            user.userinformation.login_times = 1
                        user.userinformation.save()
                        return HttpResponseRedirect(reverse('searchindex'))
                else:
                    form.valiatetype(i)
                    return render_to_response(
                        'login.html', {
                            'form': form,
                        },
                        context_instance=RequestContext(request))
            else:
                return render_to_response(
                    'login.html', {
                        'form': form,
                    },
                    context_instance=RequestContext(request))

        return refresh_header(request, user_auth(request, username, pwd, code))
    else:
        form = LoginForm()
        next = request.GET.get('next', None)
        return render_to_response('login.html', {
            'form': form,
            'next': next
        },
                                  context_instance=RequestContext(request))