diff --git a/src/database.cpp b/src/database.cpp index dabbdf6..1e33ce0 100644 --- a/src/database.cpp +++ b/src/database.cpp @@ -136,6 +136,14 @@ namespace Database { */ const static std::string PREPARED_STATEMENT_SELECT_CHECK_FREELANCER_RESET_KEY_EXPIRED = "checkFreelancerResetKeyExpired"; const static std::string SQL_STATEMENT_SELECT_CHECK_FREELANCER_RESET_KEY_EXPIRED = "select count(*) from passwordresetkeys where passwordresetkey = $1 and expiration <= CURRENT_TIMESTAMP;"; + + /* + * Name and Statement for prepared statement to create new reset key + * $1 = email, $2 = resetkey + */ + const static std::string PREPARED_STATEMENT_INSERT_FREELANCER_RESET_KEY = "insertFreelancerResetKey"; + const static std::string SQL_STATEMENT_INSERT_FREELANCER_RESET_KEY = "insert into passwordresetkeys values ($1, $2, CURRENT_TIMESTAMP);"; + /* * Statement to remove expired reset keys */ @@ -591,6 +599,19 @@ namespace Database { return result; } + + /* + * Creates a new entry for a password reset key for a freelancer + * Takes an open pqxx::connection the freelancers email and the password reset key + */ + void executePreparedStatement_INSERT_FREELANCER_RESET_KEY(pqxx::connection &connection, const std::string& freelancerEmail, const std::string& passwordResetKey) { + connection.prepare(PREPARED_STATEMENT_INSERT_FREELANCER_RESET_KEY, SQL_STATEMENT_INSERT_FREELANCER_RESET_KEY); + pqxx::work work(connection); + work.exec_prepared(PREPARED_STATEMENT_INSERT_FREELANCER_RESET_KEY, freelancerEmail, passwordResetKey); + work.commit(); + connection.unprepare(PREPARED_STATEMENT_INSERT_FREELANCER_RESET_KEY); + } + /* * parses the result and returns a JSON * Takes a result and optionally the desired row