Register seems to work :) Next step permissions and login
--HG-- branch : quitta-gsoc-2013
This commit is contained in:
parent
4f822c37fe
commit
761d7b2775
3 changed files with 97 additions and 44 deletions
|
@ -255,6 +255,63 @@ class Users{
|
|||
}
|
||||
// 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
|
||||
// ----------------------------------------------------------------------------------------
|
||||
// where we can find the mysql database
|
||||
$DBHOST = 'localhost' ;
|
||||
$DBNAME = 'nel' ;
|
||||
$DBUSERNAME = 'shard' ;
|
||||
$DBPASSWORD = '' ;
|
||||
|
||||
$WEBDBHOST = 'localhost';
|
||||
$WEBDBPORT = '3306';
|
||||
$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
|
||||
// (in nel.user= nel.permission= ring.ring_user and ring.characters
|
||||
|
|
|
@ -31,50 +31,36 @@ function add_user(){
|
|||
|
||||
|
||||
function write_user($newUser){
|
||||
$login = $newUser["name"];
|
||||
$pass = $newUser["pass"];
|
||||
$email = $newUser["mail"];
|
||||
global $WEBDBHOST;
|
||||
global $WEBDBPORT;
|
||||
global $WEBDBNAME;
|
||||
global $WEBDBUSERNAME;
|
||||
global $WEBDBPASSWORD;
|
||||
global $SHARDDBHOST;
|
||||
global $SHARDDBPORT;
|
||||
global $SHARDDBNAME;
|
||||
global $SHARDDBUSERNAME;
|
||||
global $SHARDDBPASSWORD;
|
||||
|
||||
$salt = Users::generateSALT();
|
||||
$hashpass = crypt($pass, $salt);
|
||||
$values["name"] = $newUser["name"];
|
||||
$values["pass"] = $newUser["pass"];
|
||||
$values["mail"] = $newUser["mail"];
|
||||
|
||||
$params = array(
|
||||
$login,
|
||||
$hashpass,
|
||||
$email
|
||||
);
|
||||
$values["webhost"] = $WEBDBHOST;
|
||||
$values["webport"] = $WEBDBPORT;
|
||||
$values["webdbname"] = $WEBDBNAME;
|
||||
$values["webusername"] = $WEBDBUSERNAME;
|
||||
$values["webpassword"] = $WEBDBPASSWORD ;
|
||||
|
||||
$result = Users :: create_Server_User($params);
|
||||
//test purpose
|
||||
$result = "fail";
|
||||
|
||||
$hostname = 'localhost';
|
||||
$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;
|
||||
}
|
||||
$values["shardhost"] = $SHARDDBHOST;
|
||||
$values["shardport"] = $SHARDDBPORT;
|
||||
$values["sharddbname"] = $SHARDDBNAME;
|
||||
$values["shardusername"] = $SHARDDBUSERNAME;
|
||||
$values["shardpassword"] = $SHARDDBPASSWORD;
|
||||
|
||||
|
||||
// add user locally here
|
||||
$result = Users :: createUser($values);
|
||||
|
||||
print('Awesome');
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue