From 6aca9390fa35d9b9cdfba85838b303cdcdef49fe Mon Sep 17 00:00:00 2001 From: Stanislas Dolcini Date: Sat, 6 Oct 2018 15:04:58 +0200 Subject: [PATCH] Extract ring creation function --- .../login/class/connection_handler.php | 32 ++++++++++++------- 1 file changed, 20 insertions(+), 12 deletions(-) diff --git a/code/web/public_php/login/class/connection_handler.php b/code/web/public_php/login/class/connection_handler.php index 7124cf94f..12a8d12e3 100644 --- a/code/web/public_php/login/class/connection_handler.php +++ b/code/web/public_php/login/class/connection_handler.php @@ -49,6 +49,25 @@ class ConnectionHandler return $salt; } + /** + * Create the db ring. + * @todo: currently broken, because it uses globals. + */ + private function CreateRing($domainInfo) + { // check if the ring user exist, and create it if not + // $ringDb = mysqli_connect($DBHost, $RingDBUserName, $RingDBPassword) or die(errorMsgBlock(3004, 'Ring', $DBHost, $RingDBUserName)); + // mysqli_select_db($ringDb, $domainInfo['ring_db_name']) or die(errorMsgBlock(3005, 'Ring', $domainInfo['ring_db_name'], $DBHost, $RingDBUserName)); + // $query = "SELECT user_id FROM ring_users where user_id = '" . $id . "'"; + // $result = mysqli_query($ringDb, $query) or die(errorMsgBlock(3006, $query, 'Ring', $domainInfo['ring_db_name'], $DBHost, $RingDBUserName, mysqli_error($ringDb))); + + // if (mysqli_num_rows($result) == 0) { + // // no ring user record, build one + // $login = mysqli_real_escape_string($ringDb, $_GET['login']); + // $query = "INSERT INTO ring_users SET user_id = '$id', user_name = '$login', user_type='ut_pioneer'"; + // $result = mysqli_query($ringDb, $query) or die(errorMsgBlock(3006, $query, 'Ring', $domainInfo['ring_db_name'], $DBHost, $RingDBUserName, mysqli_error($ringDb))); + // } + } + private function Login($login, $password, $clientApplication, $cp, $submittedLang) { $res = false; @@ -63,18 +82,7 @@ class ConnectionHandler // if we need to create missing ring info if ($AutoCreateRingInfo) { - // check if the ring user exist, and create it if not - $ringDb = mysqli_connect($DBHost, $RingDBUserName, $RingDBPassword) or die(errorMsgBlock(3004, 'Ring', $DBHost, $RingDBUserName)); - mysqli_select_db($ringDb, $domainInfo['ring_db_name']) or die(errorMsgBlock(3005, 'Ring', $domainInfo['ring_db_name'], $DBHost, $RingDBUserName)); - $query = "SELECT user_id FROM ring_users where user_id = '" . $id . "'"; - $result = mysqli_query($ringDb, $query) or die(errorMsgBlock(3006, $query, 'Ring', $domainInfo['ring_db_name'], $DBHost, $RingDBUserName, mysqli_error($ringDb))); - - if (mysqli_num_rows($result) == 0) { - // no ring user record, build one - $login = mysqli_real_escape_string($ringDb, $_GET['login']); - $query = "INSERT INTO ring_users SET user_id = '$id', user_name = '$login', user_type='ut_pioneer'"; - $result = mysqli_query($ringDb, $query) or die(errorMsgBlock(3006, $query, 'Ring', $domainInfo['ring_db_name'], $DBHost, $RingDBUserName, mysqli_error($ringDb))); - } + CreateRing($domainInfo); } // store the web host for this domain