def login(): user = User() username = request.form.get('username').strip() password = request.form.get('password').strip() vcode = request.form.get('logincode').strip().lower() print(vcode, session.get('vcode')) if vcode != session.get('vcode') or vcode == 0000: return 'vcode-error' else: password = hashlib.md5(password.encode()).hexdigest() result = user.find_by_username(username) if len(result) == 1 and result[0].password == password: session['islogin'] = '******' session['userid'] = result[0].userid session['username'] = username session['nickname'] = result[0].nickname session['role'] = result[0].role # 更新积分表 Credit().insert_detail(type='正常登录', target='0', credit=1) user.update_credit(1) # 写入cookie response = make_response('login-pass') response.set_cookie('username', username, max_age=1 * 3600) response.set_cookie('password', password, max_age=1 * 3600) return response else: return 'login-fail'
def login(): user = User() username = request.form.get('username').strip() password = request.form.get('password').strip() vcode = request.form.get('vcode').lower().strip() # 校验图像验证码是否正确,0000用来做测试 if vcode != session.get('vcode') and vcode != '0000': return 'vcode-error' else: # 实现登录功能 # 密码加密 password = hashlib.md5(password.encode()).hexdigest() result = user.find_by_username(username) if len(result) == 1 and result[0].password == password: session['islogin'] = '******' session['userid'] = result[0].userid session['username'] = username session['nickname'] = result[0].nickname session['role'] = result[0].role # 更新积分详情表 Credit().insert_detail(type='正常登录', target='0', credit=1) user.update_credit(1) # 将Cookie写入浏览器,持久化存储 response = make_response('login-pass') response.set_cookie('username', username, max_age=30 * 24 * 3600) response.set_cookie('password', password, max_age=30 * 24 * 3600) return response else: return 'login-fail'