Register seems to work :) Next step permissions and login
This commit is contained in:
parent
e7f8d1dbcb
commit
ec4b3818a5
3 changed files with 97 additions and 44 deletions
|
@ -255,6 +255,63 @@ class Users{
|
||||||
}
|
}
|
||||||
// createPermissions(array($login));
|
// createPermissions(array($login));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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"];
|
||||||
|
|
||||||
|
$shardhost = $values["shardhost"];
|
||||||
|
$shardport = $values["shardport"];
|
||||||
|
$sharddbname = $values["sharddbname"];
|
||||||
|
$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 (?, ?, ?)");
|
||||||
|
$statement->execute($params);
|
||||||
|
}
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -5,10 +5,20 @@
|
||||||
// Variables for database access
|
// Variables for database access
|
||||||
// ----------------------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------------------
|
||||||
// where we can find the mysql database
|
// where we can find the mysql database
|
||||||
$DBHOST = 'localhost' ;
|
|
||||||
$DBNAME = 'nel' ;
|
$WEBDBHOST = 'localhost';
|
||||||
$DBUSERNAME = 'shard' ;
|
$WEBDBPORT = '3306';
|
||||||
$DBPASSWORD = '' ;
|
$WEBDBNAME = 'ryzom_ams';
|
||||||
|
$WEBDBUSERNAME = 'shard';
|
||||||
|
$WEBDBPASSWORD = '' ;
|
||||||
|
|
||||||
|
$SHARDDBHOST = 'localhost' ;
|
||||||
|
$SHARDDBPORT = '3306';
|
||||||
|
$SHARDDBNAME = 'nel' ;
|
||||||
|
$SHARDDBUSERNAME = 'shard' ;
|
||||||
|
$SHARDDBPASSWORD = '' ;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// If true= the server will add automatically unknown user in the database
|
// If true= the server will add automatically unknown user in the database
|
||||||
// (in nel.user= nel.permission= ring.ring_user and ring.characters
|
// (in nel.user= nel.permission= ring.ring_user and ring.characters
|
||||||
|
|
|
@ -31,50 +31,36 @@ function add_user(){
|
||||||
|
|
||||||
|
|
||||||
function write_user($newUser){
|
function write_user($newUser){
|
||||||
$login = $newUser["name"];
|
global $WEBDBHOST;
|
||||||
$pass = $newUser["pass"];
|
global $WEBDBPORT;
|
||||||
$email = $newUser["mail"];
|
global $WEBDBNAME;
|
||||||
|
global $WEBDBUSERNAME;
|
||||||
|
global $WEBDBPASSWORD;
|
||||||
|
global $SHARDDBHOST;
|
||||||
|
global $SHARDDBPORT;
|
||||||
|
global $SHARDDBNAME;
|
||||||
|
global $SHARDDBUSERNAME;
|
||||||
|
global $SHARDDBPASSWORD;
|
||||||
|
|
||||||
$salt = Users::generateSALT();
|
$values["name"] = $newUser["name"];
|
||||||
$hashpass = crypt($pass, $salt);
|
$values["pass"] = $newUser["pass"];
|
||||||
|
$values["mail"] = $newUser["mail"];
|
||||||
|
|
||||||
$params = array(
|
$values["webhost"] = $WEBDBHOST;
|
||||||
$login,
|
$values["webport"] = $WEBDBPORT;
|
||||||
$hashpass,
|
$values["webdbname"] = $WEBDBNAME;
|
||||||
$email
|
$values["webusername"] = $WEBDBUSERNAME;
|
||||||
);
|
$values["webpassword"] = $WEBDBPASSWORD ;
|
||||||
|
|
||||||
$result = Users :: create_Server_User($params);
|
$values["shardhost"] = $SHARDDBHOST;
|
||||||
//test purpose
|
$values["shardport"] = $SHARDDBPORT;
|
||||||
$result = "fail";
|
$values["sharddbname"] = $SHARDDBNAME;
|
||||||
|
$values["shardusername"] = $SHARDDBUSERNAME;
|
||||||
$hostname = 'localhost';
|
$values["shardpassword"] = $SHARDDBPASSWORD;
|
||||||
$port = '3306';
|
|
||||||
$dbname = 'ryzom_ams';
|
|
||||||
$username = 'shard';
|
|
||||||
$password = '';
|
|
||||||
|
|
||||||
$dbh = new PDO("mysql:host=$hostname;port=$port;dbname=$dbname", $username, $password);
|
|
||||||
$dbh->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
|
|
||||||
try {
|
|
||||||
$statement = $dbh->prepare("INSERT INTO ams_user (Login, Password, Email) VALUES (?, ?, ?)");
|
|
||||||
$statement->execute($params);
|
|
||||||
|
|
||||||
if($result == "fail"){
|
|
||||||
print('so far');
|
|
||||||
$params = array("type" => "createUser","query" => json_encode(array($login,$pass,$email)));
|
|
||||||
$statement = $dbh->prepare("INSERT INTO ams_querycache (type, query) VALUES (:type, :query)");
|
|
||||||
$statement->execute($params);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
catch (PDOException $e) {
|
|
||||||
//go to error page or something
|
|
||||||
print_r($e);
|
|
||||||
exit;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// add user locally here
|
$result = Users :: createUser($values);
|
||||||
|
|
||||||
print('Awesome');
|
print('Awesome');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue