Continued work on changeAccountName() & basic refactoring

This commit is contained in:
theskywinds 2025-06-04 09:53:57 +02:00
parent 36b46c6899
commit dbe1063f29
2 changed files with 24 additions and 9 deletions

View File

@ -8,6 +8,7 @@ namespace AtmAdmin {
char startup();
bool handleUserInformation(char choice, std::string& information);
std::string changeAccountPin();
std::string changeAccountName();
}
#endif //ATMADMIN_H

View File

@ -1,9 +1,9 @@
#include <iostream>
#include "Errorseal.h"
#include "AtmAdmin.h"
#include <algorithm>
#include <oneapi/tbb/detail/_task.h>
#include <iostream>
#include <ranges>
#include "AtmAdmin.h"
#include "Errorseal.h"
namespace AtmAdmin {
char startup() {
@ -36,8 +36,11 @@ namespace AtmAdmin {
// Ensure that the name is also converted to fully lowercase.
// The code below is a placeholder
std::cout << "Enter your new username: ";
std::cin >> information;
tempInformation = changeAccountName();
if (tempInformation != "invalid") {
information = tempInformation;
return true;
}
break;
case '3':
// Simply a way to cheat, very straight-forward.
@ -108,14 +111,25 @@ namespace AtmAdmin {
std::string changeAccountName() {
std::string newName{};
std::cout << "Enter new name: ";
std::cin >> newName;
Error::ignoreLine();
if (newName.size() < 2 or newName.size() > 10) {
// Ensures the name is between 2 and 10 characters long.
if (newName.length() < 2 or newName.length() > 10) {
errorReport("Name has to be between 2 and 10 characters.");
return "invalid";
}
// Checks if the first character is a number.
if (isdigit(newName.at(0))) {
errorReport("First letter cannot be a digit.");
return "invalid";
}
// Turns all the letters into lowercase.
std::ranges::transform (newName.cbegin(), newName.cend(), newName.begin(), [] (unsigned char input) { return tolower(input); });
return newName;
}
}
}