From 696f8f724fc68deea747bc45f9fe7b7debfc74ea Mon Sep 17 00:00:00 2001 From: Chris-bot374 Date: Sat, 6 Jul 2024 10:10:57 +0200 Subject: [PATCH] Update DBLogin.cpp --- DBHandler/DBLogin.cpp | 33 +++++++++++++++++---------------- 1 file changed, 17 insertions(+), 16 deletions(-) diff --git a/DBHandler/DBLogin.cpp b/DBHandler/DBLogin.cpp index e942725..344e8b0 100644 --- a/DBHandler/DBLogin.cpp +++ b/DBHandler/DBLogin.cpp @@ -11,30 +11,31 @@ return 1 if admin | 0 if not admin | -1 if failed */ -int DBLogin::checkValidLogin(int id, std::string pw) { - +int DBLogin::checkValidLogin(std::string id, std::string pw) { + try { - pqxx::work worker(connectionObject); + pqxx::work worker(connectionObject); - std::string query = - "SELECT admin FROM studenten_veranstalterr WHERE id = $1 AND passwort = $2"; + std::string query = + "SELECT admin FROM studenten_veranstalter WHERE id = $1 AND passwort = $2"; - pqxx::result response = worker.exec_params(query, id, pw); + pqxx::result response = worker.exec_params(query, id, pw); - if (response.affected_rows() > 0) { + if (response.affected_rows() > 0) { - std::cout << response[0][0] << std::endl; - if (response[0][0].is_null()) - return 0; - return response[0][0].as(); + + if (response[0][0].is_null()) + return 0; + return response[0][0].as(); + } + + return -1; + } + catch (const std::exception& e) { + std::cerr << "Error: " << e.what() << std::endl; } - return -1; -} -catch (const std::exception& e) { - std::cerr << "Error: " << e.what() << std::endl; } -}