diff --git a/Trenser.VehicleServiceSystem/Trenser.VehicleServiceSystem/Trenser.VehicleServiceSystem.vcxproj b/Trenser.VehicleServiceSystem/Trenser.VehicleServiceSystem/Trenser.VehicleServiceSystem.vcxproj
index a65c46d..1b76c8a 100644
--- a/Trenser.VehicleServiceSystem/Trenser.VehicleServiceSystem/Trenser.VehicleServiceSystem.vcxproj
+++ b/Trenser.VehicleServiceSystem/Trenser.VehicleServiceSystem/Trenser.VehicleServiceSystem.vcxproj
@@ -171,6 +171,7 @@
+
diff --git a/Trenser.VehicleServiceSystem/Trenser.VehicleServiceSystem/controllers/Controller.cpp b/Trenser.VehicleServiceSystem/Trenser.VehicleServiceSystem/controllers/Controller.cpp
index d536e8a..e641900 100644
--- a/Trenser.VehicleServiceSystem/Trenser.VehicleServiceSystem/controllers/Controller.cpp
+++ b/Trenser.VehicleServiceSystem/Trenser.VehicleServiceSystem/controllers/Controller.cpp
@@ -2,7 +2,7 @@
bool Controller::login(const std::string& username, const std::string& password)
{
- return false;
+ return m_authenticationManagementService.login(username, password);
}
void Controller::logout()
@@ -19,7 +19,7 @@ void Controller::createCustomer(const std::string& username, const std::string&
const User* Controller::getAuthenticatedUser()
{
- return nullptr;
+ return m_authenticationManagementService.getAuthenticatedUser();
}
void Controller::createTechnician(const std::string& username, const std::string& password, const std::string& email, const std::string& phone)
@@ -143,5 +143,6 @@ void Controller::configureNotifications(const std::string& userID, bool paymentN
void Controller::runSystemChecks()
{
+ m_userManagementService.ensureAdminExists();
}
diff --git a/Trenser.VehicleServiceSystem/Trenser.VehicleServiceSystem/controllers/Controller.h b/Trenser.VehicleServiceSystem/Trenser.VehicleServiceSystem/controllers/Controller.h
index 3aabb58..e1ecc49 100644
--- a/Trenser.VehicleServiceSystem/Trenser.VehicleServiceSystem/controllers/Controller.h
+++ b/Trenser.VehicleServiceSystem/Trenser.VehicleServiceSystem/controllers/Controller.h
@@ -2,6 +2,8 @@
#include "Map.h"
#include
#include "Enums.h"
+#include "AuthenticationManagementService.h"
+#include "UserManagementService.h"
class Service;
class ComboPackage;
@@ -14,6 +16,9 @@ class Notification;
class Controller
{
+private:
+ AuthenticationManagementService m_authenticationManagementService;
+ UserManagementService m_userManagementService;
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..91dd003 100644
--- a/Trenser.VehicleServiceSystem/Trenser.VehicleServiceSystem/services/AuthenticationManagementService.cpp
+++ b/Trenser.VehicleServiceSystem/Trenser.VehicleServiceSystem/services/AuthenticationManagementService.cpp
@@ -1,3 +1,29 @@
#include "AuthenticationManagementService.h"
+#include "User.h"
User* AuthenticationManagementService::m_authenticatedUser = nullptr;
+
+bool AuthenticationManagementService::login(const std::string& username, const std::string& password)
+{
+ util::Map users = m_dataStore.getUsers();
+ int usersMapSize = users.getSize();
+ for (int index = 0; index < usersMapSize; index++)
+ {
+ User* user = users.getValueAt(index);
+ if (username == user->getUserName())
+ {
+ if (password == user->getPassword())
+ {
+ m_authenticatedUser = user;
+ return true;
+ }
+ return false;
+ }
+ }
+ return false;
+}
+
+User* AuthenticationManagementService::getAuthenticatedUser()
+{
+ return m_authenticatedUser;
+}
diff --git a/Trenser.VehicleServiceSystem/Trenser.VehicleServiceSystem/services/UserManagementService.cpp b/Trenser.VehicleServiceSystem/Trenser.VehicleServiceSystem/services/UserManagementService.cpp
index 2a5bd9e..2c2e156 100644
--- a/Trenser.VehicleServiceSystem/Trenser.VehicleServiceSystem/services/UserManagementService.cpp
+++ b/Trenser.VehicleServiceSystem/Trenser.VehicleServiceSystem/services/UserManagementService.cpp
@@ -1 +1,30 @@
#include "UserManagementService.h"
+#include "User.h"
+#include "Enums.h"
+#include "Config.h"
+
+void UserManagementService::ensureAdminExists()
+{
+ auto& usersMap = m_dataStore.getUsers();
+ int usersMapSize = usersMap.getSize();
+ bool isAdminFound = false;
+ for (int index = 0; index < usersMapSize; index++)
+ {
+ User* user = usersMap.getValueAt(index);
+ if (user && user->getUserType() == util::UserType::ADMIN)
+ {
+ isAdminFound = true;
+ break;
+ }
+ }
+ if (!isAdminFound)
+ {
+ createUser(
+ config::admin::DEFAULT_ADMIN_USERNAME,
+ config::admin::DEFAULT_ADMIN_NAME,
+ config::admin::DEFAULT_ADMIN_PASSWORD,
+ config::admin::DEFAULT_ADMIN_EMAIL,
+ config::admin::DEFAULT_ADMIN_PHONE,
+ util::UserType::ADMIN);
+ }
+}
diff --git a/Trenser.VehicleServiceSystem/Trenser.VehicleServiceSystem/services/UserManagementService.h b/Trenser.VehicleServiceSystem/Trenser.VehicleServiceSystem/services/UserManagementService.h
index bb7a85a..34603a4 100644
--- a/Trenser.VehicleServiceSystem/Trenser.VehicleServiceSystem/services/UserManagementService.h
+++ b/Trenser.VehicleServiceSystem/Trenser.VehicleServiceSystem/services/UserManagementService.h
@@ -13,7 +13,7 @@ private:
DataStore& m_dataStore;
public:
UserManagementService() : m_dataStore(DataStore::getInstance()) {}
- void createUser(const std::string& username, const std::string& password, const std::string& email, const std::string& phone, util::UserType type);
+ void createUser(const std::string& username, const std::string& name, const std::string& password, const std::string& email, const std::string& phone, util::UserType type);
void updateUserDetails(const std::string& userID, const std::string& email, const std::string& phone);
util::Map getUsers();
util::Map getUsers(util::UserType type);
@@ -21,4 +21,5 @@ public:
void removeUser(const std::string& userID);
util::Vector getUserNotifications(const std::string& userID);
void deleteNotification(const std::string& notificationID, const std::string& userID);
+ void ensureAdminExists();
};
diff --git a/Trenser.VehicleServiceSystem/Trenser.VehicleServiceSystem/utilities/Config.h b/Trenser.VehicleServiceSystem/Trenser.VehicleServiceSystem/utilities/Config.h
new file mode 100644
index 0000000..38c7bed
--- /dev/null
+++ b/Trenser.VehicleServiceSystem/Trenser.VehicleServiceSystem/utilities/Config.h
@@ -0,0 +1,13 @@
+#pragma once
+
+namespace config
+{
+ namespace admin
+ {
+ constexpr const char* DEFAULT_ADMIN_USERNAME = "admin";
+ constexpr const char* DEFAULT_ADMIN_NAME = "admin";
+ constexpr const char* DEFAULT_ADMIN_PASSWORD = "";
+ constexpr const char* DEFAULT_ADMIN_EMAIL = "admin@vss";
+ constexpr const char* DEFAULT_ADMIN_PHONE = "0000000000";
+ }
+}
diff --git a/Trenser.VehicleServiceSystem/Trenser.VehicleServiceSystem/views/UserInterface.cpp b/Trenser.VehicleServiceSystem/Trenser.VehicleServiceSystem/views/UserInterface.cpp
index 122f9a8..b03defd 100644
--- a/Trenser.VehicleServiceSystem/Trenser.VehicleServiceSystem/views/UserInterface.cpp
+++ b/Trenser.VehicleServiceSystem/Trenser.VehicleServiceSystem/views/UserInterface.cpp
@@ -1,6 +1,8 @@
#include "UserInterface.h"
#include "InputHelper.h"
#include "OutputHelper.h"
+#include "Enums.h"
+#include "User.h"
void UserInterface::run()
{
@@ -48,7 +50,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()