handler signup fulfilment
This commit is contained in:
69
src/main.cpp
69
src/main.cpp
@ -299,6 +299,75 @@ int main(int argc, char *argv[]) {
|
||||
return page.render();
|
||||
});
|
||||
|
||||
/*
|
||||
* Page for freelancer to sign up fulfillment
|
||||
*/
|
||||
CROW_ROUTE(app, "/freelancer/signup/fulfilment").methods("POST"_method)
|
||||
([databaseURI, configuration](const crow::request& postRequest ) {
|
||||
crow::mustache::context ctx;
|
||||
|
||||
string postRequestBody = postRequest.body;
|
||||
Utilities::decodeString(postRequestBody);
|
||||
vector<string> splitPostRequestBody = Utilities::splitStringIntoVector(postRequestBody, '&');
|
||||
|
||||
string name, email, password;
|
||||
|
||||
bool requestFillCompletion = false;
|
||||
for (const string& item : splitPostRequestBody) {
|
||||
vector<string> splitItem = Utilities::splitStringIntoVector(item, '=');
|
||||
if (splitItem.at(0) == "freelancername")
|
||||
name = splitItem.at(1);
|
||||
if (splitItem.at(0) == "freelanceremail")
|
||||
email = splitItem.at(1);
|
||||
if (splitItem.at(0) == "freelancerpassword")
|
||||
password = splitItem.at(1);
|
||||
}
|
||||
|
||||
//check if signup data is complete
|
||||
if (!email.empty() && !name.empty() && !password.empty())
|
||||
requestFillCompletion = true;
|
||||
|
||||
if (requestFillCompletion) {
|
||||
//check if email address hasn't been registered yet
|
||||
pqxx::connection databaseConnection(databaseURI);
|
||||
pqxx::result checkResult = Database::executePreparedStatement_SELECT_CHECK_EMAIL_EXISTS(databaseConnection, email);
|
||||
int checkResultExtracted = stoi(checkResult.at(0).at(0).c_str());
|
||||
|
||||
if (checkResultExtracted == 0) {
|
||||
string pwsalt, pwhash;
|
||||
pwsalt = Utilities::generateSalt();
|
||||
pwhash = Utilities::hashPassword(pwsalt, password);
|
||||
|
||||
int errorLevel = Database::executePreparedStatement_INSERT_NEW_FREELANCER(databaseConnection, email, name, pwsalt, pwhash);
|
||||
if (errorLevel == 0) {
|
||||
ctx["REGISTRATION_SUCCESS"] = true;
|
||||
ctx["freelancername"] = name;
|
||||
ctx["freelanceremail"] = email;
|
||||
}
|
||||
else {
|
||||
ctx["REGISTRATION_ERROR"] = true;
|
||||
if (errorLevel == 1)
|
||||
ctx["REGISTRATION_ERROR_QUERY"] = true;
|
||||
if (errorLevel == 2)
|
||||
ctx["REGISTRATION_ERROR_CRITICAL"] = true;
|
||||
}
|
||||
}
|
||||
else {
|
||||
ctx["REGISTRATION_ERROR"] = true;
|
||||
ctx["freelanceremail"] = email;
|
||||
ctx["REGISTRATION_ERROR_EMAIL_ALREADY_IN_USE<"] = true;
|
||||
}
|
||||
}
|
||||
else {
|
||||
ctx["REGISTRATION_ERROR"] = true;
|
||||
ctx["REGISTRATION_ERROR_EMAIL_NAME_PASS_NOT_FILLED"] = true;
|
||||
}
|
||||
|
||||
string templateHTML = "freelancer_Signup_Fulfilment.html";
|
||||
|
||||
auto page = crow::mustache::load(templateHTML);
|
||||
|
||||
return page.render();
|
||||
});
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user