Register seems to work :) Next step permissions and login

--HG--
branch : quitta-gsoc-2013
hg/feature/sse2
Quitta 12 years ago
parent 4f822c37fe
commit 761d7b2775

@ -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);
//test purpose
$result = "fail";
$hostname = 'localhost'; $values["shardhost"] = $SHARDDBHOST;
$port = '3306'; $values["shardport"] = $SHARDDBPORT;
$dbname = 'ryzom_ams'; $values["sharddbname"] = $SHARDDBNAME;
$username = 'shard'; $values["shardusername"] = $SHARDDBUSERNAME;
$password = ''; $values["shardpassword"] = $SHARDDBPASSWORD;
$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;
}
$result = Users :: createUser($values);
// add user locally here
print('Awesome'); print('Awesome');
} }

Loading…
Cancel
Save