|
|
|
@ -257,15 +257,12 @@ class Users{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function createUser($values){
|
|
|
|
|
$login = $values["name"];
|
|
|
|
|
$pass = $values["pass"];
|
|
|
|
|
$email = $values["mail"];
|
|
|
|
|
|
|
|
|
|
$webhost = $values["webhost"];
|
|
|
|
|
$webport = $values["webport"];
|
|
|
|
|
$webdbname = $values["webdbname"];
|
|
|
|
|
$webusername = $values["webusername"];
|
|
|
|
|
$webpassword = $values["webpassword"];
|
|
|
|
|
$libhost = $values["libhost"];
|
|
|
|
|
$libport = $values["libport"];
|
|
|
|
|
$libdbname = $values["libdbname"];
|
|
|
|
|
$libusername = $values["libusername"];
|
|
|
|
|
$libpassword = $values["libpassword"];
|
|
|
|
|
|
|
|
|
|
$shardhost = $values["shardhost"];
|
|
|
|
|
$shardport = $values["shardport"];
|
|
|
|
@ -273,84 +270,31 @@ class Users{
|
|
|
|
|
$shardusername = $values["shardusername"];
|
|
|
|
|
$shardpassword = $values["shardpassword"];
|
|
|
|
|
|
|
|
|
|
$salt = Users::generateSALT();
|
|
|
|
|
$hashpass = crypt($pass, $salt);
|
|
|
|
|
|
|
|
|
|
$params = array(
|
|
|
|
|
$login,
|
|
|
|
|
$hashpass,
|
|
|
|
|
$email
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
try{
|
|
|
|
|
//make connection with web db
|
|
|
|
|
$dbw = new PDO("mysql:host=$webhost;port=$webport;dbname=$webdbname", $webusername, $webpassword);
|
|
|
|
|
$dbw->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
|
|
|
|
|
|
|
|
|
|
//put into web db
|
|
|
|
|
$statement = $dbw->prepare("INSERT INTO ams_user (Login, Password, Email) VALUES (?, ?, ?)");
|
|
|
|
|
$statement->execute($params);
|
|
|
|
|
try {
|
|
|
|
|
//make connection with and put into shard db
|
|
|
|
|
$dbs = new PDO("mysql:host=$shardhost;port=$shardport;dbname=$sharddbname", $shardusername, $shardpassword);
|
|
|
|
|
$dbs->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
|
|
|
|
|
$statement = $dbs->prepare("INSERT INTO user (Login, Password, Email) VALUES (:name, :pass, :mail)");
|
|
|
|
|
$statement->execute($values["params"]);
|
|
|
|
|
return "ok";
|
|
|
|
|
}
|
|
|
|
|
catch (PDOException $e) {
|
|
|
|
|
//oh noooz, the shard is offline! Put in query queue at ams_lib db!
|
|
|
|
|
try {
|
|
|
|
|
//make connection with and put into shard db
|
|
|
|
|
$dbs = new PDO("mysql:host=$shardhost;port=$shardport;dbname=$sharddbname", $shardusername, $shardpassword);
|
|
|
|
|
$dbs->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
|
|
|
|
|
$statement = $dbs->prepare("INSERT INTO user (Login, Password, Email) VALUES (?, ?, ?)");
|
|
|
|
|
$dbl = new PDO("mysql:host=$libhost;port=$libport;dbname=$libdbname", $libusername, $libpassword);
|
|
|
|
|
$dbl->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
|
|
|
|
|
$params = array("type" => "createUser","query" => json_encode(array($values["params"]["name"],$values["params"]["pass"],$values["params"]["mail"])));
|
|
|
|
|
$statement = $dbl->prepare("INSERT INTO ams_querycache (type, query) VALUES (:type, :query)");
|
|
|
|
|
$statement->execute($params);
|
|
|
|
|
return "shardoffline";
|
|
|
|
|
}catch (PDOException $e) {
|
|
|
|
|
print_r($e);
|
|
|
|
|
return "liboffline";
|
|
|
|
|
}
|
|
|
|
|
catch (PDOException $e) {
|
|
|
|
|
//print_r($e);
|
|
|
|
|
//oh noooz, the shard is offline! Put in query queue at web db!
|
|
|
|
|
$params = array("type" => "createUser","query" => json_encode(array($login,$pass,$email)));
|
|
|
|
|
$statement = $dbw->prepare("INSERT INTO ams_querycache (type, query) VALUES (:type, :query)");
|
|
|
|
|
$statement->execute($params);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}catch (PDOException $e) {
|
|
|
|
|
//go to error page or something, because can't access website db
|
|
|
|
|
print_r($e);
|
|
|
|
|
exit;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function login($params){
|
|
|
|
|
$webhost = $params["webhost"];
|
|
|
|
|
$webport = $params["webport"];
|
|
|
|
|
$webdbname = $params["webdbname"];
|
|
|
|
|
$webusername = $params["webusername"];
|
|
|
|
|
$webpassword = $params["webpassword"];
|
|
|
|
|
|
|
|
|
|
try{
|
|
|
|
|
$dbw = new PDO("mysql:host=$webhost;port=$webport;dbname=$webdbname", $webusername, $webpassword);
|
|
|
|
|
$dbw->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
|
|
|
|
|
|
|
|
|
|
$statement = $dbw->prepare("SELECT * FROM ams_user WHERE Login=:user");
|
|
|
|
|
$statement->execute(array('user' => $params['name']));
|
|
|
|
|
$count = $statement->rowCount();
|
|
|
|
|
|
|
|
|
|
if ($count==1) {
|
|
|
|
|
$row = $statement->fetch();
|
|
|
|
|
$salt = substr($row['Password'],0,2);
|
|
|
|
|
$hashed_input_pass = crypt($params["pass"], $salt);
|
|
|
|
|
if($hashed_input_pass == $row['Password']){
|
|
|
|
|
//handle successful login
|
|
|
|
|
print("nice welcome!");
|
|
|
|
|
$_SESSION['user'] = $params['name'];
|
|
|
|
|
$_SESSION['permission'] = $row['Permission'];
|
|
|
|
|
print( $_SESSION['user']);
|
|
|
|
|
return "success";
|
|
|
|
|
}else{
|
|
|
|
|
//handle login failure
|
|
|
|
|
print("Login failed");
|
|
|
|
|
return "failure";
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}catch (PDOException $e) {
|
|
|
|
|
//go to error page or something, because can't access website db
|
|
|
|
|
print_r($e);
|
|
|
|
|
exit;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|