def post(self): data = _user_parser.parse_args() if UserModel.find_by_username(data["username"]): return {"message": USER_ALREADY_EXISTS}, 400 user = UserModel(**data) user.save_to_db() return {"message": CREATED_SUCCESSFULLY}, 201
def post(cls): user = user_schema.load(request.get_json()) if UserModel.find_by_username(user["username"]): return {"message": USER_ALREADY_EXISTS}, 400 user.save_to_db() return {"message": CREATED_SUCCESSFULLY}, 201
def post(cls): user_data = user_schema.load(request.get_json()) user = UserModel.find_by_username(user_data["username"]) # this is what the `authenticate()` function did in security.py if user and safe_str_cmp(user.password, user_data["password"]): # identity= is what the identity() function did in security.py—now stored in the JWT access_token = create_access_token(identity=user.id, fresh=True) refresh_token = create_refresh_token(user.id) return {"access_token": access_token, "refresh_token": refresh_token}, 200 return {"message": INVALID_CREDENTIALS}, 401
def post(self): data = _user_parser.parse_args() user = UserModel.find_by_username(data["username"]) # this is what the `authenticate()` function did in security.py if user and safe_str_cmp(user.password, data["password"]): # identity= is what the identity() function did in security.py—now stored in the JWT access_token = create_access_token(identity=user.id, fresh=True) refresh_token = create_refresh_token(user.id) return { "access_token": access_token, "refresh_token": refresh_token }, 200 return {"message": INVALID_CREDENTIALS}, 401
def delete(cls, user_id: int): user = UserModel.find_by_id(user_id) if not user: return {"message": USER_NOT_FOUND}, 404 user.delete_from_db() return {"message": USER_DELETED}, 200
def get(cls, user_id: int): user = UserModel.find_by_id(user_id) if not user: return {"message": USER_NOT_FOUND}, 404 return user.json(), 200