def logingotok(request): post = request.POST username = post.get("Username") disname = post.get("disname") otpcode = post.get("otpcode") returnbackurl = request.session.get("returnbackurl") ip = request.META.get('HTTP_X_FORWARDED_FOR', request.META['REMOTE_ADDR']) agent = request.META.get('HTTP_USER_AGENT', '') try: if not returnbackurl or returnbackurl==r'/' or returnbackurl==r'/login/': returnbackurl = r'/home/' gotken = seargooled(username.lower()) if str(generate_otp(gotken[0]['token'])) == str(otpcode): request.session['username'] = username request.session['displayname'] = disname request.session['returnbackurl'] = '' updateUsertoken(username, ip, agent) result = {'isSuccess': True, "message": '验证成功','backurl': returnbackurl} else: result = {'isSuccess': False, "message": '验证失败'} except Exception as e: print(e) result = {'isSuccess': False, "message": '验证失败'} response = HttpResponse() response['Content-Type'] = "text/javascript" response.write(json.dumps(result)) return response
def userlogin(request): post = request.POST username = post.get("Username") password = post.get("Password") try: if username: if password: if username.lower() == returnadminusernamevalue: adminoldassword = readprofile('password', 'administratorpassword') if check_password(password, adminoldassword): request.session['username'] = returnadminusernamevalue request.session['displayname'] = '超级管理员' result = {'code': 3, "message": '/basite/'} else: result = {'code': 2, "message": '密码错误'} else: loginvalue = verifyuser_login_new(username, password) if loginvalue['isSuccess'] == True: gotken = seargooled(username.lower()) if gotken: result = { 'code': 0, "message": { 'username': loginvalue['message']['sAMAccountName'], 'displayname': loginvalue['message']['displayName'] } } response = HttpResponse() response['Content-Type'] = "text/javascript" response.write(json.dumps(result)) return response else: result = {'code': 1, "message": '未绑定'} response = HttpResponse() response['Content-Type'] = "text/javascript" response.write(json.dumps(result)) return response # return HttpResponseRedirect(returnbackurl, request) else: # return render_to_response("login.html", {'message': loginvalue['message']}) result = {'code': 2, "message": loginvalue['message']} else: result = {'code': 2, "message": '请填写密码'} else: result = {'code': 2, "message": '请填写用户名'} except Exception as e: print(e) result = {'code': 2, "message": '出现异常'} response = HttpResponse() response['Content-Type'] = "text/javascript" response.write(json.dumps(result)) return response
def userlogin(request): post = request.POST username = post.get("Username") password = post.get("Password") ip = request.META.get('HTTP_X_FORWARDED_FOR', request.META['REMOTE_ADDR']) agent = request.META.get('HTTP_USER_AGENT', '') try: result = {'code': 2, 'backurl': ''} if username: if password: if username.lower() == returnadminusernamevalue: adminoldassword =readprofile('password','administratorpassword') if check_password(password, adminoldassword): request.session['username'] = returnadminusernamevalue request.session['displayname'] = '超级管理员' result = {'code': 3, "message": '/basite/'} else: result = {'code': 2, "message": '密码错误'} else: loginvalue = verifyuser_login_new(username, password) if loginvalue['isSuccess']: goo_status = goostatus() if goo_status: if goo_status['usergotoken'] == '0': returnbackurl = request.session.get("returnbackurl") if not returnbackurl or returnbackurl == r'/' or returnbackurl == r'/login/': returnbackurl = r'/home/' request.session['username'] = username request.session['displayname'] = loginvalue['message']['displayname'] request.session['returnbackurl'] = '' # result = {'isSuccess': True, "message": '验证成功', 'backurl': returnbackurl} result = {'code': 4, 'backurl': returnbackurl} else: returnbackurl = request.session.get("returnbackurl") if not returnbackurl or returnbackurl == r'/' or returnbackurl == r'/login/': returnbackurl = r'/home/' request.session['username'] = username request.session['displayname'] = loginvalue['message']['displayname'] request.session['returnbackurl'] = '' # result = {'isSuccess': True, "message": '验证成功', 'backurl': returnbackurl} result = {'code': 4, 'backurl': returnbackurl} if result['code'] != 4: gotken = seargooled(username.lower()) if gotken: gotken_ip = gotken[0].get('ip', '') gotken_agent = gotken[0].get('agent', '') if gotken_ip == ip and gotken_agent == agent: returnbackurl = request.session.get("returnbackurl") if not returnbackurl or returnbackurl == r'/' or returnbackurl == r'/login/': returnbackurl = r'/home/' request.session['username'] = username request.session['displayname'] = loginvalue['message']['name'] request.session['returnbackurl'] = '' # result = {'isSuccess': True, "message": '验证成功', 'backurl': returnbackurl} result = {'code': 4, 'backurl': returnbackurl} else: result = {'code': 0, "message": {'username': loginvalue['message']['sAMAccountName'], 'displayname': loginvalue['message']['displayName']}} else: result = {'code': 1, "message": '未绑定'} else: result = {'code': 2, "message": loginvalue['message']} else: result = {'code': 2, "message": '请填写密码'} else: result = {'code': 2, "message": '请填写用户名'} except Exception as e: print(e) result = {'code': 2, "message": '出现异常'} response = HttpResponse() response['Content-Type'] = "text/javascript" response.write(json.dumps(result)) return response