Files
Training-Team2-Zenvy-Jan26/Trenser.Zenvy/Trenser.Zenvy/services/AuthenticationManagementService.cpp
T
Princy Jerin f85614ecc5 Implement Deactive Employee functionality
<UserStory>
EMP002 : Deactivate Employee
</UserStory>

<Changes>
- Added deactivateEmployee logic to set employee status to INACTIVE
- Enabled Deactivate Employee option in AdminMenu
- Implemented listing of active employees for selection
- Connected UI flow for employee deactivation
- Fix minor syntax issues
</Changes>

<Review>
Smitha Mohan
</Review>
2026-04-08 11:36:50 +05:30

70 lines
2.0 KiB
C++

#include <stdexcept>
#include "AuthenticationManagementService.h"
#include "ApplicationConfig.h"
AuthenticationDTO AuthenticationManagementService::login(const std::string& email, const std::string& password)
{
employeeMap& employees = m_dataStore.getEmployees();
Enums::LoginStatus loginStatus = Enums::LoginStatus::USER_NOT_FOUND;
Enums::EmployeeType employeeType = Enums::EmployeeType::INVALID;
Enums::EmployeeDesignation employeeDesignation = Enums::EmployeeDesignation::INVALID;
for (const auto& employee : employees)
{
if (employee.second->getEmployeeEmail() == email)
{
if (employee.second->getEmployeePassword() == password)
{
if (password == Config::Authentication::DEFAULT_PASSWORD)
{
loginStatus = Enums::LoginStatus::FIRST_LOGIN;
}
else
{
loginStatus = Enums::LoginStatus::SUCCESS;
}
employeeType = employee.second->getEmployeeType();
if (employeeType == Enums::EmployeeType::GENERAL)
{
std::shared_ptr<GeneralEmployee> generalEmployee = std::dynamic_pointer_cast<GeneralEmployee>(employee.second);
if (generalEmployee)
{
employeeDesignation = generalEmployee->getDesignation();
}
else
{
throw std::runtime_error("Invalid Employee Type");
}
}
m_dataStore.setAuthenticatedEmployee(employee.second);
}
else
{
loginStatus = Enums::LoginStatus::INVALID_PASSWORD;
}
break;
}
}
return std::make_tuple(loginStatus, employeeType, employeeDesignation);
}
void AuthenticationManagementService::changePassword(const std::string& password)
{
std::shared_ptr<Employee> authenticatedUser = m_dataStore.getAuthenticatedEmployee();
if (authenticatedUser)
{
authenticatedUser->setEmployeePassword(password);
}
else
{
throw std::runtime_error("User not found");
}
}
void AuthenticationManagementService::logout() {
if (m_dataStore.getAuthenticatedEmployee()) {
m_dataStore.getAuthenticatedEmployee() = nullptr;
}
else {
throw std::runtime_error("No user currently logged In...");
}
}