pasword reset request route handler
This commit is contained in:
38
src/main.cpp
38
src/main.cpp
@ -279,6 +279,44 @@ int main(int argc, char *argv[]) {
|
||||
return page.render();
|
||||
});
|
||||
|
||||
/*
|
||||
* Page for freelancer password reset fulfilment
|
||||
*/
|
||||
CROW_ROUTE(app, "/freelancer/login/passwordreset/fulfilment")
|
||||
([&, configuration](const crow::request& postRequest ) {
|
||||
crow::mustache::context ctx;
|
||||
string postRequestBody = postRequest.body;
|
||||
Utilities::decodeString(postRequestBody);
|
||||
vector<string> splitPostRequestBody = Utilities::splitStringIntoVector(postRequestBody, '&');
|
||||
string email;
|
||||
for (const string& item : splitPostRequestBody) {
|
||||
vector<string> splitItem = Utilities::splitStringIntoVector(item, '=');
|
||||
if (splitItem.at(0) == "freelanceremail")
|
||||
email = splitItem.at(1);
|
||||
}
|
||||
|
||||
if (!email.empty()) {
|
||||
pqxx::connection databaseConnection(configuration.databaseConnectionString);
|
||||
pqxx::result checkFreelancerExists = Database::executePreparedStatement_SELECT_CHECK_EMAIL_EXISTS(databaseConnection, email);
|
||||
int checkFreelancerExistsExtracted = stoi(checkFreelancerExists.at(0).at(0).c_str());
|
||||
if (checkFreelancerExistsExtracted == 1) {
|
||||
std::string passwordResetKey = Utilities::generateRandomHashValueSHA256();
|
||||
|
||||
pqxx::result checkFreelancerResetKeyExists = Database::executePreparedStatement_SELECT_CHECK_FREELANCER_RESET_KEY(databaseConnection, email);
|
||||
int checkFreelancerResetKeyExistsExtracted = stoi(checkFreelancerResetKeyExists.at(0).at(0).c_str());
|
||||
if (checkFreelancerResetKeyExistsExtracted > 0)
|
||||
Database::executePreparedStatement_DELETE_FREELANCER_RESET_KEY(databaseConnection, email);
|
||||
|
||||
Database::executePreparedStatement_INSERT_FREELANCER_RESET_KEY(databaseConnection, email, passwordResetKey);
|
||||
|
||||
if (Utilities::sendPasswordResetEmail(configuration, email, passwordResetKey) == 0)
|
||||
ctx["passwordresetmailsent"] = true;
|
||||
}
|
||||
ctx["resetemail"] = email;
|
||||
}
|
||||
auto page = crow::mustache::load("freelancer_Login_PasswordReset.html");
|
||||
return page.render(ctx);
|
||||
});
|
||||
/*
|
||||
* Page for freelancer to log in fulfillment
|
||||
*/
|
||||
|
Reference in New Issue
Block a user