Merge branch 'feature-customer-management-cus005' into feature-customer-management
This commit is contained in:
@@ -1,5 +1,7 @@
|
||||
#include <stdexcept>
|
||||
#include "Controller.h"
|
||||
#include "Enums.h"
|
||||
#include "User.h"
|
||||
|
||||
bool Controller::login(const std::string& username, const std::string& password)
|
||||
{
|
||||
@@ -32,6 +34,12 @@ void Controller::createTechnician(const std::string& username, const std::string
|
||||
|
||||
void Controller::updateUserDetails(const std::string& email, const std::string& phone)
|
||||
{
|
||||
User* authenticatedUser = m_authenticationManagementService.getAuthenticatedUser();
|
||||
if (authenticatedUser == nullptr)
|
||||
{
|
||||
throw std::runtime_error("No user currently logged in!");
|
||||
}
|
||||
m_userManagementService.updateUserDetails(authenticatedUser->getId(), email, phone);
|
||||
}
|
||||
|
||||
util::Map<std::string, const Service*> Controller::getServices()
|
||||
|
||||
+13
@@ -59,3 +59,16 @@ void UserManagementService::createUser(const std::string& username, const std::s
|
||||
inventoryManagementService.attach(newUser);
|
||||
}
|
||||
}
|
||||
|
||||
void UserManagementService::updateUserDetails(const std::string& userID, const std::string& email, const std::string& phone)
|
||||
{
|
||||
auto& usersMap = m_dataStore.getUsers();
|
||||
int index = usersMap.find(userID);
|
||||
if (index == -1)
|
||||
{
|
||||
throw std::runtime_error("User does not exist!");
|
||||
}
|
||||
User* user = usersMap.getValueAt(index);
|
||||
user->setEmail(email);
|
||||
user->setPhone(phone);
|
||||
}
|
||||
|
||||
@@ -56,6 +56,27 @@ void CustomerMenu::changePassword()
|
||||
|
||||
void CustomerMenu::updateDetails()
|
||||
{
|
||||
std::string email, phone;
|
||||
util::clear();
|
||||
std::cout << "Enter new email: ";
|
||||
util::read(email);
|
||||
if (!util::isEmailValid(email))
|
||||
{
|
||||
std::cout << "Error: Email is invalid!";
|
||||
util::pressEnter();
|
||||
return;
|
||||
}
|
||||
std::cout << "Enter new phone: ";
|
||||
util::read(phone);
|
||||
if (!util::isPhoneNumberValid(phone))
|
||||
{
|
||||
std::cout << "Error: Phone number is invalid!";
|
||||
util::pressEnter();
|
||||
return;
|
||||
}
|
||||
m_controller.updateUserDetails(email, phone);
|
||||
std::cout << "Profile details updated successfully";
|
||||
util::pressEnter();
|
||||
}
|
||||
|
||||
void CustomerMenu::selectService()
|
||||
|
||||
Reference in New Issue
Block a user