def userLogin(request): reponse = dict() reponse.update(status = 0, msg = '用户名或密码错误,请重新录入!') if request.method == 'POST': form = LoginForm(request.POST) if form.is_valid(): userId = form.cleaned_data['userId'] passwd = form.cleaned_data['passwd'] if authService(userId, passwd): authCode = tools.getAuthCode(userId) tools.addSession(userId, authCode) reponse.update(status = 1, userLoginId= userId, userLoginAuth=authCode, msg='登录成功!') return HttpResponse(json.dumps(reponse), mimetype='application/json')
def checkUserAuth(request): formPost = UserAuthForm() formCookie = UserAuthForm() if request.POST: formPost = UserAuthForm(request.POST) if request.COOKIES: formCookie = UserAuthForm(request.COOKIES) if formCookie.is_valid(): userLoginId = formCookie.cleaned_data['userLoginId'] userLoginAuth = formCookie.cleaned_data['userLoginAuth'] if tools.getSession(userLoginId) == userLoginAuth: tools.addSession(userLoginId, userLoginAuth) return True; if formPost.is_valid(): userLoginId = formPost.cleaned_data['userLoginId'] userLoginAuth = formPost.cleaned_data['userLoginAuth'] if tools.getSession(userLoginId) == userLoginAuth: tools.addSession(userLoginId, userLoginAuth) return True; return False;