#include #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 = std::dynamic_pointer_cast(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 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..."); } }