From fa08d4a90fb619c304cee4079a8d63c583d6531b Mon Sep 17 00:00:00 2001 From: Avinash Rajesh Date: Wed, 20 May 2026 19:42:45 +0530 Subject: [PATCH] Implement Login Functionality MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ADM003: Login 1. Added credential input handling in UserInterface::login with username and password prompts. 2. Integrated Controller::login to validate credentials and retrieve authenticated user. 3. Implemented role-based menu navigation: Admin → AdminMenu, Technician → TechnicianMenu, Customer → CustomerMenu. 4. Added error handling for invalid credentials and unknown user types with clear feedback messages. 5. Included util::clear for screen refresh and structured output formatting during login. Precondition: 1. Valid user accounts exist in the system (Admin, Technician, Customer). 2. Controller is connected to UserManagementService for authentication. 3. UserInterface is initialized with role-specific menus. Steps: 1. Launch UserInterface and select "Login". 2. Enter incorrect username or password. - Verify that system displays "Error: Invalid Username or Password". 3. Enter valid admin credentials. - Verify that AdminMenu is displayed successfully. 4. Enter valid technician or customer credentials. - Verify that TechnicianMenu or CustomerMenu is displayed accordingly. Sreeja Reghukumar --- .../views/UserInterface.cpp | 34 ++++++++++++++++++- 1 file changed, 33 insertions(+), 1 deletion(-) diff --git a/Trenser.VehicleServiceSystem/Trenser.VehicleServiceSystem/views/UserInterface.cpp b/Trenser.VehicleServiceSystem/Trenser.VehicleServiceSystem/views/UserInterface.cpp index 122f9a8..3fa0ea6 100644 --- a/Trenser.VehicleServiceSystem/Trenser.VehicleServiceSystem/views/UserInterface.cpp +++ b/Trenser.VehicleServiceSystem/Trenser.VehicleServiceSystem/views/UserInterface.cpp @@ -1,6 +1,7 @@ #include "UserInterface.h" #include "InputHelper.h" #include "OutputHelper.h" +#include "User.h" void UserInterface::run() { @@ -48,7 +49,38 @@ bool UserInterface::handleOperation(int choice) void UserInterface::login() { - + std::string username, password; + util::clear(); + std::cout << "Enter username: "; + util::read(username); + std::cout << "Enter password: "; + util::read(password); + if (m_controller.login(username, password)) + { + const User* authenticatedUser = m_controller.getAuthenticatedUser(); + if (authenticatedUser != nullptr) + { + switch (authenticatedUser->getUserType()) + { + case util::UserType::ADMIN: + m_adminMenu.showMenu(); + break; + case util::UserType::TECHNICIAN: + m_technicianMenu.showMenu(); + break; + case util::UserType::CUSTOMER: + m_customerMenu.showMenu(); + break; + default: + std::cout << "\nError: Unknown user type"; + break; + } + } + } + else + { + std::cout << "\nError: Invalid Username or Password"; + } } void UserInterface::registerCustomer()