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..54610e1 100644 --- a/Trenser.VehicleServiceSystem/Trenser.VehicleServiceSystem/services/AuthenticationManagementService.cpp +++ b/Trenser.VehicleServiceSystem/Trenser.VehicleServiceSystem/services/AuthenticationManagementService.cpp @@ -1,3 +1,13 @@ #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/AdminMenu.cpp b/Trenser.VehicleServiceSystem/Trenser.VehicleServiceSystem/views/AdminMenu.cpp index 0432f3c..d1c596d 100644 --- a/Trenser.VehicleServiceSystem/Trenser.VehicleServiceSystem/views/AdminMenu.cpp +++ b/Trenser.VehicleServiceSystem/Trenser.VehicleServiceSystem/views/AdminMenu.cpp @@ -1,6 +1,7 @@ #include "AdminMenu.h" #include "InputHelper.h" #include "OutputHelper.h" +#include "Validator.h" void AdminMenu::showMenu() { @@ -38,6 +39,23 @@ void AdminMenu::logout() void AdminMenu::changePassword() { + std::string newPassword; + while (true) + { + util::clear(); + std::cout << "Enter new password: "; + util::read(newPassword); + if (!util::isPasswordValid(newPassword)) + { + std::cout << "Error: Password is not strong enough!\n"; + util::pressEnter(); + continue; + } + m_controller.changePassword(newPassword); + std::cout << "Password changed successfully\n"; + util::pressEnter(); + break; + } } void AdminMenu::viewStockLevels() diff --git a/Trenser.VehicleServiceSystem/Trenser.VehicleServiceSystem/views/TechnicianMenu.cpp b/Trenser.VehicleServiceSystem/Trenser.VehicleServiceSystem/views/TechnicianMenu.cpp index d6c4d57..b0b3c77 100644 --- a/Trenser.VehicleServiceSystem/Trenser.VehicleServiceSystem/views/TechnicianMenu.cpp +++ b/Trenser.VehicleServiceSystem/Trenser.VehicleServiceSystem/views/TechnicianMenu.cpp @@ -1,6 +1,7 @@ #include "TechnicianMenu.h" #include "InputHelper.h" #include "OutputHelper.h" +#include "Validator.h" void TechnicianMenu::showMenu() { @@ -38,3 +39,24 @@ void TechnicianMenu::completeJob() void TechnicianMenu::viewNotifications() { } + +void TechnicianMenu::changePassword() +{ + std::string newPassword; + while (true) + { + util::clear(); + std::cout << "Enter new password: "; + util::read(newPassword); + if (!util::isPasswordValid(newPassword)) + { + std::cout << "Error: Password is not strong enough!\n"; + util::pressEnter(); + continue; + } + m_controller.changePassword(newPassword); + std::cout << "Password changed successfully\n"; + util::pressEnter(); + break; + } +} \ No newline at end of file diff --git a/Trenser.VehicleServiceSystem/Trenser.VehicleServiceSystem/views/TechnicianMenu.h b/Trenser.VehicleServiceSystem/Trenser.VehicleServiceSystem/views/TechnicianMenu.h index c366d9b..cbf5fc6 100644 --- a/Trenser.VehicleServiceSystem/Trenser.VehicleServiceSystem/views/TechnicianMenu.h +++ b/Trenser.VehicleServiceSystem/Trenser.VehicleServiceSystem/views/TechnicianMenu.h @@ -10,4 +10,5 @@ public: void showMenu(); void completeJob(); void viewNotifications(); + void changePassword(); };