Exemplo n.º 1
0
def token_load(hashed=''):
    user_token = UserTokenModel.query \
        .filter(UserTokenModel.hashed == hashed)\
        .first()

    data = Serializer(APP_SECRET_KEY).loads(user_token.token)
    data['expired_at'] = user_token.expired_at.isoformat()
    data['permission'] = get_user(data['user_id']).permission

    return data
Exemplo n.º 2
0
def token_load(hashed=''):
    user_token = UserTokenModel.query \
        .filter(UserTokenModel.hashed == hashed)\
        .first()

    data = Serializer(APP_SECRET_KEY).loads(user_token.token)
    data['expired_at'] = user_token.expired_at.isoformat()
    data['permission'] = get_user(data['user_id']).permission

    return data
Exemplo n.º 3
0
def token_load(hashed=''):
    user_token = UserTokenModel.query \
        .filter(UserTokenModel.hashed == hashed)\
        .first()
    # print('youngtip >> ' + str(hashed))
    # print('youngtip >> ' + str(user_token.token))
    data = Serializer(APP_SECRET_KEY).loads(user_token.token)
    data['expired_at'] = user_token.expired_at.isoformat()
    data['permission'] = get_user(data['user_id']).permission
    data['token'] = user_token.hashed  # hashed token
    # print('youngtip token_load >> ' + str(data))
    return data
Exemplo n.º 4
0
    def get(self, prefix):
        try:
            if prefix == 'me':
                user_id = token_load_with_auth(request.headers['Authorization'])['user_id']
            else:
                user_id = int(prefix)

            if token_is_auth(request.headers['Authorization'], user_id):
                user = get_user(user_id)
                return serialize_user(user), status.HTTP_200_OK
            else:
                return "You don't have permission.", status.HTTP_401_UNAUTHORIZED
        except ValueError:
            return "Prefix can only be me or a number.", status.HTTP_400_BAD_REQUEST
Exemplo n.º 5
0
    def get(self, prefix):
        try:
            if prefix == 'me':
                user_id = token_load_with_auth(request.headers['Authorization'])['user_id']
            else:
                user_id = int(prefix)

            if token_is_auth(request.headers['Authorization'], user_id):
                user = get_user(user_id)

                return serialize_user(user), status.HTTP_200_OK
            else:
                return "You don't have permission.", status.HTTP_401_UNAUTHORIZED
        except ValueError:
            return "Prefix can only be me or a number.", status.HTTP_400_BAD_REQUEST