diff --git a/Trenser.VehicleServiceSystem/Trenser.VehicleServiceSystem/controllers/Controller.cpp b/Trenser.VehicleServiceSystem/Trenser.VehicleServiceSystem/controllers/Controller.cpp index d536e8a..931def8 100644 --- a/Trenser.VehicleServiceSystem/Trenser.VehicleServiceSystem/controllers/Controller.cpp +++ b/Trenser.VehicleServiceSystem/Trenser.VehicleServiceSystem/controllers/Controller.cpp @@ -11,6 +11,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/controllers/Controller.h b/Trenser.VehicleServiceSystem/Trenser.VehicleServiceSystem/controllers/Controller.h index 3aabb58..0333e80 100644 --- a/Trenser.VehicleServiceSystem/Trenser.VehicleServiceSystem/controllers/Controller.h +++ b/Trenser.VehicleServiceSystem/Trenser.VehicleServiceSystem/controllers/Controller.h @@ -2,6 +2,7 @@ #include "Map.h" #include #include "Enums.h" +#include "AuthenticationManagementService.h" class Service; class ComboPackage; @@ -14,6 +15,8 @@ class Notification; class Controller { +private: + AuthenticationManagementService m_authenticationManagementService; public: bool login(const std::string& username, const std::string& password); void logout(); diff --git a/Trenser.VehicleServiceSystem/Trenser.VehicleServiceSystem/services/AuthenticationManagementService.cpp b/Trenser.VehicleServiceSystem/Trenser.VehicleServiceSystem/services/AuthenticationManagementService.cpp index ca07fee..4251c95 100644 --- a/Trenser.VehicleServiceSystem/Trenser.VehicleServiceSystem/services/AuthenticationManagementService.cpp +++ b/Trenser.VehicleServiceSystem/Trenser.VehicleServiceSystem/services/AuthenticationManagementService.cpp @@ -1,3 +1,14 @@ +#include #include "AuthenticationManagementService.h" +#include "User.h" User* AuthenticationManagementService::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 047f471..b4cbd8b 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() { @@ -37,6 +38,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()