Пример #1
0
    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)
Пример #2
0
 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)
Пример #3
0
def list():
    users, error = Users.list()
    if (error):
        return Response.send({}, "", error)
    return Response.send(users, "Successfully fetched")
Пример #4
0
def delete(id):
    user = Users.delete(id)
    return Response.send(user, "Successfully deleted", 202)
Пример #5
0
def update(id):
    user = Users.update(id, request.json)
    return Response.send(user, "Successfully updated")
Пример #6
0
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)
Пример #7
0
def verify(user={}, token=""):
    return Response.send({
        "user": user,
        "token": token
    }, "Successfully Verified")
Пример #8
0
def details(id):
    user, error = Users.details(id)
    if (error):
        return Response.send({}, "", error)
    return Response.send(user, "Successfully fetched")