def logout(): try: c = getCookie() decryptData = str(decrypt(key, iv, bytes(c, encoding='utf-8'))) decryptData = re.findall(r"b'(.+)'", decryptData)[0] resp = User.logout(decryptData) if resp is not None: return resp else: return MSG.Failed() except Exception as e: logger.error("%s {}".format(e) % bad) return MSG.Failed()
def login(): try: # username = request.form['username'] # password = request.form['password'] username = request.args.get("username") password = request.args.get("password") if len(username.replace(" ","")) == 0 \ or len(password.replace(" ","")) == 0: return MSG.Failed(msg="用户名或密码不能为空") resp = User.login(username, password) if resp is not None: return resp else: return MSG.Failed() except Exception as e: logger.error("%s {}".format(e) % bad) return MSG.Failed()
def setCookie(username): try: encryptData = encrypt(bytes(username, encoding='utf-8'), key, iv) resp = make_response(MSG.Success(msg="success")) encryptData = str(encryptData, encoding='utf-8') resp.set_cookie('id', encryptData, max_age=3600) return resp except TypeError: logger.error("%s encrypt string argument without an encoding." % bad) except Exception as e: logger.error("%s {}".format(e) % bad)
def wrapped_function(username): if username not in session: return MSG.Failed() else: return f()
def decorated(*args): for arg in args: if len(arg.replace(" ", "")) == 0: return MSG.Failed(msg="参数不能为空") return f(*args)
def decorated(username, *args): if type(len(User.query.filter_by(username=username).all())) == 0: return MSG.Failed(msg="用户不存在") else: return f(username, *args)
def delCookie(): resp = make_response(MSG.Success()) resp.delete_cookie('id') return resp