Exemple #1
0
def fetch_user_api_key(id, password):
    """
    Obtains the user's api key

    Parameters
    ----------
    id : integer
        The user's id
    password : string
        The user's password

    Returns
    -------
    api_key : string
        Returns the user's api key. Return's None if there is no password found 
    """
    if id is not None and password is not None:
        db_pass = users_dao.select_users('password', [id], None, None, None,
                                         None, None)

        if len(db_pass) == 0:
            return None

        if password_manager.check_password(password, db_pass[0][0]):
            api_key = users_dao.select_users('api_key', [id], None, None, None,
                                             None, None)
            return api_key[0][0]

    return None
Exemple #2
0
def fetch_shareable_user_ids(sharing_id, share_ids):
    """
    Fetch the valid user ids to share a flight with
    The sharing user, disabled users and non-existent users will be filtered out.

    Parameters
    ----------
    sharing_id : integer
        The user id that is sharing the flight
    share_ids : list[int]
        The user ids that the flight will be shared with

    Returns
    -------
    List of valid ids to share the flight with
    """
    sharable_ids = []
    potential_sharable_users = users_rs_to_object_list(
        users_dao.select_users('*', share_ids, None, None, None, None, None))
    for user in potential_sharable_users:
        if not (user.role == roles.Disabled
                or str(user.id) == str(sharing_id)):
            sharable_ids.append(user.id)

    return sharable_ids
Exemple #3
0
def generate_user_api_key(id, password):
    """
    Generates an api key for a user

    Parameters
    ----------
    id : integer
        The user's id
    password : string
        The user's password

    """
    if id is not None and password is not None:
        db_pass = users_dao.select_users('password', [id], None, None, None,
                                         None, None)

        if len(db_pass) == 0:
            return None

        if password_manager.check_password(password, db_pass[0][0]):
            api_key = ''.join(
                random.choices(string.ascii_uppercase +
                               string.ascii_lowercase + string.digits,
                               k=20))

            users_dao.update_user_api_key(id, api_key)
            return api_key
    return None
Exemple #4
0
def verify_api_key(api_key):
    """
    Verifies the user's api key to make sure the user is valid

    Parameters
    ----------
    api_key : string
        The passed api_key that's to be verified

    Returns
    -------
    True if account was successfully verified. False if the account isn't verified    
    """
    if api_key is None or api_key == '':
        return False

    # web interface api key
    if api_key == 'vsRV7QBUP3EQGaD4wPbMjzUC2':
        return True

    user_roles = users_dao.select_users('role', None, None, None, None, None,
                                        api_key)[0]
    for role in user_roles:
        user_proper_role = roles(int(role))
        if user_proper_role == roles.Admin or user_proper_role == roles.Basic:
            return True
    return False
Exemple #5
0
def fetch_user_role(id):
    """
    Fetches users role based on the passed id

    Parameters
    ----------
    id : integer
        The id of the user to be found

    Returns
    -------
    user : user object 
        Returns the users with the matching id
    """
    if id is not None:
        return users_dao.select_users('role', [id], None, None, None, None,
                                      None)[0][0]
Exemple #6
0
def fetch_users(ids, email, password, role):
    """
    Fetch all users based on the passed values

    Parameters
    ----------
    ids : list[int]
        The ids of the users
    email : string
        The email of the users
    password : string
        The password of the users
    role : roles
        The role of the users

    Returns
    -------
    List of all users that have the passed parameters
    """
    return users_rs_to_object_list(
        users_dao.select_users('*', ids, email, password,
                               None if role is None else role.value, None,
                               None))
Exemple #7
0
def check_force_password_reset(user_id):
    if user_id is not None:
        return int(
            str(
                users_dao.select_users('force_reset', [user_id], None, None,
                                       None, None, None)[0][0]))