def get_user(current_user, search_id): user = UserModel.get_user_by_id(current_user) if user['role'] != "admin": return jsonify( {"message": "You are not authorised to view this function"}), 401 user = UserModel.get_user_by_id(search_id) return jsonify({'User': user}), 200
def update_user(user_id, **kwargs): user = UserModel.get_user_by_id(user_id) for key in user: if key in kwargs: user[key] = kwargs[key] UserModel.delete_user(user_id) UserModel.register_user(user) return UserModel.get_user_by_id(user_id)
def get(self, _id: str): user = UserModel.get_user_by_id(_id) if user: user_schema = UserSchema() result: dict = user_schema.dump(user) return result, 200 return {"msg": "User Not found"}, 404
def get(self, user_id: str): user = UserModel.get_user_by_id(user_id) if user: schema = OrderSchema(many=True) orders: List[OrderModel] = OrderModel.get_orders_by_user(user) result = schema.dump(orders) return result, 200 return {"msg": "No user found"}, 404
def get_users(current_user): user = UserModel.get_user_by_id(current_user) if user['role'] != "admin": return jsonify( {"message": "You are not authorised to view this function"}), 401 users_list = UserModel.get_users() return jsonify({ 'Users of ManagerStore': [make_public_user(user) for user in users_list] }), 200
def post(self): headers = request.headers requested_data = request.get_json() user = UserModel.get_user_by_id(headers["User"]) if user: sketch = SketchModel.get_sketch_by_id(requested_data["sketch"]) if sketch: OrderModel.create_order(user, sketch) return {"msg": "Order created"}, 201 return {"msg": "Sketch not found"}, 404 return {"msg": "User not found"}, 404
def decorated(*args, **kwargs): token = None if 'x-access-token' in request.headers: token = request.headers['x-access-token'] if not token: return jsonify({"message": "token is missing"}), 401 try: data = jwt.decode(token, app.config['SECRETE_KEY'], algorithms=['HS256']) current_user = data['sub'] user = UserModel.get_user_by_id(current_user) if user['role'] != "admin": current_user = data['sub'] if user['role'] != "store_attendant": current_user = data['sub'] except: return jsonify({"token": "token is missing"}), 401 return f(current_user, *args, **kwargs)
def decorated(*args, **kwargs): token = None if 'x-access-token' in request.headers: token = request.headers['x-access-token'] if not token: return jsonify({"message": "token is missing"}), 401 try: data = jwt.decode(token, app.config['SECRETE_KEY'], algorithms=['HS256']) print(data['sub'], 'data') current_user = data['sub'] user = UserModel.get_user_by_id(current_user) print(user, 'user') except: return jsonify( {"message": "Your session has expired, please login again"}), 401 return f(current_user, *args, **kwargs)