194 lines
4.6 KiB
C++
194 lines
4.6 KiB
C++
/*
|
||
* File: UserInterface.cpp
|
||
* Description: Implements the UserInterface class functions including menu loop, login handling, and routing to appropriate role-based menus.
|
||
* Author: Trenser
|
||
* Created: 02-Apr-2026
|
||
*/
|
||
|
||
#include <iostream>
|
||
#include <utility>
|
||
#include <memory>
|
||
#include <stdexcept>
|
||
#include "UserInterface.h"
|
||
#include "AdminMenu.h"
|
||
#include "EmployeeMenu.h"
|
||
#include "FinanceExecutiveMenu.h"
|
||
#include "HRManagerMenu.h"
|
||
#include "ITExecutiveMenu.h"
|
||
#include "TalentExecutiveMenu.h"
|
||
#include "TeamExecutiveMenu.h"
|
||
#include "TeamLeadMenu.h"
|
||
#include "ZenvyController.h"
|
||
#include "InputHelper.h"
|
||
#include "OutputHelper.h"
|
||
#include "Validator.h"
|
||
|
||
/*
|
||
* Function: UserInterface::run
|
||
* Description: Starts the user interface loop and displays login/exit options until exit is selected
|
||
* Parameters:
|
||
* None
|
||
* Returns:
|
||
* None
|
||
*/
|
||
void UserInterface::run()
|
||
{
|
||
bool isMenuActive = true;
|
||
while (isMenuActive)
|
||
{
|
||
try
|
||
{
|
||
int choice;
|
||
util::clear();
|
||
std::cout << "Zenvy - HR Management System\n1. Login\n2. Exit\nEnter your Choice: ";
|
||
util::read(choice);
|
||
if (!handleOperation(choice))
|
||
{
|
||
isMenuActive = false;
|
||
}
|
||
}
|
||
catch (const std::exception& e)
|
||
{
|
||
std::cout << "Exception: " << e.what() << std::endl;
|
||
util::pressEnter();
|
||
}
|
||
}
|
||
}
|
||
|
||
/*
|
||
* Function: UserInterface::handleOperation
|
||
* Description: Handles the user’s menu choice and executes the corresponding action
|
||
* Parameters:
|
||
* choice - integer representing the selected menu option
|
||
* Returns:
|
||
* true - if the interface should remain active
|
||
* false - if the user chooses to exit
|
||
*/
|
||
bool UserInterface::handleOperation(int choice)
|
||
{
|
||
switch (choice)
|
||
{
|
||
case 1:
|
||
login();
|
||
break;
|
||
case 2:
|
||
std::cout << "Exiting..." << std::endl;
|
||
return false;
|
||
default:
|
||
std::cout << "Enter a valid choice!" << std::endl;
|
||
util::pressEnter();
|
||
}
|
||
return true;
|
||
}
|
||
|
||
/*
|
||
* Function: UserInterface::login
|
||
* Description: Authenticates the user by email and password, validates login status, and routes to the appropriate menu
|
||
* Parameters:
|
||
* None
|
||
* Returns:
|
||
* None
|
||
*/
|
||
void UserInterface::login()
|
||
{
|
||
std::string email, password;
|
||
util::clear();
|
||
std::cout << "Enter email: ";
|
||
util::read(email);
|
||
std::cout << "Enter password: ";
|
||
util::read(password);
|
||
AuthenticationDTO authenticationContext = m_controller->login(email, password);
|
||
Enums::LoginStatus loginStatus = std::get<0>(authenticationContext);
|
||
Enums::EmployeeType employeeType = std::get<1>(authenticationContext);
|
||
Enums::EmployeeDesignation employeeDesignation = std::get<2>(authenticationContext);
|
||
if (loginStatus == Enums::LoginStatus::USER_NOT_FOUND)
|
||
{
|
||
std::cout << "Error: User Not Found! Try Again\n";
|
||
util::pressEnter();
|
||
return;
|
||
}
|
||
if (loginStatus == Enums::LoginStatus::INVALID_PASSWORD)
|
||
{
|
||
std::cout << "Error: Invalid Password! Try Again\n";
|
||
util::pressEnter();
|
||
return;
|
||
}
|
||
if (loginStatus == Enums::LoginStatus::FIRST_LOGIN)
|
||
{
|
||
util::clear();
|
||
std::cout << "Warning: You're using the default password!\n"
|
||
<< "Please change it.\n";
|
||
std::cout << "Enter new password: \n";
|
||
util::read(password);
|
||
if (util::isPasswordValid(password))
|
||
{
|
||
m_controller->changePassword(password);
|
||
}
|
||
else
|
||
{
|
||
std::cout << "\nInvalid Password";
|
||
util::pressEnter();
|
||
return;
|
||
}
|
||
}
|
||
util::clear();
|
||
// Route to appropriate menu
|
||
switch (employeeType)
|
||
{
|
||
case Enums::EmployeeType::ADMIN:
|
||
{
|
||
AdminMenu menu;
|
||
menu.run();
|
||
break;
|
||
}
|
||
case Enums::EmployeeType::HR:
|
||
{
|
||
HRManagerMenu menu;
|
||
menu.run();
|
||
break;
|
||
}
|
||
case Enums::EmployeeType::FINANCE:
|
||
{
|
||
FinanceExecutiveMenu menu;
|
||
menu.run();
|
||
break;
|
||
}
|
||
case Enums::EmployeeType::IT:
|
||
{
|
||
ITExecutiveMenu menu;
|
||
menu.run();
|
||
break;
|
||
}
|
||
case Enums::EmployeeType::TEAM:
|
||
{
|
||
TeamExecutiveMenu menu;
|
||
menu.run();
|
||
break;
|
||
}
|
||
case Enums::EmployeeType::TAG:
|
||
{
|
||
TalentExecutiveMenu menu;
|
||
menu.run();
|
||
break;
|
||
}
|
||
case Enums::EmployeeType::GENERAL:
|
||
{
|
||
if (employeeDesignation == Enums::EmployeeDesignation::TEAM_LEAD)
|
||
{
|
||
TeamLeadMenu menu;
|
||
menu.run();
|
||
}
|
||
else
|
||
{
|
||
EmployeeMenu menu;
|
||
menu.run();
|
||
}
|
||
break;
|
||
}
|
||
default:
|
||
throw std::runtime_error("Error: Unsupported employee type!\n");
|
||
util::pressEnter();
|
||
break;
|
||
}
|
||
m_controller->logout();
|
||
} |