Fix login validation and improve error messages
- Check if user account is inactive before allowing login - Add password confirmation in change password dialog - Prevent changing password to the same value - Standardize error messages to say "Invalid index" instead of "Invalid choice" - Add blank line before system pause prompt - Add "Change Password" header to change password screen - Show error message when login fails Fixes #1738 Fixes #1736
This commit is contained in:
@@ -62,6 +62,7 @@ namespace util
|
||||
*/
|
||||
inline void pressEnter()
|
||||
{
|
||||
std::cout << std::endl;
|
||||
system("pause");
|
||||
}
|
||||
}
|
||||
@@ -77,7 +77,7 @@ inline std::string selectServicesToRemove(util::Map<std::string, const Service*>
|
||||
}
|
||||
else
|
||||
{
|
||||
std::cout << "Invalid choice." << std::endl;
|
||||
std::cout << "Invalid index." << std::endl;
|
||||
return "";
|
||||
}
|
||||
}
|
||||
@@ -359,7 +359,7 @@ static std::string selectInvoiceFromUserForPayment(const util::Map<std::string,
|
||||
}
|
||||
else
|
||||
{
|
||||
std::cout << "Invalid choice.\n";
|
||||
std::cout << "Invalid index.\n";
|
||||
return "";
|
||||
}
|
||||
}
|
||||
@@ -389,7 +389,7 @@ static util::PaymentMode selectPaymentMode()
|
||||
}
|
||||
else
|
||||
{
|
||||
std::cout << "Invalid choice, Offline mode selected.\n";
|
||||
std::cout << "Invalid choice. Offline mode selected.\n";
|
||||
return util::PaymentMode::OFFLINE;
|
||||
}
|
||||
}
|
||||
@@ -513,7 +513,7 @@ static std::string selectJobCardToComplete(util::Map<std::string, const JobCard*
|
||||
}
|
||||
else
|
||||
{
|
||||
std::cout << "Invalid choice.\n";
|
||||
std::cout << "Invalid index.\n";
|
||||
return "";
|
||||
}
|
||||
}
|
||||
@@ -561,7 +561,7 @@ inline const Notification* selectNotification(const util::Vector<const Notificat
|
||||
util::read(selectedIndex);
|
||||
if (!indexedNotifications.containsKey(selectedIndex))
|
||||
{
|
||||
std::cout << "Invalid selection." << std::endl;
|
||||
std::cout << "Invalid index." << std::endl;
|
||||
return nullptr;
|
||||
}
|
||||
return indexedNotifications[selectedIndex];
|
||||
@@ -623,10 +623,16 @@ Return type: void
|
||||
inline void changePasswordHelper(Controller& controller)
|
||||
{
|
||||
util::clear();
|
||||
std::string newPassword;
|
||||
const User* authenticatedUser = controller.getAuthenticatedUser();
|
||||
if (!authenticatedUser)
|
||||
{
|
||||
throw std::runtime_error("No user is currently logged in!");
|
||||
}
|
||||
std::string newPassword, confirmedPassword;
|
||||
while (true)
|
||||
{
|
||||
util::clear();
|
||||
std::cout << "Change Password\n";
|
||||
std::cout << "Enter new password: ";
|
||||
util::read(newPassword);
|
||||
if (!util::isPasswordValid(newPassword))
|
||||
@@ -635,6 +641,20 @@ inline void changePasswordHelper(Controller& controller)
|
||||
util::pressEnter();
|
||||
continue;
|
||||
}
|
||||
if (newPassword == authenticatedUser->getPassword())
|
||||
{
|
||||
std::cout << "New password cannot be same as old password. Try again\n";
|
||||
util::pressEnter();
|
||||
continue;
|
||||
}
|
||||
std::cout << "Confirm new password: ";
|
||||
util::read(confirmedPassword);
|
||||
if (confirmedPassword != newPassword)
|
||||
{
|
||||
std::cout << "Passwords are different. Try again\n";
|
||||
util::pressEnter();
|
||||
continue;
|
||||
}
|
||||
controller.changePassword(newPassword);
|
||||
std::cout << "Password changed successfully\n";
|
||||
util::pressEnter();
|
||||
|
||||
@@ -85,14 +85,15 @@ void UserInterface::login()
|
||||
{
|
||||
std::string username, password;
|
||||
util::clear();
|
||||
std::cout << "Enter username: ";
|
||||
std::cout << "Login ";
|
||||
std::cout << "\nEnter 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)
|
||||
if (authenticatedUser && authenticatedUser->getState() != util::State::INACTIVE)
|
||||
{
|
||||
switch (authenticatedUser->getUserType())
|
||||
{
|
||||
@@ -110,10 +111,16 @@ void UserInterface::login()
|
||||
break;
|
||||
}
|
||||
}
|
||||
else if (authenticatedUser && authenticatedUser->getState() == util::State::INACTIVE)
|
||||
{
|
||||
std::cout << "\nError: Your account has been disabled. Please contact your Administrator.";
|
||||
util::pressEnter();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
std::cout << "\nError: Invalid Username or Password";
|
||||
util::pressEnter();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user