Password registration/reset confirmation at entry

This commit is contained in:
Tina_Azure
2023-04-30 18:12:31 +02:00
parent 5b877355c4
commit 0dc262ef69
5 changed files with 25 additions and 5 deletions

View File

@ -346,15 +346,17 @@ int main(int argc, char *argv[]) {
string postRequestBody = postRequest.body;
Utilities::decodeString(postRequestBody);
vector<string> splitPostRequestBody = Utilities::splitStringIntoVector(postRequestBody, '&');
string password;
string password, passwordConfirmation;
for (const string& item : splitPostRequestBody) {
vector<string> splitItem = Utilities::splitStringIntoVector(item, '=');
if (splitItem.at(0) == "freelancerpassword")
password = splitItem.at(1);
if (splitItem.at(0) == "freelancerpasswordconfirmation")
passwordConfirmation = splitItem.at(1);
}
pqxx::connection databaseConnection(configuration.databaseConnectionString);
pqxx::result freelancerEmail = Database::executePreparedStatement_SELECT_FREELANCER_EMAIL_FROM_PASSWORD_RESET_KEY(databaseConnection, passwordResetKey);
if (!freelancerEmail.empty() && !password.empty()) {
if (!freelancerEmail.empty() && !password.empty() && !(password.compare(passwordConfirmation) == 0)) {
string email = freelancerEmail.at(0).at(0).c_str();
pqxx::result keyExpiration = Database::executePreparedStatement_SELECT_CHECK_FREELANCER_RESET_KEY_EXPIRED(databaseConnection, email);
if (stoi(keyExpiration.at(0).at(0).c_str()) == 0) {
@ -385,6 +387,8 @@ int main(int argc, char *argv[]) {
ctx["PASSWORD_EMPTY"] = true;
if (freelancerEmail.empty())
ctx["PASSWORD_RESET_DOES_NOT_EXIST"] = true;
if (!(password.compare(passwordConfirmation) == 0))
ctx["PASSWORD_RESET_PASS_CONFIRMATION"] = true;
}
auto page = crow::mustache::load("passwordReset_Fulfillment.html");
return page.render(ctx);
@ -485,7 +489,7 @@ int main(int argc, char *argv[]) {
Utilities::decodeString(postRequestBody);
vector<string> splitPostRequestBody = Utilities::splitStringIntoVector(postRequestBody, '&');
string name, email, password;
string name, email, password, passwordConfirmation;
bool requestFillCompletion = false;
for (const string& item : splitPostRequestBody) {
@ -496,10 +500,12 @@ int main(int argc, char *argv[]) {
email = splitItem.at(1);
if (splitItem.at(0) == "freelancerpassword")
password = splitItem.at(1);
if (splitItem.at(0) == "freelancerpasswordconfirmation")
passwordConfirmation = splitItem.at(1);
}
//check if signup data is complete
if (!email.empty() && !name.empty() && !password.empty())
if (!email.empty() && !name.empty() && !password.empty() && !(password.compare(passwordConfirmation) == 0))
requestFillCompletion = true;
if (requestFillCompletion) {
@ -536,6 +542,8 @@ int main(int argc, char *argv[]) {
}
else {
ctx["REGISTRATION_ERROR"] = true;
if (!(password.compare(passwordConfirmation) == 0))
ctx["REGISTRATION_ERROR_PASS_CONFIRMATION"] = true;
ctx["REGISTRATION_ERROR_EMAIL_NAME_PASS_NOT_FILLED"] = true;
}

View File

@ -10,6 +10,7 @@
<label for="freelancername">Name:</label> <input type="text" id="freelancername" name="freelancername" value=""><br>
<label for="freelanceremail">E-Mail:</label> <input type="email" id="freelanceremail" name="freelanceremail" value=""><br>
<label for="freelancerpassword">Password: </label> <input type="password" id="freelancerpassword" name="freelancerpassword" value=""><br>
<label for="freelancerpasswordconfirmation">Confirm Password: </label> <input type="password" id="freelancerpasswordconfirmation" name="freelancerpasswordconfirmation" value=""><br>
<button type="submit" class="button">Sign Up</button>
</form>
<br>

View File

@ -26,9 +26,14 @@
{{/REGISTRATION_ERROR_EMAIL_ALREADY_IN_USE}}
{{#REGISTRATION_ERROR_EMAIL_NAME_PASS_NOT_FILLED}}
<div>
The registration form has not been filled out completely
The registration form has not been filled out completely.
</div>
{{/REGISTRATION_ERROR_EMAIL_NAME_PASS_NOT_FILLED}}
{{#REGISTRATION_ERROR_PASS_CONFIRMATION}}
<div>
The Password does not equal the confirmation.
</div>
{{/REGISTRATION_ERROR_PASS_CONFIRMATION}}
{{#REGISTRATION_ERROR}}
<form action="/freelancer/signup" method="get">
<button type="submit" class="button">Registration Error: Return to signup</button>

View File

@ -8,6 +8,7 @@
<br>
<form action="/passwordreset/{{passwordresetkey}}/fulfilment" method="post">
<label for="freelancerpassword">Password: </label> <input type="password" id="freelancerpassword" name="freelancerpassword" value=""><br>
<label for="freelancerpasswordconfirmation">Confirm Password: </label> <input type="password" id="freelancerpasswordconfirmation" name="freelancerpasswordconfirmation" value=""><br>
<button type="submit" class="button">Reset Password</button>
</form>
<br>

View File

@ -23,6 +23,11 @@
No new password has been entered.
</div>
{{/PASSWORD_EMPTY}}
{{#PASSWORD_RESET_PASS_CONFIRMATION}}
<div>
The Password does not equal the confirmation.
</div>
{{/PASSWORD_RESET_PASS_CONFIRMATION}}
{{#PASSWORD_RESET_EXPIRED}}
<div>
The password request has expired.