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:
@@ -108,6 +108,17 @@ bool util::isPasswordValid(const std::string& password)
|
||||
return hasUpper && hasLower && hasDigit && hasSpecial;
|
||||
}
|
||||
|
||||
/*
|
||||
* Function: isUsernameDuplicate
|
||||
* Description: Checks if the given username already exists among active users.
|
||||
* Parameters:
|
||||
* username - string containing the username to validate
|
||||
* usersMap - map of user objects keyed by identifier
|
||||
* Returns:
|
||||
* bool - true if the username is already in use by an active user, false otherwise
|
||||
* Notes:
|
||||
* - Only considers users with state util::State::ACTIVE
|
||||
*/
|
||||
bool util::isUsernameDuplicate(const std::string& username, const util::Map<std::string, User*>& usersMap)
|
||||
{
|
||||
int index = usersMap.findIf(
|
||||
@@ -119,6 +130,17 @@ bool util::isUsernameDuplicate(const std::string& username, const util::Map<std:
|
||||
return index != -1;
|
||||
}
|
||||
|
||||
/*
|
||||
* Function: isPhoneDuplicate
|
||||
* Description: Checks if the given phone number already exists among active users.
|
||||
* Parameters:
|
||||
* phone - string containing the phone number to validate
|
||||
* usersMap - map of user objects keyed by identifier
|
||||
* Returns:
|
||||
* bool - true if the phone number is already in use by an active user, false otherwise
|
||||
* Notes:
|
||||
* - Only considers users with state util::State::ACTIVE
|
||||
*/
|
||||
bool util::isPhoneDuplicate(const std::string& phone, const util::Map<std::string, User*>& usersMap)
|
||||
{
|
||||
int index = usersMap.findIf(
|
||||
@@ -130,6 +152,17 @@ bool util::isPhoneDuplicate(const std::string& phone, const util::Map<std::strin
|
||||
return index != -1;
|
||||
}
|
||||
|
||||
/*
|
||||
* Function: isEmailDuplicate
|
||||
* Description: Checks if the given email address already exists among active users.
|
||||
* Parameters:
|
||||
* email - string containing the email address to validate
|
||||
* usersMap - map of user objects keyed by identifier
|
||||
* Returns:
|
||||
* bool - true if the email address is already in use by an active user, false otherwise
|
||||
* Notes:
|
||||
* - Only considers users with state util::State::ACTIVE
|
||||
*/
|
||||
bool util::isEmailDuplicate(const std::string& email, const util::Map<std::string, User*>& usersMap)
|
||||
{
|
||||
int index = usersMap.findIf(
|
||||
@@ -139,4 +172,4 @@ bool util::isEmailDuplicate(const std::string& email, const util::Map<std::strin
|
||||
}
|
||||
);
|
||||
return index != -1;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user