Beispiel #1
0
    def get_author_name(cls, user_id, token):
        if not cls.url:
            info, code = cls._mock_get_info(user_id)
            return info["display_name"]

        msg, code = Requester.auth_fetch('GET', cls.url + f'/users/{user_id}', cls.tkn_hdr(token), payload={})
        return msg["display_name"]
Beispiel #2
0
    def register_user(cls, fullname, email, phone, avatar, token, password=""):
        if not cls.url:
            return cls._mock_register(fullname, email, phone, avatar)

        payload = {'email': email, 'display_name': fullname,
                                    'phone_number': phone, 'image_location': avatar, 'password': password}

        return Requester.auth_fetch('POST', cls.url + '/users', cls.tkn_hdr(token), payload)
Beispiel #3
0
    def is_valid_token(cls, token):
        if not cls.url:
            return True

        msg, code = Requester.auth_fetch('POST', cls.url + '/sign-in', cls.tkn_hdr(token), payload={})

        if code == 200:
            return True

        if code == 400:
            return False
Beispiel #4
0
    def get_uuid_from_token(cls, token):
        if not cls.url:
            cls._mock_get_info(int(token))
            return int(token)
        
        msg, code = Requester.auth_fetch('GET', cls.url + '/users/id', cls.tkn_hdr(token), payload={})

        if code != 200:
            raise NotFoundError(f"User with token {token[:10]}... not found")

        return msg["uid"]
Beispiel #5
0
    def find_user(cls, token, name=None, email=None, phone=None, per_page=None, page=None):
        if not cls.url:
            return cls._mock_find(name, email, phone)

        query = "?"

        if name:
            query += f"name={name}"
        if email:
            query += f"&email={email}"
        if phone:
            query += f"&phone={phone}"
        if per_page:
            query += f"&per_page={per_page}"
        if page:
            query += f"&page={page}"

        msg, code = Requester.auth_fetch('GET', cls.url + '/users' + query, cls.tkn_hdr(token), payload={})
        return msg, code
Beispiel #6
0
    def modify_user(cls, user_id, args_dict):
        if not cls.url:
            return cls._mock_modify(user_id, args_dict)

        msg, code = Requester.auth_fetch('PUT', cls.url + '/users/' + str(user_id), cls.tkn_hdr(args_dict["x-access-token"]), args_dict)
        return msg, code
Beispiel #7
0
    def get_user_info(cls, user_id, token):
        if not cls.url:
            return cls._mock_get_info(user_id)

        return Requester.auth_fetch('GET', cls.url + f'/users/{user_id}', cls.tkn_hdr(token), payload={})
Beispiel #8
0
    def is_user_admin(cls, uuid):
        if not cls.url:
            return {"admin":False}, 200

        msg, code = Requester.auth_fetch('GET', cls.url + '/users/' + str(uuid) + '/admin', {}, payload={})
        return msg, code
Beispiel #9
0
    def is_admin(cls, token):
        if not cls.url:
            return {"admin":False}, 200

        msg, code = Requester.auth_fetch('GET', cls.url + '/users/admin', cls.tkn_hdr(token), payload={})
        return msg, code
Beispiel #10
0
    def send_new_password(cls, email, reset_code, password):
        payload = {"email":email, "code": reset_code, "password": password}

        msg, code = Requester.auth_fetch('POST', cls.url + '/change-password-with-reset-code', {}, payload=payload)
        return msg, code
Beispiel #11
0
 def send_reset_code(cls, email):
     msg, code = Requester.auth_fetch('POST', cls.url + '/reset-codes', {}, payload={"email":email})
     return msg, code
Beispiel #12
0
 def delete_user(cls, user_id, token):
     if not cls.url:
         cls.mock_db[user_id-1] = {"DELETED":True}
         return
     msg, code = Requester.auth_fetch('DELETE', cls.url + f'/users/{user_id}', cls.tkn_hdr(token), payload={})
     return msg, code