handler login fulfilment
This commit is contained in:
62
src/main.cpp
62
src/main.cpp
@@ -280,10 +280,68 @@ int main(int argc, char *argv[]) {
|
||||
|
||||
|
||||
|
||||
/*string templateHTML = "customer_Freelancer_Template_Request.html";
|
||||
string templateHTML = "freelancer_Login.html";
|
||||
auto page = crow::mustache::load(templateHTML);
|
||||
|
||||
return page.render();*/
|
||||
return page.render();
|
||||
});
|
||||
|
||||
/*
|
||||
* Page for freelancer to log in fulfillment
|
||||
*/
|
||||
CROW_ROUTE(app, "/freelancer/login/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 email, password;
|
||||
|
||||
for (const string& item : splitPostRequestBody) {
|
||||
vector<string> splitItem = Utilities::splitStringIntoVector(item, '=');
|
||||
if (splitItem.at(0) == "freelanceremail")
|
||||
email = splitItem.at(1);
|
||||
if (splitItem.at(0) == "freelancerpassword")
|
||||
password = splitItem.at(1);
|
||||
}
|
||||
|
||||
//check if login data is complete
|
||||
if (!email.empty() && !password.empty()){
|
||||
//check if freelancer exists
|
||||
pqxx::connection databaseConnection(databaseURI);
|
||||
pqxx::result checkFreelancerExists = Database::executePreparedStatement_SELECT_CHECK_EMAIL_EXISTS(databaseConnection, email);
|
||||
int checkFreelancerExistsExtracted = stoi(checkFreelancerExists.at(0).at(0).c_str());
|
||||
if (checkFreelancerExistsExtracted == 1) {
|
||||
pqxx::result freelancerSalt = Database::executePreparedStatement_SELECT_FREELANCER_SALT(databaseConnection, email);
|
||||
string salt = freelancerSalt.at(0).at(0).c_str();
|
||||
string hash = Utilities::hashPassword(salt, password);
|
||||
pqxx::result checkFreelancerHash = Database::executePreparedStatement_SELECT_CHECK_HASH_VALID(databaseConnection, email, hash);
|
||||
int checkFreelancerHashExtracted = stoi(checkFreelancerHash.at(0).at(0).c_str());
|
||||
if (checkFreelancerHashExtracted == 1) {
|
||||
//todo::create secure cookie
|
||||
ctx["LOGIN_SUCCESS"] = true;
|
||||
}
|
||||
else {
|
||||
ctx["LOGIN_ERROR"] = true;
|
||||
ctx["LOGIN_ERROR_LOGIN_DATA_INVALID"] = true;
|
||||
}
|
||||
}
|
||||
else {
|
||||
ctx["LOGIN_ERROR"] = true;
|
||||
ctx["LOGIN_ERROR_LOGIN_DATA_INVALID"] = true;
|
||||
}
|
||||
}
|
||||
else {
|
||||
ctx["LOGIN_ERROR"] = true;
|
||||
ctx["LOGIN_ERROR_EMAIL_PASS_NOT_FILLED"] = true;
|
||||
}
|
||||
|
||||
|
||||
string templateHTML = "freelancer_Login_Fulfilment.html";
|
||||
auto page = crow::mustache::load(templateHTML);
|
||||
|
||||
return page.render(ctx);
|
||||
});
|
||||
|
||||
/*
|
||||
* Page for freelancer to sign up
|
||||
|
Reference in New Issue
Block a user