def validateToken(*args, **kwargs): token = request.headers.get("token") if token == None: return Response.send({}, "Missing Authentication token", 401) try: request.user = decode(token, secret) except: return Response.send({}, "Invalid Authentication token", 401) return func(*args, **kwargs)
def JWT(*args, **kwargs): email = request.json.get("email") password = request.json.get("password") user, error = Users.verify(email, password) if (error): return Response.send({}, "Invalid Credentials", error) token = encode({ "id": user[0], "email": user[1], "phone": user[2] }, secret).decode('UTF-8') print(type(token)) return func(user, token)
def list(): users, error = Users.list() if (error): return Response.send({}, "", error) return Response.send(users, "Successfully fetched")
def delete(id): user = Users.delete(id) return Response.send(user, "Successfully deleted", 202)
def update(id): user = Users.update(id, request.json) return Response.send(user, "Successfully updated")
def post(): userId, error = Users.create(request.json) if (userId): return Response.send({"userId": userId}, "Successfully created", 201) return Response.send({}, "Email already exists", error)
def verify(user={}, token=""): return Response.send({ "user": user, "token": token }, "Successfully Verified")
def details(id): user, error = Users.details(id) if (error): return Response.send({}, "", error) return Response.send(user, "Successfully fetched")