From 4f822c37fe1056579ceb5e7dd62276e934cb188f Mon Sep 17 00:00:00 2001 From: Quitta Date: Wed, 19 Jun 2013 23:53:53 +0200 Subject: [PATCH] first attempt to get register up and running --HG-- branch : quitta-gsoc-2013 --- .../ryzom_ams/ams_lib/autoload/users.php | 23 ++++++++- .../ryzom_ams/www/html/inc/add_user.php | 49 +++++++++++++++++-- .../server/ryzom_ams/www/html/sql/db.sql | 18 +++++++ 3 files changed, 85 insertions(+), 5 deletions(-) create mode 100644 code/ryzom/tools/server/ryzom_ams/www/html/sql/db.sql 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 69dd98ccc..3c9a64ece 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 @@ -234,6 +234,27 @@ class Users{ } // done! return $salt; - } } + + function create_Server_User($params) + { + try { + $hostname = 'localhost'; + $port = '3306'; + $dbname = 'nel'; + $username = 'shard'; + $password = ''; + $dbh = new PDO("mysql:host=$hostname;port=$port;dbname=$dbname", $username, $password); + $dbh->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); + $statement = $dbh->prepare("INSERT INTO user (Login, Password, Email) VALUES (?, ?, ?)"); + $statement->execute($params); + return "success"; + } + catch (PDOException $e) { + return "fail"; + } + // createPermissions(array($login)); + } +} + 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 96b90acb4..38e90efeb 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 @@ -12,7 +12,7 @@ function add_user(){ 'init' => $_POST["Email"], 'unhashpass' => $_POST["Password"], 'status' => 1, - 'access' => REQUEST_TIME + 'access' => $_SERVER['REQUEST_TIME'] ); //header( 'Location: email_sent.php' ); write_user( $edit ); @@ -30,9 +30,50 @@ function add_user(){ } -function write_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 + ); + + $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; + } + + // add user locally here print('Awesome'); } diff --git a/code/ryzom/tools/server/ryzom_ams/www/html/sql/db.sql b/code/ryzom/tools/server/ryzom_ams/www/html/sql/db.sql new file mode 100644 index 000000000..5c8864545 --- /dev/null +++ b/code/ryzom/tools/server/ryzom_ams/www/html/sql/db.sql @@ -0,0 +1,18 @@ +CREATE DATABASE IF NOT EXISTS `ryzom_ams`; +USE `ryzom_ams`; +DROP TABLE IF EXISTS ams_user; +DROP TABLE IF EXISTS ams_querycache; + +CREATE TABLE IF NOT EXISTS `ams_user` ( + `UId` int(10) NOT NULL AUTO_INCREMENT, + `Login` varchar(64) NOT NULL DEFAULT '', + `Password` varchar(13) DEFAULT NULL, + `Email` varchar(255) NOT NULL DEFAULT '', + PRIMARY KEY (`UId`) +) ENGINE=MyISAM DEFAULT CHARSET=latin1 COMMENT='contains all users information for ryzom_ams'; + +CREATE TABLE ams_querycache ( + `SID` INT NOT NULL AUTO_INCREMENT PRIMARY KEY , + `type` VARCHAR( 64 ) NOT NULL , + `query` VARCHAR( 512 ) NOT NULL +); \ No newline at end of file