database request to check if a freelancer is logged on

This commit is contained in:
Tina_Azure
2023-04-22 23:17:56 +02:00
parent 4eb6923bce
commit c422b65e03

View File

@ -53,6 +53,12 @@ namespace Database {
const static std::string PREPARED_STATEMENT_SELECT_CHECK_EMAIL_EXISTS = "selectCheckEmailExists";
const static std::string SQL_STATEMENT_SELECT_CHECK_EMAIL_EXISTS = "select count(*) from freelancers where emailaddress = $1;";
/*
* Name and Statement for prepared statement to validate if a freelancer is already logged in
*/
const static std::string PREPARED_STATEMENT_SELECT_CHECK_FREELANCER_LOGIN_STATE = "selectCheckFreelancerLoginState";
const static std::string SQL_STATEMENT_SELECT_CHECK_FREELANCER_LOGIN_STATE = "select count(*) from freelancers where emailaddress = $1 AND loginvalidationkey = $2;";
/*
* Name and Statement for prepared statement to get salt using a given email
*/
@ -359,6 +365,17 @@ namespace Database {
return result;
}
/*
* Executes the prepared statement SELECT_CHECK_FREELANCER_LOGIN_STATE
* Takes an open pqxx::connection the loginKey and the id to check
* Delivers count of loginValidationKey occurence 0 for none 1+ for more
*/
pqxx::result executePreparedStatement_SELECT_CHECK_FREELANCER_LOGIN_STATE(pqxx::connection &connection, const std::string& freelancerEmail, const std::string& loginKey) {
connection.prepare(PREPARED_STATEMENT_SELECT_CHECK_FREELANCER_LOGIN_STATE, SQL_STATEMENT_SELECT_CHECK_FREELANCER_LOGIN_STATE);
pqxx::work work(connection);
pqxx::result result = work.exec_prepared(PREPARED_STATEMENT_SELECT_CHECK_FREELANCER_LOGIN_STATE, freelancerEmail, loginKey);
work.commit();
connection.unprepare(PREPARED_STATEMENT_SELECT_CHECK_FREELANCER_LOGIN_STATE);
return result;
}