From c2fbfa2d03f65d6a3c04ad49069528ae90c9286b Mon Sep 17 00:00:00 2001 From: Ajmal Jalaludeen Date: Mon, 6 Apr 2026 12:05:22 +0530 Subject: [PATCH] Add changePassword method in controller and authenticated user accessor AUTH004 : Change Password - Added changePassword method in ZenvyController to move to AuthenticationManagementService - Declared changePassword in ZenvyController.h - Introduced getAuthenticatedUser() in DataStore for accessing authenticated employee - Updated DataStore.h with getAuthenticatedUser() method - Prepared AuthenticationManagementService.cpp for password change implementation Smitha Mohan --- .../Trenser.Zenvy/controllers/ZenvyController.cpp | 3 ++- .../Trenser.Zenvy/controllers/ZenvyController.h | 2 ++ .../Trenser.Zenvy/datastores/DataStore.cpp | 5 +++++ Trenser.Zenvy/Trenser.Zenvy/datastores/DataStore.h | 1 + .../services/AuthenticationManagementService.cpp | 13 +++++++++++++ .../services/AuthenticationManagementService.h | 3 ++- 6 files changed, 25 insertions(+), 2 deletions(-) diff --git a/Trenser.Zenvy/Trenser.Zenvy/controllers/ZenvyController.cpp b/Trenser.Zenvy/Trenser.Zenvy/controllers/ZenvyController.cpp index c1b4287..4efe6f2 100644 --- a/Trenser.Zenvy/Trenser.Zenvy/controllers/ZenvyController.cpp +++ b/Trenser.Zenvy/Trenser.Zenvy/controllers/ZenvyController.cpp @@ -10,6 +10,7 @@ void ZenvyController::logout() { } -void AuthenticationManagementService::changePassword() +void ZenvyController::changePassword(const std::string& password) const { + m_authenticationManagementService->changePassword(password); } diff --git a/Trenser.Zenvy/Trenser.Zenvy/controllers/ZenvyController.h b/Trenser.Zenvy/Trenser.Zenvy/controllers/ZenvyController.h index 3dc3575..6413723 100644 --- a/Trenser.Zenvy/Trenser.Zenvy/controllers/ZenvyController.h +++ b/Trenser.Zenvy/Trenser.Zenvy/controllers/ZenvyController.h @@ -44,5 +44,7 @@ public: //Authentication AuthenticationContext login(const std::string& email, const std::string& password); void logout(); + void changePassword(const std::string&) const; }; + diff --git a/Trenser.Zenvy/Trenser.Zenvy/datastores/DataStore.cpp b/Trenser.Zenvy/Trenser.Zenvy/datastores/DataStore.cpp index 7fcd993..71f6d56 100644 --- a/Trenser.Zenvy/Trenser.Zenvy/datastores/DataStore.cpp +++ b/Trenser.Zenvy/Trenser.Zenvy/datastores/DataStore.cpp @@ -11,6 +11,11 @@ logMap& DataStore::getLogs() return m_logs; } +std::shared_ptr& DataStore::getAuthenticatedEmployee() +{ + return m_authenticatedEmployee; +} + void DataStore::setAuthenticatedEmployee(std::shared_ptr authenticatedEmployee) { m_authenticatedEmployee = authenticatedEmployee; diff --git a/Trenser.Zenvy/Trenser.Zenvy/datastores/DataStore.h b/Trenser.Zenvy/Trenser.Zenvy/datastores/DataStore.h index ca2bd63..750d741 100644 --- a/Trenser.Zenvy/Trenser.Zenvy/datastores/DataStore.h +++ b/Trenser.Zenvy/Trenser.Zenvy/datastores/DataStore.h @@ -37,5 +37,6 @@ public: DataStore& operator=(DataStore&&) = delete; employeeMap& getEmployees(); logMap& getLogs(); + std::shared_ptr& getAuthenticatedEmployee(); void setAuthenticatedEmployee(std::shared_ptr < Employee>); }; \ No newline at end of file diff --git a/Trenser.Zenvy/Trenser.Zenvy/services/AuthenticationManagementService.cpp b/Trenser.Zenvy/Trenser.Zenvy/services/AuthenticationManagementService.cpp index 9f60c05..bf98c64 100644 --- a/Trenser.Zenvy/Trenser.Zenvy/services/AuthenticationManagementService.cpp +++ b/Trenser.Zenvy/Trenser.Zenvy/services/AuthenticationManagementService.cpp @@ -46,3 +46,16 @@ std::tuple } return std::make_tuple(loginStatus, employeeType, employeeDesignation); } + +void AuthenticationManagementService::changePassword(const std::string& password) +{ + std::shared_ptr authenticatedUser = m_dataStore.getAuthenticatedUser(); + if (authenticatedUser) + { + authenticatedUser->setEmployeePassword(password); + } + else + { + throw std::runtime_error("User not found"); + } +} diff --git a/Trenser.Zenvy/Trenser.Zenvy/services/AuthenticationManagementService.h b/Trenser.Zenvy/Trenser.Zenvy/services/AuthenticationManagementService.h index 5790978..9c65eae 100644 --- a/Trenser.Zenvy/Trenser.Zenvy/services/AuthenticationManagementService.h +++ b/Trenser.Zenvy/Trenser.Zenvy/services/AuthenticationManagementService.h @@ -2,6 +2,7 @@ #include #include #include +#include #include "DataStore.h" #include "Enums.h" @@ -13,6 +14,6 @@ public: AuthenticationManagementService() : m_dataStore(DataStore::getInstance()) {}; std::tuple login(const std::string& username, const std::string& password); void logout(); - void changePassword(); + void changePassword(std::string); };