Merge branch 'feature-customer-management-cus004' into feature-customer-management
This commit is contained in:
+3
-1
@@ -1,4 +1,5 @@
|
||||
#include "Controller.h"
|
||||
#include "Enums.h"
|
||||
|
||||
bool Controller::login(const std::string& username, const std::string& password)
|
||||
{
|
||||
@@ -15,8 +16,9 @@ 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)
|
||||
void Controller::createCustomer(const std::string& username, const std::string& name, const std::string& password, const std::string& email, const std::string& phone)
|
||||
{
|
||||
m_userManagementService.createUser(username, name, password, email, phone, util::UserType::CUSTOMER);
|
||||
}
|
||||
|
||||
const User* Controller::getAuthenticatedUser()
|
||||
|
||||
@@ -23,7 +23,7 @@ public:
|
||||
bool login(const std::string& username, const std::string& password);
|
||||
void logout();
|
||||
void changePassword(const std::string& newPassword);
|
||||
void createCustomer(const std::string& username, const std::string& password, const std::string& email, const std::string& phone);
|
||||
void createCustomer(const std::string& username, const std::string& name, const std::string& password, const std::string& email, const std::string& phone);
|
||||
const User* getAuthenticatedUser();
|
||||
void createTechnician(const std::string& username, const std::string& password, const std::string& email, const std::string& phone);
|
||||
void updateUserDetails(const std::string& email, const std::string& phone);
|
||||
|
||||
+32
-1
@@ -1,7 +1,12 @@
|
||||
#include "UserManagementService.h"
|
||||
#include <stdexcept>
|
||||
#include "User.h"
|
||||
#include "Enums.h"
|
||||
#include "Config.h"
|
||||
#include "UserManagementService.h"
|
||||
#include "ServiceManagementService.h"
|
||||
#include "PaymentManagementService.h"
|
||||
#include "InventoryManagementService.h"
|
||||
#include "Factory.h"
|
||||
|
||||
void UserManagementService::ensureAdminExists()
|
||||
{
|
||||
@@ -28,3 +33,29 @@ void UserManagementService::ensureAdminExists()
|
||||
util::UserType::ADMIN);
|
||||
}
|
||||
}
|
||||
|
||||
void UserManagementService::createUser(const std::string& username, const std::string& name, const std::string& password, const std::string& email, const std::string& phone, util::UserType type)
|
||||
{
|
||||
InventoryManagementService inventoryManagementService;
|
||||
PaymentManagementService paymentManagementService;
|
||||
ServiceManagementService serviceManagementService;
|
||||
auto& usersMap = m_dataStore.getUsers();
|
||||
int index = usersMap.findIf(
|
||||
[&](const std::string&, User* user)
|
||||
{
|
||||
return user->getUserName() == username;
|
||||
}
|
||||
);
|
||||
if (index != -1)
|
||||
{
|
||||
throw std::runtime_error("Username already exists");
|
||||
}
|
||||
User* newUser = Factory::getObject<User>(username, password, name, phone, email, type);
|
||||
usersMap.insert(newUser->getId(), newUser);
|
||||
paymentManagementService.attach(newUser);
|
||||
serviceManagementService.attach(newUser);
|
||||
if (newUser->getUserType() == util::UserType::ADMIN)
|
||||
{
|
||||
inventoryManagementService.attach(newUser);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
#include "OutputHelper.h"
|
||||
#include "Enums.h"
|
||||
#include "User.h"
|
||||
#include "Validator.h"
|
||||
|
||||
void UserInterface::run()
|
||||
{
|
||||
@@ -86,5 +87,37 @@ void UserInterface::login()
|
||||
|
||||
void UserInterface::registerCustomer()
|
||||
{
|
||||
|
||||
std::string username, name, email, phone, password;
|
||||
util::clear();
|
||||
std::cout << "Enter username: ";
|
||||
util::read(username);
|
||||
std::cout << "Enter name: ";
|
||||
util::read(name);
|
||||
std::cout << "Enter email: ";
|
||||
util::read(email);
|
||||
if (!util::isEmailValid(email))
|
||||
{
|
||||
std::cout << "Error: Email is invalid!";
|
||||
util::pressEnter();
|
||||
return;
|
||||
}
|
||||
std::cout << "Enter password: ";
|
||||
util::read(password);
|
||||
if (!util::isPasswordValid(password))
|
||||
{
|
||||
std::cout << "Error: Password is invalid!";
|
||||
util::pressEnter();
|
||||
return;
|
||||
}
|
||||
std::cout << "Enter phone: ";
|
||||
util::read(phone);
|
||||
if (!util::isPhoneNumberValid(phone))
|
||||
{
|
||||
std::cout << "Error: Phone number is invalid!";
|
||||
util::pressEnter();
|
||||
return;
|
||||
}
|
||||
m_controller.createCustomer(username, name, password, email, phone);
|
||||
std::cout << "Registration is successful";
|
||||
util::pressEnter();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user