diff --git a/src/database.cpp b/src/database.cpp index 46c6f37..624fee4 100644 --- a/src/database.cpp +++ b/src/database.cpp @@ -124,6 +124,11 @@ namespace Database { const static std::string PREPARED_STATEMENT_SELECT_CHECK_FREELANCER_RESET_KEY = "checkFreelancerResetKey"; const static std::string SQL_STATEMENT_SELECT_CHECK_FREELANCER_RESET_KEY = "select count(*) from passwordresetkeys where freelanceremail = $1;"; + /* + * Name and Statement for prepared statement to select a freelancers emailaddress based on a given password reset key + */ + const static std::string PREPARED_STATEMENT_SELECT_FREELANCER_EMAIL_FROM_PASSWORD_RESET_KEY = "selectFreelancerEmailAddressFromPasswordResetKeys"; + const static std::string SQL_STATEMENT_SELECT_FREELANCER_EMAIL_FROM_PASSWORD_RESET_KEY = "select freelanceremail from passwordresetkeys where passwordresetkey = $1;"; /* * Statement to remove expired reset keys @@ -551,6 +556,20 @@ namespace Database { connection.unprepare(PREPARED_STATEMENT_SELECT_CHECK_FREELANCER_RESET_KEY); return result; } + /* + * Executes the prepared statement SELECT_FREELANCER_EMAIL_FROM_PASSWORD_RESET_KEY + * Takes an open pqxx::connection and the password reset key + * returns email if reset key exists + */ + pqxx::result executePreparedStatement_SELECT_FREELANCER_EMAIL_FROM_PASSWORD_RESET_KEY(pqxx::connection &connection, const std::string& passwordResetKey) { + connection.prepare(PREPARED_STATEMENT_SELECT_FREELANCER_EMAIL_FROM_PASSWORD_RESET_KEY, SQL_STATEMENT_SELECT_FREELANCER_EMAIL_FROM_PASSWORD_RESET_KEY); + pqxx::work work(connection); + pqxx::result result = work.exec_prepared(PREPARED_STATEMENT_SELECT_FREELANCER_EMAIL_FROM_PASSWORD_RESET_KEY, passwordResetKey); + work.commit(); + connection.unprepare(PREPARED_STATEMENT_SELECT_FREELANCER_EMAIL_FROM_PASSWORD_RESET_KEY); + return result; + } + /* * parses the result and returns a JSON * Takes a result and optionally the desired row