Extract ring creation function

This commit is contained in:
Stanislas Dolcini 2018-10-06 15:04:58 +02:00
parent 436bfd0c36
commit 6aca9390fa

View file

@ -49,6 +49,25 @@ class ConnectionHandler
return $salt; 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) private function Login($login, $password, $clientApplication, $cp, $submittedLang)
{ {
$res = false; $res = false;
@ -63,18 +82,7 @@ class ConnectionHandler
// if we need to create missing ring info // if we need to create missing ring info
if ($AutoCreateRingInfo) { if ($AutoCreateRingInfo) {
// check if the ring user exist, and create it if not CreateRing($domainInfo);
$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)));
}
} }
// store the web host for this domain // store the web host for this domain