f85614ecc5
<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>
70 lines
2.0 KiB
C++
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...");
|
|
}
|
|
} |