Fix Update Profile and User Validation Issues
- Included Validator.h in UserManagementService.cpp for duplicate checks. - Enhanced updateUserDetails in UserManagementService to validate: - Throw error if user does not exist. - Throw error if email already exists among active users. - Throw error if phone number already exists among active users. - Implemented new duplicate validation functions in Validator.cpp: - isUsernameDuplicate - isPhoneDuplicate - isEmailDuplicate - Declared new duplicate validation functions in Validator.h. - Updated CustomerMenu::updateDetails: - Added "Update Details" header for clarity. - Improved error messages with newline formatting. - Added success message with newline formatting. Fixes #1746
This commit is contained in:
+9
-1
@@ -111,7 +111,15 @@ void UserManagementService::updateUserDetails(const std::string& userID, const s
|
||||
int index = usersMap.find(userID);
|
||||
if (index == -1)
|
||||
{
|
||||
throw std::runtime_error("User does not exist!");
|
||||
throw std::runtime_error("User does not exist!\n");
|
||||
}
|
||||
if (util::isEmailDuplicate(email, usersMap))
|
||||
{
|
||||
throw std::runtime_error("Email already exists!\n");
|
||||
}
|
||||
if (util::isPhoneDuplicate(phone, usersMap))
|
||||
{
|
||||
throw std::runtime_error("Phone number already exists!\n");
|
||||
}
|
||||
User* user = usersMap.getValueAt(index);
|
||||
user->setEmail(email);
|
||||
|
||||
Reference in New Issue
Block a user