def post(self, *args, **kwargs): print(self.request.arguments, 'in LoginHandler') form = LoinForm(self.request.arguments) dic = {"status": "error", "reason": "Incorrect username or password"} print('form.validate():', form.validate()) if form.validate(): # print(form.email.data) password = yield tornado.gen.Task(client.hget, 'userinfo:%s' % form.email.data, 'password') if password and password == form.password.data: self.set_secure_cookie('username', form.email.data) # self.redirect(self.get_argument('next', '/')) dic["status"] = "success" dic["reason"] = "Matched, please wait." print("I'm sorry three") # return form_errors = form.email.errors if form.email.errors else form.password.errors if form_errors: dic['status'] = "invalid" dic['reason'] = form_errors self.write(dic)
def login_handler(): form = LoinForm(request.forms) dic = {"status": "error", "reason": u"用户名或密码错误"} if form.validate(): email = form.email.data.lower() password = form.password.data correct_pwd = red.hget('userinfo:%s' % email, 'password') if password and check_password(password, correct_pwd): s = request.environ.get('beaker.session') s['username'] = email s.save() red.hincrby('userinfo:%s' % email, 'visited_times', 1) dic["status"] = "success" dic["reason"] = "Matched, please wait." form_errors = (form.email.errors if form.email.errors else form.password.errors) if form_errors: dic['status'], dic['reason'] = "invalid", form_errors return dic