def login2(request):
    form_obj = forms.LoginForm()
    if request.method == "POST":
        gt = GeetestLib(pc_geetest_id, pc_geetest_key)
        challenge = request.POST.get(gt.FN_CHALLENGE, "")
        validate = request.POST.get(gt.FN_VALIDATE, "")
        seccode = request.POST.get(gt.FN_SECCODE, "")
        status = request.session[gt.GT_STATUS_SESSION_KEY]
        user_id = request.session["user_id"]
        if status:
            result = gt.success_validate(challenge, validate, seccode, user_id)
        else:
            result = gt.failback_validate(challenge, validate, seccode)

        if result:
            ret = {"code": 0}
            username = request.POST.get("username")
            password = request.POST.get("password")
            user = auth.authenticate(username=username, password=password)
            if user:
                ret["data"] = "/index/"
            else:
                ret["code"] = 1
                ret["data"] = "用户名或者密码错误"

            return JsonResponse(ret)

    return render(request, "login2.html", {"form_obj": form_obj})
Beispiel #2
0
def login_slide_validate(request):
    if request.method == "POST":
        res = {"code": 0}
        gt = geetest.GeetestLib(pc_geetest_id, pc_geetest_key)
        challenge = request.POST.get(gt.FN_CHALLENGE, '')
        validate = request.POST.get(gt.FN_VALIDATE, '')
        seccode = request.POST.get(gt.FN_SECCODE, '')
        status = request.session[gt.GT_STATUS_SESSION_KEY]
        user_id = request.session["user_id"]
        if status:
            result = gt.success_validate(challenge, validate, seccode, user_id)
        else:
            result = gt.failback_validate(challenge, validate, seccode)

        if result:
            username = request.POST.get("username")
            password = request.POST.get("password")
            print(username, password)
            user = authenticate(username=username, password=password)
            if user:
                auth.login(request, user)
                res = {"code": 1}
        else:
            res["code"] = 0
        return JsonResponse(res)

    login_obj = forms.LoginForm()
    return render(request, "login_slide_validate.html",
                  {"login_obj": login_obj})
Beispiel #3
0
def login(request):
    if request.method == 'GET':
        loginform = forms.LoginForm()
        return render(request, 'blog/login.html', {'loginform': loginform})
    elif request.method == 'POST':
        loginform = forms.LoginForm(request.POST)
        if loginform.is_valid():
            # 使用django的用户
            obj = auth.authenticate(username=loginform.cleaned_data.get('username'), password=loginform.cleaned_data.get('password'))
            #obj = models.UserInfo.objects.filter(**loginform.cleaned_data).first()
            if obj:
                request.session['username'] = loginform.cleaned_data.get('username')
                return redirect(reverse('blog_list'))
            else:
                error_message = '用户名或密码错误'
                return render(request, 'blog/login.html', {'loginform': loginform,'error_message': error_message})
        else:
            return render(request, 'blog/login.html', {'loginform': loginform})
def login(request):
    if request.method == "GET":
        loginForm = forms.LoginForm()
        return render(request,"login.html",{"loginForm":loginForm})
    elif request.method == "POST":
        remember = request.POST.get("remember")
        loginForm = forms.LoginForm(request.POST)
        ret = {"success_info":None,"error_info":None}
        if loginForm.is_valid():
            login_user = models.UserInfo.objects.filter(**loginForm.cleaned_data).first()
            if login_user:
                request.session['is_login'] = True
                request.session['user_id'] = login_user.id
                if not remember:
                    request.session.set_expiry(0)
                ret['success_info'] = loginForm.cleaned_data.get("username")
        else:
            ret['error_info'] = loginForm.errors
        return JsonResponse(ret)
Beispiel #5
0
def login():
    if current_user.is_authenticated:
        return redirect(url_for('home'))
    form = forms.LoginForm()
    if form.validate_on_submit():
        user = models.User.query.filter_by(email=form.email.data).first()
        if user and crypto.check_password_hash(user.password,
                                               form.password.data):
            login_user(user, remember=form.remember.data)
            page = request.args.get('next')
            return redirect(page) if page else redirect(url_for('home'))
        else:
            flash('Incorrect Username or Password', 'danger')
    return render_template('login.html', title='login', form=form)
Beispiel #6
0
def login():

    loginform = forms.LoginForm()

    if loginform.validate_on_submit():
        username = loginform.username.data
        password = loginform.password.data

        user = models.User.query.filter_by(name=username).first()
        if user is None:
            flask.flash("User {} doesn't exist.".format(username))
            return flask.redirect(flask.url_for('login'))

        user_handler = models.UserHandler(user)
        if user_handler.login(password):
            flask.flash("{} logged in !".format(username))
            print('current_user:'******'homepage'))
        else:
            flask.flash("Something went wrong")

    return flask.render_template('login.html', form=loginform)
def login(request):
    form_obj = forms.LoginForm()
    if request.method == "POST":
        ret = {"code": 0}
        username = request.POST.get("username")
        password = request.POST.get("password")
        v_code = request.POST.get("v_code", "")

        if v_code.upper() == request.session.get("v_code", ""):
            user = auth.authenticate(username=username, password=password)
            if user:
                auth.login(request, user)
                ret["data"] = "/index/"
            else:
                ret["code"] = 1
                ret["data"] = "用户名密码错误"
        else:
            ret["code"] = 1
            ret["data"] = "验证码错误"
        return JsonResponse(ret)

    return render(request, "login.html", {"form_obj": form_obj})
Beispiel #8
0
 def get(self, request):
     login_obj = forms.LoginForm()
     return render(request, "login_slide_validate.html",
                   {"login_obj": login_obj})