def login(request): print("views.....login") if request.method == "GET": return render(request, 'login.html') else: print("views.....loginxxxxxxxxxxxxxxxxx") u = request.POST.get('username') p = request.POST.get('password') obj = models.UserInfo.objects.filter(user__username=u, user__password=p).first() print(u, p) print(obj) obj2 = models.UserInfo.objects.filter(user__username="******", user__password="******").first() print(obj2) if obj: print("验证正确") request.session['user_info'] = {'username': u, 'nickname': obj.nickname, 'nid': obj.id} # 得到的值 # 角色 权限 # request.session[settings.RBAC_PERMISSION_SESSION_KEY] = user_permission_dict # request.session[settings.RBAC_MENU_PERMISSION_SESSION_KEY] = { # 菜单 # settings.RBAC_MENU_KEY: menu_list, # settings.RBAC_MENU_PERMISSION_KEY: menu_permission_list # } initial_permission(request, obj.user_id) return redirect('/index.html') else: return render(request, 'login.html')
def login(request): if request.method == "GET": return render(request,'login.html') else: u = request.POST.get('username') p = request.POST.get('password') obj = models.UserInfo.objects.filter(user__username=u,user__password=p).first() if obj: request.session['user_info'] = {'username':u,'nickname':obj.nickname,'nid':obj.id} initial_permission(request,obj.user_id) return redirect('/index.html') else: return render(request,'login.html')
def login(request): if request.method == "GET": login_user = LoginForm(request) return render(request,"Login.html",{"login_user":login_user}) else: login_user = LoginForm(request,request.POST) if login_user.is_valid(): # obj = models.UserInfo.objects.filter(user__username=login_user.cleaned_data["username"], user__password=login_user.cleaned_data["password"]).first() obj = Rbacmodels.User.objects.get(username=login_user.cleaned_data["username"],password=login_user.cleaned_data["password"]) request.session["user_info"] = {"username":login_user.cleaned_data.get("username")} # initial_permission(request, obj.user_id) initial_permission(request, obj.id) return redirect("/index.html") else: return render(request, "Login.html", {"login_user": login_user})
def login(request): if request.method == 'GET': return render(request, 'login.html') else: u = request.POST.get('username') p = request.POST.get('password') info = models.UserInfo.objects.filter(user__password=p, user__username=u).first() if info: request.session['userinfo'] = { 'username': u, 'password': p, 'nid': info.user_id } initial_permission(request, info.id) return render(request, 'index.html', {'info': info}) else: return redirect('/login.html')
def login(request): if request.method == "GET": return render(request, 'login.html') else: u = request.POST.get('username') p = request.POST.get('password') obj = models.UserInfo.objects.filter(user__username=u, user__password=p).first() if obj: request.session['user_info'] = { "username": u, "nickname": obj.nickname, "nid": obj.id } #获取当前用户权限 #获取当前用户菜单 #去配置文件中获取key,写入session中 from rbac.service import initial_permission initial_permission(request, obj.user_id) return redirect('/index.html') else: return render(request, 'login.html')
def login(request, *args, **kwargs): if request.method == "GET": form = LoginForm(request) return render(request, 'login.html', {"form": form}) else: form = LoginForm(request, request.POST) if form.is_valid(): username = request.POST.get('userinfo_name') password = request.POST.get('userinfo_password') user = rbac_models.User.objects.filter(username=username, password=password).first() print(user) if user: initial_permission(request, user) return render(request, "backend_layout_1.html", {"user": user}) else: return render(request, 'login.html', { "form": form, "obj": "账号或密码错误" }) else: print(form.errors) return render(request, 'login.html', {"form": form})
def login(request): """ 用户登陆 :param request: :return: """ if request.method == 'GET': return render(request, 'login.html') else: username = request.POST.get('username') password = request.POST.get('password') obj = models.UserInfo.objects.filter(user__username=username, user__password=password).first() if obj: # 登陆成功后,将用户信息保存到session当中 request.session['user_info'] = { 'username': username, 'nickname': obj.nickname, 'nid': obj.id } initial_permission(request, obj.user_id) # 初始化用户对应的权限 return redirect('/index.html') else: return render(request, 'login.html')
def acc_login(request): error = "" if request.method == "POST": ret = {"status": 0, "msg": ""} next = request.META.get('HTTP_REFERER') print(next) username = request.POST.get("username") password = request.POST.get("password") 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, '') print(request.session.__dict__, 555) status = request.session[gt.GT_STATUS_SESSION_KEY] user_id = request.session["user_id"] user_list = [] try: conn = get_redis_connection("default") user = UserProfile.objects.filter(user__username=username).first() if not user: return render(request, 'login.html', {'msg': '未查询到此账号!'}) if int(user.login_state): print(type(bool(user.login_state)), bool(user.login_state), user.login_state) return render(request, 'login.html', {'msg': '账号已经冻结!'}) if (datetime.datetime.now() - user.login_lock_date).total_seconds() < 600: return render(request, 'login.html', {'msg': '账号锁定十分钟内不能登陆!'}) if user.pass_err_count >= 3: user.login_lock_date = datetime.datetime.now() user.save() return render(request, 'login.html', {'msg': '密码输入超过5次,用户锁定十分钟'}) obj = UserProfile.objects.filter(user__username=username, user__password=password).first() if status: result = gt.success_validate(challenge, validate, seccode, user_id) else: result = gt.failback_validate(challenge, validate, seccode) print(555555555, result) if result: if obj: pduser = UserProfile.objects.values("session").filter( user__username=username)[0] print(111, type(pduser["session"])) # 如果session为“None”则说明还没有登录过的新用户 if pduser["session"] == None: request.session["user"] = username request.session['user_info'] = { 'username': username, 'nickname': obj.nickname, 'nid': obj.user.id, } initial_permission(request, obj.user.id) session_id = request.session.__dict__[ "_SessionBase__session_key"] print(444444444, session_id) return redirect( request.GET.get("next") or "/index.html", locals()) else: print(request.session.__dict__) print(pduser) request.session.delete(pduser["session"]) request.session["user"] = username request.session['user_info'] = { 'username': username, 'nickname': obj.nickname, 'nid': obj.user.id, } session_id = request.session.__dict__[ "_SessionBase__session_key"] # print(session_id) # UserProfile.objects.filter(user__username=username).update(session=session_id) initial_permission(request, obj.user.id) return redirect( request.GET.get("next") or "/index.html", locals()) else: error = "Wrong username or password !" user.pass_err_count += 1 user.save() return render(request, "login.html", {"error": error}) else: ret["status"] = 1 ret["msg"] = "验证码错误" return JsonResponse(ret) except Exception as e: print(e) return render(request, "login.html", {"msg": e}) return render(request, "login.html", {"error": error})