diff --git a/Trenser.VehicleServiceSystem/Trenser.VehicleServiceSystem/controllers/Controller.cpp b/Trenser.VehicleServiceSystem/Trenser.VehicleServiceSystem/controllers/Controller.cpp index adb2344..b9da8b1 100644 --- a/Trenser.VehicleServiceSystem/Trenser.VehicleServiceSystem/controllers/Controller.cpp +++ b/Trenser.VehicleServiceSystem/Trenser.VehicleServiceSystem/controllers/Controller.cpp @@ -12,6 +12,7 @@ void Controller::logout() void Controller::changePassword(const std::string& newPassword) { + m_authenticationManagementService.changePassword(newPassword); } void Controller::createCustomer(const std::string& username, const std::string& password, const std::string& email, const std::string& phone) diff --git a/Trenser.VehicleServiceSystem/Trenser.VehicleServiceSystem/services/AuthenticationManagementService.cpp b/Trenser.VehicleServiceSystem/Trenser.VehicleServiceSystem/services/AuthenticationManagementService.cpp index 7f7e3e8..36c2080 100644 --- a/Trenser.VehicleServiceSystem/Trenser.VehicleServiceSystem/services/AuthenticationManagementService.cpp +++ b/Trenser.VehicleServiceSystem/Trenser.VehicleServiceSystem/services/AuthenticationManagementService.cpp @@ -1,3 +1,4 @@ +#include #include "AuthenticationManagementService.h" #include "User.h" @@ -32,3 +33,12 @@ void AuthenticationManagementService::logout() { m_authenticatedUser = nullptr; } + +void AuthenticationManagementService::changePassword(const std::string& newPassword) +{ + if (m_authenticatedUser == nullptr) + { + throw std::runtime_error("There is no user currently logged in!"); + } + m_authenticatedUser->setPassword(newPassword); +} diff --git a/Trenser.VehicleServiceSystem/Trenser.VehicleServiceSystem/views/CustomerMenu.cpp b/Trenser.VehicleServiceSystem/Trenser.VehicleServiceSystem/views/CustomerMenu.cpp index 2e5fc75..e39a0a7 100644 --- a/Trenser.VehicleServiceSystem/Trenser.VehicleServiceSystem/views/CustomerMenu.cpp +++ b/Trenser.VehicleServiceSystem/Trenser.VehicleServiceSystem/views/CustomerMenu.cpp @@ -1,6 +1,7 @@ #include "CustomerMenu.h" #include "InputHelper.h" #include "OutputHelper.h" +#include "Validator.h" void CustomerMenu::showMenu() { @@ -38,6 +39,19 @@ void CustomerMenu::logout() void CustomerMenu::changePassword() { + std::string newPassword; + util::clear(); + std::cout << "Enter new password: "; + util::read(newPassword); + m_controller.changePassword(newPassword); + if (!util::isPasswordValid(newPassword)) + { + std::cout << "Error: Password is not strong enough!"; + util::pressEnter(); + return; + } + std::cout << "Password changed successfully"; + util::pressEnter(); } void CustomerMenu::updateDetails()