def AuthenticateUser(acc: LoginReq):
    try:
        account = AccountRep.Authenticate(acc)
        if (account['role']['role_id'] == 3):  # customer
            user = (models.Customers.query.filter(
                models.Customers.account_id == account['account_id'],
                models.Customers.account_id != None).first().serialize())

        if (account['role']['role_id'] == 1
                or account['role']['role_id'] == 2):  # admin, manager
            user = (models.Employees.query.filter(
                models.Employees.account_id == account['account_id'],
                models.Employees.account_id != None).first().serialize())
        secect_key = app.config['SECRET_KEY']
        payload = {
            'account_id': account['account_id'],
            'iat': datetime.utcnow(),
            'exp': datetime.utcnow() + timedelta(minutes=300000)
        }
        access_token = jwt.encode(payload, secect_key)
        result = {
            'access_token': access_token,
            'account': account,
            'user_info': user,
        }
        return result
    except ErrorRsp as e:
        raise e
def AuthenticateUser(acc: LoginReq):
    try:
        account = AccountRep.Authenticate(acc)
        if (account['role']['role_id'] == 3):  # customer
            search_customer_req = SearchCustomersReq(
                {'account_id': account['account_id']})
            user = CustomerRep.SearchCustomers(search_customer_req)

        if (account['role']['role_id'] == 1
                or account['role']['role_id'] == 2):  # admin, manager
            search_employee_req = SearchEmployeesReq(
                {'account_id': account['account_id']})
            user = EmployeeRep.SearchEmployees(search_employee_req)

        secect_key = app.config['SECRET_KEY']
        payload = {
            'account_id': account['account_id'],
            'iat': datetime.utcnow(),
            'exp': datetime.utcnow() + timedelta(minutes=30)
        }
        access_token = jwt.encode(payload, secect_key)
        result = {
            'access_token': access_token,
            'account': account,
            'user_info': user[0] if len(user) > 0 else None
        }
        return result
    except ErrorRsp as e:
        raise e