def post(self): args = parse_base.parse_args() password = args.get("password") action = args.get("action").lower() if action == USER_ACTION_REGISTER: args_register = parse_register.parse_args() phone = args_register.get("phone") username = args_register.get("username") movie_user = MovieUser() movie_user.username = username movie_user.password = password movie_user.phone = phone if not movie_user.save(): abort(400, msg="create fail") data = { "status": HTTP_CREATE_OK, "msg": "用户创建成功", "data": movie_user } return marshal(data, single_movie_user_fields) elif action == USER_ACTION_LOGIN: args_login = parse_login.parse_args() username = args_login.get("username") phone = args_login.get("phone") user = get_user(username) or get_user(phone) if not user: abort(400, msg="用户不存在") if not user.check_password(password): abort(401, msg="密码错误") if user.is_delete: abort(401, msg="用户不存在") token = uuid.uuid4().hex cache.set(token, user.id, timeout=60 * 60 * 24 * 7) data = {"msg": "login success", "status": HTTP_OK, "token": token} return data else: abort(400, msg="其提供正确的参数")
def post(self): args = parse.parse_args() token = args.get("token") user_id = cache.get(token) user = get_user(user_id) if not user: abort(400, message="plz input effective token ") return {"msg": "success"}
def post(self): args = parse_base.parse_args() password = args.get("password") action = args.get("action") if action == USER_ACTION_REGISTER: register = parse_register.parse_args() username = register.get("username") phone = register.get("phone") movie_user = MovieUserModel() movie_user.username = username movie_user.password = password movie_user.phone = phone print("--->", username, password, phone) if not movie_user.save(): abort(400, message="create fail") data = { "status": HTTP_CREATE_OK, "msg": "success", "data": movie_user } return marshal(data, single_movie_user_fields) elif action == USER_ACTION_LOGIN: login = parse_login.parse_args() username = login.get("username") phone = login.get("phone") print("username--phone", login, username, phone) user = get_user(username) or get_user(phone) if not user: abort(400, message="the user isn't exists!") if not user.check_password(password): abort(400, message="password is error!") if user.is_delete: abort(400, msg="the user isn't exists!") token = uuid.uuid4().hex cache.set(token, user.id, timeout=60 * 60 * 24 * 7) data = {"msg": "login success", "status": HTTP_OK, "token": token} return data else: abort(400, message="plz input correct args")
def post(self): args = parse.parse_args() token = args.get("token") user_id = cache.get(token) user = get_user(user_id) if not user: abort(401, msg="请登录") return {"msg": "post order ok"}
def _verify(): token = request.args.get("token") if not token: abort(401, msg="not login") user_id = cache.get(token) if not user_id: abort(401, msg="user not avaliable") user = get_user(user_id) if not user: abort(401, msg="user not avaliable") g.user = user g.auth = token
def _verify(): token = request.args.get("token") if not token: abort(401, msg="not login") if not token.startswith(MOVIE_USER): abort(403, msg="no access") user_id = cache.get(token) if not user_id: abort(401, msg="user not avaliable") user = get_user(user_id) if not user: abort(401, msg="user not avaliable") g.user = user g.auth = token