def login(request): if request.method == 'GET': return render_to_response('nmaptoolview/login.html', {'data': ''}) else: username = request.POST.get('username', '') password = request.POST.get('password', '') # result = Ture/False(if len(col) > 0); result, username, role, power = usercontrol.validuser( username, password) ctx = {} ctx['username'] = username ctx['password'] = password ctx['result'] = result ctx['role'] = role ctx['power'] = power # return render(request, 'nmaptoolview/post.html', ctx) # return render(request, 'nmaptoolview/taskmain.html', {'data': '用户名和密码正确', 'username':username}) if result: # 在base/navbar.html模板中使用username参数 response = render(request, 'nmaptoolview/taskmain.html', { 'data': '用户名和密码正确', 'username': username }) # 将username写入浏览器cookie,失效时间为3600 loginuser = User(result, username, password, role, power) webtool.setCookies(response, loginuser, 3600) return response else: return render(request, 'nmaptoolview/login.html', {'data': '用户名和密码错误'})
def login(request): if request.method=='GET': return render_to_response('nmaptoolview/login.html', {'data':''}) else: username=request.POST.get('username','') password=request.POST.get('password','') result,username,role,power= usercontrol.validuser(username,password) if result: response = render_to_response('nmaptoolview/taskmain.html', {'data':'用户名和密码成功','username':username}) loginuser=User(result,username,password,role,power) #将username写入浏览器cookie,失效时间为3600 webtool.setCookies(response,loginuser,3600) return response else: return render_to_response('nmaptoolview/login.html', {'data':'用户名或密码错误'})
def login(request): if request.method=='GET': return render_to_response('nmaptoolview/login.html', {'data':''}) else: username=request.POST.get('username','') password=request.POST.get('password','') result,username,role,power= usercontrol.validuser(username,password) if result: response = render_to_response('nmaptoolview/mainpage.html', {'data':'用户名和密码成功','username':username}) loginuser=User(result,username,password,role,power) #将username写入浏览器cookie,失效时间为3600 webtool.setCookies(response,loginuser,3600) return response else: return render_to_response('nmaptoolview/login.html', {'data':'用户名或密码错误'})