From 761d7b2775c34c8c2241eb3b32cc7445a31e6158 Mon Sep 17 00:00:00 2001 From: Quitta Date: Thu, 20 Jun 2013 01:02:27 +0200 Subject: [PATCH] Register seems to work :) Next step permissions and login --HG-- branch : quitta-gsoc-2013 --- .../ryzom_ams/ams_lib/autoload/users.php | 57 ++++++++++++++++ .../tools/server/ryzom_ams/www/config.php | 18 +++-- .../ryzom_ams/www/html/inc/add_user.php | 66 ++++++++----------- 3 files changed, 97 insertions(+), 44 deletions(-) diff --git a/code/ryzom/tools/server/ryzom_ams/ams_lib/autoload/users.php b/code/ryzom/tools/server/ryzom_ams/ams_lib/autoload/users.php index 3c9a64ece..2bd042f74 100644 --- a/code/ryzom/tools/server/ryzom_ams/ams_lib/autoload/users.php +++ b/code/ryzom/tools/server/ryzom_ams/ams_lib/autoload/users.php @@ -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; + } + + } } diff --git a/code/ryzom/tools/server/ryzom_ams/www/config.php b/code/ryzom/tools/server/ryzom_ams/www/config.php index db2571b3a..8a6728dd6 100644 --- a/code/ryzom/tools/server/ryzom_ams/www/config.php +++ b/code/ryzom/tools/server/ryzom_ams/www/config.php @@ -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 diff --git a/code/ryzom/tools/server/ryzom_ams/www/html/inc/add_user.php b/code/ryzom/tools/server/ryzom_ams/www/html/inc/add_user.php index 38e90efeb..81639130f 100644 --- a/code/ryzom/tools/server/ryzom_ams/www/html/inc/add_user.php +++ b/code/ryzom/tools/server/ryzom_ams/www/html/inc/add_user.php @@ -31,50 +31,36 @@ function add_user(){ function write_user($newUser){ - $login = $newUser["name"]; - $pass = $newUser["pass"]; - $email = $newUser["mail"]; - - $salt = Users::generateSALT(); - $hashpass = crypt($pass, $salt); - - $params = array( - $login, - $hashpass, - $email - ); + global $WEBDBHOST; + global $WEBDBPORT; + global $WEBDBNAME; + global $WEBDBUSERNAME; + global $WEBDBPASSWORD; + global $SHARDDBHOST; + global $SHARDDBPORT; + global $SHARDDBNAME; + global $SHARDDBUSERNAME; + global $SHARDDBPASSWORD; - $result = Users :: create_Server_User($params); - //test purpose - $result = "fail"; + $values["name"] = $newUser["name"]; + $values["pass"] = $newUser["pass"]; + $values["mail"] = $newUser["mail"]; - $hostname = 'localhost'; - $port = '3306'; - $dbname = 'ryzom_ams'; - $username = 'shard'; - $password = ''; + $values["webhost"] = $WEBDBHOST; + $values["webport"] = $WEBDBPORT; + $values["webdbname"] = $WEBDBNAME; + $values["webusername"] = $WEBDBUSERNAME; + $values["webpassword"] = $WEBDBPASSWORD ; + + $values["shardhost"] = $SHARDDBHOST; + $values["shardport"] = $SHARDDBPORT; + $values["sharddbname"] = $SHARDDBNAME; + $values["shardusername"] = $SHARDDBUSERNAME; + $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'); }