Example #1
0
def forgot_password(data, scenario):
    user_result = fetch_user_by_email(data['email'])
    if user_result is None:
        raise DBException(f'"{data["email"]}" is an invalid account.', -1)

    if scenario == 1:
        return '123456'

    if scenario == 2:
        if data['verification_code'] != '123456':
            raise DBException(
                f'"{data["verification_code"]}" is an invalid verification code.',
                -2)

        return ''

    if scenario == 3:
        execute_quad_sp(
            'MWH.UMA_WAREHOUSE_ADMIN_CONSOLE', 'PASSWORD RESET', {
                'VARCHAR_01': user_result['employee_email'],
                'VARCHAR_02': user_result['employee_password'],
                'VARCHAR_03': generate_password_hash(data['new_password'])
            })

        return user_result['id']
Example #2
0
def reset_user_password(email, existing_password, new_password):
    """
    Resets a user's password.
    :param email: User email
    :type email: str
    :param existing_password: Raw existing user password
    :type existing_password: str
    :param new_password: Raw new user password
    :type new_password: str
    """
    user_result = fetch_user_by_email(email)
    if user_result is None:
        raise DBException(f'"{email}" is an invalid account.', -1)

    if verify_password_hash(existing_password,
                            user_result['employee_password']) is False:
        raise DBException('The password is invalid.', -2)

    execute_quad_sp(
        'MWH.UMA_WAREHOUSE_ADMIN_CONSOLE', 'PASSWORD RESET', {
            'VARCHAR_01': email,
            'VARCHAR_02': user_result['employee_password'],
            'VARCHAR_03': generate_password_hash(new_password)
        })

    return user_result['id']
Example #3
0
def login_user(email, password):
    """
    Returns True if the login credentials are valid.
    :param email: User email
    :type email: str
    :param password: Raw user password
    :type password: str
    """
    user_result = fetch_user_by_email(email)
    if user_result is None:
        raise DBException(f'"{email}" is an invalid account.', -1)

    if verify_password_hash(password,
                            user_result['employee_password']) is False:
        raise DBException(f'"{email}" is an invalid account.', -2)

    execute_quad_sp('MWH.UMA_WAREHOUSE_ADMIN_CONSOLE', 'LOGIN', {
        'VARCHAR_01': email,
        'VARCHAR_02': user_result['employee_password']
    })

    return user_result['id']
Example #4
0
def fetch_user_by_id(id_):
    """
    Returns the user information.
    :param id_: User ID
    :type id_: int
    """
    result = execute_quad_sp('MWH.UMA_WAREHOUSE_ADMIN_CONSOLE_REPORTS',
                             'LIST_ADMIN_CONSOLE_USER_BY_ID',
                             {'VARCHAR_01': id_})

    if len(result) < 1:
        return None

    return result[0]
Example #5
0
def fetch_user_by_email(email):
    """
    Returns the user information.
    :param email: User email
    :type email: str
    """
    result = execute_quad_sp('MWH.UMA_WAREHOUSE_ADMIN_CONSOLE_REPORTS',
                             'LIST_ADMIN_CONSOLE_USER_BY_EMAIL',
                             {'VARCHAR_01': email})

    if len(result) < 1:
        return None

    return result[0]
Example #6
0
def create(sp_name, sp_message, in_args):
    """
    Creates a controlling account.
    :param str sp_name: Stored Procedure name
    :param str sp_message: Stored Procedure message
    :param dict in_args: str
    :returns dict: The created controlling account
    """
    return execute_quad_sp(
        sp_name,
        sp_message,
        {
            'IN_PCtrlAcct_ID': in_args['p_ctrl_acct_id'],
            'IN_Code': in_args['code'],
            'IN_Name': in_args['name'],
            'IN_Balance': in_args['balance'],
            'IN_rUnit_ID': in_args['ctrl_acct_units']
        }
    )