From fc7bab9506a449b72b6083ba150851954324b1c6 Mon Sep 17 00:00:00 2001 From: Quitta Date: Wed, 26 Jun 2013 03:26:25 +0200 Subject: [PATCH 1/4] Reworked register --- .../ryzom_ams/ams_lib/autoload/users.php | 72 +++++++------------ .../tools/server/ryzom_ams/www/config.php | 19 +++-- .../ryzom_ams/www/html/inc/add_user.php | 48 ++++++++++--- .../tools/server/ryzom_ams/www/html/index.php | 10 ++- .../server/ryzom_ams/www/html/sql/db.sql | 7 +- .../server/ryzom_ams/www/html/sql/install.php | 65 +++++++++++++++++ 6 files changed, 155 insertions(+), 66 deletions(-) create mode 100644 code/ryzom/tools/server/ryzom_ams/www/html/sql/install.php 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 731eb5cdd..cc42c8f86 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 @@ -257,15 +257,12 @@ class Users{ } 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"]; + $libhost = $values["libhost"]; + $libport = $values["libport"]; + $libdbname = $values["libdbname"]; + $libusername = $values["libusername"]; + $libpassword = $values["libpassword"]; $shardhost = $values["shardhost"]; $shardport = $values["shardport"]; @@ -273,44 +270,29 @@ class Users{ $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; + try { + //make connection with and put into shard db + $dbs = new PDO("mysql:host='127.0.39.3';port=$shardport;dbname=$sharddbname", $shardusername, $shardpassword); + $dbs->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); + $statement = $dbs->prepare("INSERT INTO user (Login, Password, Email) VALUES (:name, :pass, :mail)"); + $statement->execute($values["params"]); + return "ok"; } - + catch (PDOException $e) { + //oh noooz, the shard is offline! Put in query queue at ams_lib db! + try { + $dbl = new PDO("mysql:host=$libhost;port=$libport;dbname=$libdbname", $libusername, $libpassword); + $dbl->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); + $params = array("type" => "createUser","query" => json_encode(array($values["params"]["name"],$values["params"]["pass"],$values["params"]["mail"]))); + $statement = $dbl->prepare("INSERT INTO ams_querycache (type, query) VALUES (:type, :query)"); + $statement->execute($params); + return "shardoffline"; + }catch (PDOException $e) { + print_r($e); + return "liboffline"; + } + } + } public function login($params){ diff --git a/code/ryzom/tools/server/ryzom_ams/www/config.php b/code/ryzom/tools/server/ryzom_ams/www/config.php index 8a6728dd6..747ae8414 100644 --- a/code/ryzom/tools/server/ryzom_ams/www/config.php +++ b/code/ryzom/tools/server/ryzom_ams/www/config.php @@ -5,21 +5,30 @@ // Variables for database access // ---------------------------------------------------------------------------------------- // where we can find the mysql database +//----------------------------------------------------------------------------------------- +//the www db $WEBDBHOST = 'localhost'; $WEBDBPORT = '3306'; $WEBDBNAME = 'ryzom_ams'; -$WEBDBUSERNAME = 'shard'; -$WEBDBPASSWORD = '' ; - +$WEBDBUSERNAME = 'root'; +$WEBDBPASSWORD = 'lol123' ; + +//the ams_lib db +$LIBDBHOST = 'localhost'; +$LIBDBPORT = '3306'; +$LIBDBNAME = 'ryzom_ams_lib'; +$LIBDBUSERNAME = 'root'; +$LIBDBPASSWORD = 'lol123' ; + +//the shard db $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 $ALLOW_UNKNOWN = true ; 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 81639130f..8a13a8614 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,26 +31,43 @@ function add_user(){ function write_user($newUser){ + + //get the db specifics out of the config file global $WEBDBHOST; global $WEBDBPORT; global $WEBDBNAME; global $WEBDBUSERNAME; global $WEBDBPASSWORD; + + global $LIBDBHOST; + global $LIBDBPORT; + global $LIBDBNAME; + global $LIBDBUSERNAME; + global $LIBDBPASSWORD; + global $SHARDDBHOST; global $SHARDDBPORT; global $SHARDDBNAME; global $SHARDDBUSERNAME; global $SHARDDBPASSWORD; - $values["name"] = $newUser["name"]; - $values["pass"] = $newUser["pass"]; - $values["mail"] = $newUser["mail"]; + //create salt here, because we want it to be the same on the web/server + $hashpass = crypt($newUser["pass"], Users::generateSALT()); - $values["webhost"] = $WEBDBHOST; - $values["webport"] = $WEBDBPORT; - $values["webdbname"] = $WEBDBNAME; - $values["webusername"] = $WEBDBUSERNAME; - $values["webpassword"] = $WEBDBPASSWORD ; + $params = array( + 'name' => $newUser["name"], + 'pass' => $hashpass, + 'mail' => $newUser["mail"] + ); + + //print_r($params); + //make a $values array for passing all data to the Users::createUser() function. + $values["params"] = $params; + $values["libhost"] = $LIBDBHOST; + $values["libport"] = $LIBDBPORT; + $values["libdbname"] = $LIBDBNAME; + $values["libusername"] = $LIBDBUSERNAME; + $values["libpassword"] = $LIBDBPASSWORD ; $values["shardhost"] = $SHARDDBHOST; $values["shardport"] = $SHARDDBPORT; @@ -59,8 +76,21 @@ function write_user($newUser){ $values["shardpassword"] = $SHARDDBPASSWORD; + //Create the user on the shard + in case shard is offline put copy of query in query db $result = Users :: createUser($values); - + + try{ + //make connection with web db and put it in there + $dbw = new PDO("mysql:host=$WEBDBHOST;port=$WEBDBPORT;dbname=$WEBDBNAME", $WEBDBUSERNAME, $WEBDBPASSWORD); + $dbw->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); + $statement = $dbw->prepare("INSERT INTO ams_user (Login, Password, Email) VALUES (:name, :pass, :mail)"); + $statement->execute($params); + + }catch (PDOException $e) { + //go to error page or something, because can't access website db + print_r($e); + exit; + } print('Awesome'); } diff --git a/code/ryzom/tools/server/ryzom_ams/www/html/index.php b/code/ryzom/tools/server/ryzom_ams/www/html/index.php index d15dbee03..b3749e8a6 100644 --- a/code/ryzom/tools/server/ryzom_ams/www/html/index.php +++ b/code/ryzom/tools/server/ryzom_ams/www/html/index.php @@ -5,7 +5,7 @@ require( '../config.php' ); require( '../../ams_lib/libinclude.php' ); session_start(); -print("[" . $_SESSION['user'] . "] "); +//print_r($_SESSION); //Decide what page to load if(isset($_SESSION['user'])){ @@ -31,8 +31,8 @@ function loadpage ( $page ){ } //Set permission -if(isset($_SESSION['Permission'])){ - $return['permission'] = $_SESSION['Permission']; +if(isset($_SESSION['permission'])){ + $return['permission'] = $_SESSION['permission']; }else{ //default permission $return['permission'] = 0; @@ -45,7 +45,5 @@ if($page == 'login' || $page == 'register'){ }else{ $return['no_visible_elements'] = 'FALSE'; } - +//print_r($return); helpers :: loadTemplate( $page , $return ); - -session_destroy(); 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 index 44daf16e5..ccc214125 100644 --- a/code/ryzom/tools/server/ryzom_ams/www/html/sql/db.sql +++ b/code/ryzom/tools/server/ryzom_ams/www/html/sql/db.sql @@ -1,7 +1,6 @@ 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, @@ -12,6 +11,12 @@ CREATE TABLE IF NOT EXISTS `ams_user` ( PRIMARY KEY (`UId`) ) ENGINE=MyISAM DEFAULT CHARSET=latin1 COMMENT='contains all users information for ryzom_ams'; +); + +CREATE DATABASE IF NOT EXISTS `ryzom_ams_lib`; +USE `ryzom_ams_lib`; +DROP TABLE IF EXISTS ams_querycache; + CREATE TABLE ams_querycache ( `SID` INT NOT NULL AUTO_INCREMENT PRIMARY KEY , `type` VARCHAR( 64 ) NOT NULL , diff --git a/code/ryzom/tools/server/ryzom_ams/www/html/sql/install.php b/code/ryzom/tools/server/ryzom_ams/www/html/sql/install.php new file mode 100644 index 000000000..09ba63d54 --- /dev/null +++ b/code/ryzom/tools/server/ryzom_ams/www/html/sql/install.php @@ -0,0 +1,65 @@ +setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); + $sql = " + CREATE DATABASE IF NOT EXISTS `ryzom_ams`; + USE `ryzom_ams`; + DROP TABLE IF EXISTS ams_user; + + 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 '', + `Permission` int(3) NOT NULL DEFAULT 1, + PRIMARY KEY (`UId`) + ) ENGINE=MyISAM DEFAULT CHARSET=latin1 COMMENT='contains all users information for ryzom_ams'; + + ); + "; + $statement = $dbw->prepare($sql); + $statement->execute(); + + //SETUP THE AMS_LIB DB + $dbl = new PDO("mysql:host=$LIBDBHOST;", $LIBDBUSERNAME, $LIBDBPASSWORD); + $dbl->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); + $sql = " + CREATE DATABASE IF NOT EXISTS `ryzom_ams_lib`; + USE `ryzom_ams_lib`; + DROP TABLE IF EXISTS ams_querycache; + + CREATE TABLE ams_querycache ( + `SID` INT NOT NULL AUTO_INCREMENT PRIMARY KEY , + `type` VARCHAR( 64 ) NOT NULL , + `query` VARCHAR( 512 ) NOT NULL + ); + "; + $statement = $dbl->prepare($sql); + $statement->execute(); + print('Install completed successful!'); + + + + + }catch (PDOException $e) { + //go to error page or something, because can't access website db + print('There was an error while installing'); + print_r($e); + } + + \ No newline at end of file From 8735e2f7e677501e1d1fd6dc5d5eb4eb262c5bbe Mon Sep 17 00:00:00 2001 From: Quitta Date: Wed, 26 Jun 2013 04:03:16 +0200 Subject: [PATCH 2/4] feedback on registering early version, also added an installer.php in the previous revision, forgot to mention that --- .../ryzom_ams/ams_lib/autoload/users.php | 2 +- .../ryzom_ams/ams_lib/translations/en.ini | 7 ++++ .../ryzom_ams/www/html/inc/add_user.php | 12 +++++-- .../www/html/templates/register_feedback.tpl | 33 +++++++++++++++++++ 4 files changed, 50 insertions(+), 4 deletions(-) create mode 100644 code/ryzom/tools/server/ryzom_ams/www/html/templates/register_feedback.tpl 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 cc42c8f86..f2820f468 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 @@ -272,7 +272,7 @@ class Users{ try { //make connection with and put into shard db - $dbs = new PDO("mysql:host='127.0.39.3';port=$shardport;dbname=$sharddbname", $shardusername, $shardpassword); + $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 (:name, :pass, :mail)"); $statement->execute($values["params"]); diff --git a/code/ryzom/tools/server/ryzom_ams/ams_lib/translations/en.ini b/code/ryzom/tools/server/ryzom_ams/ams_lib/translations/en.ini index af9f29d05..24d3dc845 100644 --- a/code/ryzom/tools/server/ryzom_ams/ams_lib/translations/en.ini +++ b/code/ryzom/tools/server/ryzom_ams/ams_lib/translations/en.ini @@ -5,6 +5,13 @@ [login] +[register_feedback] +status_ok = "You registered like a baws!" +status_shardoffline = "It seems the shard is offline, you can use the web-account, but you will need to wait for the shard." +status_liboffline = "You can't register an account at this time" +login_title = "Next step: Login" +login_text = "Click here if you want to log in!" + [register] title = "RYZOM CORE INGAME REGISTRATION" welcome_message = "Welcome! Please fill in the following fields to get your new Ryzom Core account" 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 8a13a8614..64733ddb2 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 @@ -15,7 +15,11 @@ function add_user(){ 'access' => $_SERVER['REQUEST_TIME'] ); //header( 'Location: email_sent.php' ); - write_user( $edit ); + $status = write_user( $edit ); + $pageElements['status'] = $status; + //TODO: perhaps send email! + $pageElements['no_visible_elements'] = 'TRUE'; + helpers :: loadtemplate( 'register_feedback', $pageElements); exit; }else{ // pass error @@ -77,6 +81,7 @@ function write_user($newUser){ //Create the user on the shard + in case shard is offline put copy of query in query db + //returns ok, shardoffline or liboffline $result = Users :: createUser($values); try{ @@ -91,6 +96,7 @@ function write_user($newUser){ print_r($e); exit; } - print('Awesome'); - } + + return $result; +} diff --git a/code/ryzom/tools/server/ryzom_ams/www/html/templates/register_feedback.tpl b/code/ryzom/tools/server/ryzom_ams/www/html/templates/register_feedback.tpl new file mode 100644 index 000000000..43a227eac --- /dev/null +++ b/code/ryzom/tools/server/ryzom_ams/www/html/templates/register_feedback.tpl @@ -0,0 +1,33 @@ +{extends file="layout.tpl"} +{block name=content} + +
+ +
+ +
+ +
+{/block} + From 577d68a6d9777b4c4d6ac8381b115e0589459d52 Mon Sep 17 00:00:00 2001 From: Quitta Date: Wed, 26 Jun 2013 16:35:33 +0200 Subject: [PATCH 3/4] Added logout, refined login and took it back out of the lib. Added timers to forward after 5 seconds after logout & register. Looks good imo --- .../ryzom_ams/ams_lib/autoload/users.php | 38 ---------- .../ryzom_ams/ams_lib/translations/en.ini | 13 +++- .../ryzom_ams/www/html/autoload/logout.php | 7 ++ .../ryzom_ams/www/html/autoload/register.php | 71 ------------------- .../server/ryzom_ams/www/html/inc/login.php | 43 +++++++++++ .../tools/server/ryzom_ams/www/html/index.php | 9 ++- .../www/html/templates/layout_user.tpl | 1 + .../ryzom_ams/www/html/templates/login.tpl | 69 ++++++++++-------- .../ryzom_ams/www/html/templates/logout.tpl | 40 +++++++++++ .../www/html/templates/register_feedback.tpl | 56 +++++++++------ 10 files changed, 183 insertions(+), 164 deletions(-) create mode 100644 code/ryzom/tools/server/ryzom_ams/www/html/autoload/logout.php delete mode 100644 code/ryzom/tools/server/ryzom_ams/www/html/autoload/register.php create mode 100644 code/ryzom/tools/server/ryzom_ams/www/html/inc/login.php create mode 100644 code/ryzom/tools/server/ryzom_ams/www/html/templates/logout.tpl 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 f2820f468..876f8d285 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 @@ -295,44 +295,6 @@ class Users{ } - public function login($params){ - $webhost = $params["webhost"]; - $webport = $params["webport"]; - $webdbname = $params["webdbname"]; - $webusername = $params["webusername"]; - $webpassword = $params["webpassword"]; - - try{ - $dbw = new PDO("mysql:host=$webhost;port=$webport;dbname=$webdbname", $webusername, $webpassword); - $dbw->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); - - $statement = $dbw->prepare("SELECT * FROM ams_user WHERE Login=:user"); - $statement->execute(array('user' => $params['name'])); - $count = $statement->rowCount(); - - if ($count==1) { - $row = $statement->fetch(); - $salt = substr($row['Password'],0,2); - $hashed_input_pass = crypt($params["pass"], $salt); - if($hashed_input_pass == $row['Password']){ - //handle successful login - print("nice welcome!"); - $_SESSION['user'] = $params['name']; - $_SESSION['permission'] = $row['Permission']; - print( $_SESSION['user']); - return "success"; - }else{ - //handle login failure - print("Login failed"); - return "failure"; - } - } - }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/ams_lib/translations/en.ini b/code/ryzom/tools/server/ryzom_ams/ams_lib/translations/en.ini index 24d3dc845..e9923a45f 100644 --- a/code/ryzom/tools/server/ryzom_ams/ams_lib/translations/en.ini +++ b/code/ryzom/tools/server/ryzom_ams/ams_lib/translations/en.ini @@ -4,13 +4,22 @@ [home] [login] +login_info = "Please login with your Username and Password." +login_error_message = "The filled in username/password were not correct!" + +[logout] +logout_message = "You've been logged out successfully!" +login_title = "Login" +login_timer = "You will be redirected to the login page in " +login_text = "Or click here if you don't want to wait!" [register_feedback] status_ok = "You registered like a baws!" status_shardoffline = "It seems the shard is offline, you can use the web-account, but you will need to wait for the shard." status_liboffline = "You can't register an account at this time" -login_title = "Next step: Login" -login_text = "Click here if you want to log in!" +login_title = "Login" +login_timer = "You will be redirected to the login page in " +login_text = "Or click here if you don't want to wait!" [register] title = "RYZOM CORE INGAME REGISTRATION" diff --git a/code/ryzom/tools/server/ryzom_ams/www/html/autoload/logout.php b/code/ryzom/tools/server/ryzom_ams/www/html/autoload/logout.php new file mode 100644 index 000000000..a52172d5a --- /dev/null +++ b/code/ryzom/tools/server/ryzom_ams/www/html/autoload/logout.php @@ -0,0 +1,7 @@ + $_POST["Username"], - 'pass' => $_POST["Password"], - 'mail' => $_POST["Email"], - 'init' => $_POST["Email"], - 'unhashpass' => $_POST["Password"], - 'status' => 1, - 'access' => REQUEST_TIME - ); - user_save( NULL, $edit ); - header( 'Location: email_sent.php' ); - exit; - }else{ - $pageElements = array( - 'GAME_NAME' => $GAME_NAME, - 'WELCOME_MESSAGE' => $WELCOME_MESSAGE, - 'USERNAME' => $user, - 'PASSWORD' => $pass, - 'CPASSWORD' => $cpass, - 'EMAIL' => $email - ); - if ( $user != "success" ){ - $pageElements['USERNAME_ERROR'] = 'TRUE'; - }else{ - $pageElements['USERNAME_ERROR'] = 'FALSE'; - } - - if ( $pass != "success" ){ - $pageElements['PASSWORD_ERROR'] = 'TRUE'; - }else{ - $pageElements['PASSWORD_ERROR'] = 'FALSE'; - } - if ( $cpass != "success" ){ - $pageElements['CPASSWORD_ERROR'] = 'TRUE'; - }else{ - $pageElements['CPASSWORD_ERROR'] = 'FALSE'; - } - if ( $email != "success" ){ - $pageElements['EMAIL_ERROR'] = 'TRUE'; - }else{ - $pageElements['EMAIL_ERROR'] = 'FALSE'; - } - if ( isset( $_POST["TaC"] ) ){ - $pageElements['TAC_ERROR'] = 'FALSE'; - }else{ - $pageElements['TAC_ERROR'] = 'TRUE'; - } - if ( helpers :: check_if_game_client() ){ - helpers :: loadtemplate( 'register', $pageElements ); - }else{ - helpers :: loadtemplate( 'register', $pageElements ); - } - } diff --git a/code/ryzom/tools/server/ryzom_ams/www/html/inc/login.php b/code/ryzom/tools/server/ryzom_ams/www/html/inc/login.php new file mode 100644 index 000000000..c2368747d --- /dev/null +++ b/code/ryzom/tools/server/ryzom_ams/www/html/inc/login.php @@ -0,0 +1,43 @@ +setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); + + $statement = $dbw->prepare("SELECT * FROM ams_user WHERE Login=:user"); + $statement->execute(array('user' => $_POST['Username'])); + + $row = $statement->fetch(); + $salt = substr($row['Password'],0,2); + $hashed_input_pass = crypt($_POST["Password"], $salt); + if($hashed_input_pass == $row['Password']){ + //handle successful login + $_SESSION['user'] = $_POST["Username"]; + $_SESSION['permission'] = $row['Permission']; + //go back to the index page. + header( 'Location: index.php' ); + exit; + }else{ + //handle login failure + $result['login_error'] = 'TRUE'; + $result['no_visible_elements'] = 'TRUE'; + helpers :: loadtemplate( 'login', $result); + exit; + } + + + }catch (PDOException $e) { + //go to error page or something, because can't access website db + print_r($e); + exit; + } + +} \ No newline at end of file diff --git a/code/ryzom/tools/server/ryzom_ams/www/html/index.php b/code/ryzom/tools/server/ryzom_ams/www/html/index.php index b3749e8a6..e09d3a0f3 100644 --- a/code/ryzom/tools/server/ryzom_ams/www/html/index.php +++ b/code/ryzom/tools/server/ryzom_ams/www/html/index.php @@ -27,9 +27,14 @@ if ( isset( $_POST["function"] ) ){ function loadpage ( $page ){ - require_once( 'autoload/' . $page . '.php' ); + $filename = 'autoload/' . $page . '.php'; + if(is_file($filename)){ + require_once($filename); + } } +loadpage($page); + //Set permission if(isset($_SESSION['permission'])){ $return['permission'] = $_SESSION['permission']; @@ -40,7 +45,7 @@ if(isset($_SESSION['permission'])){ //hide sidebar + topbar in case of login/register -if($page == 'login' || $page == 'register'){ +if($page == 'login' || $page == 'register' || $page == 'logout'){ $return['no_visible_elements'] = 'TRUE'; }else{ $return['no_visible_elements'] = 'FALSE'; diff --git a/code/ryzom/tools/server/ryzom_ams/www/html/templates/layout_user.tpl b/code/ryzom/tools/server/ryzom_ams/www/html/templates/layout_user.tpl index 5c5c25689..24ba25093 100644 --- a/code/ryzom/tools/server/ryzom_ams/www/html/templates/layout_user.tpl +++ b/code/ryzom/tools/server/ryzom_ams/www/html/templates/layout_user.tpl @@ -4,5 +4,6 @@
  • Dashboard
  • Login Page
  • +
  • Logout
  • {/block} diff --git a/code/ryzom/tools/server/ryzom_ams/www/html/templates/login.tpl b/code/ryzom/tools/server/ryzom_ams/www/html/templates/login.tpl index fdf5c2d2c..29dea8036 100644 --- a/code/ryzom/tools/server/ryzom_ams/www/html/templates/login.tpl +++ b/code/ryzom/tools/server/ryzom_ams/www/html/templates/login.tpl @@ -8,38 +8,45 @@
    - +
    + +
    +
    + +

    + + +

    + + + + {if isset($login_error) and $login_error eq "TRUE"} +
    + + {$login_error_message} +
    + {/if} +
    + Register + If you dont have an account yet, create one here! +
    +
    + {/block} diff --git a/code/ryzom/tools/server/ryzom_ams/www/html/templates/logout.tpl b/code/ryzom/tools/server/ryzom_ams/www/html/templates/logout.tpl new file mode 100644 index 000000000..a238c4606 --- /dev/null +++ b/code/ryzom/tools/server/ryzom_ams/www/html/templates/logout.tpl @@ -0,0 +1,40 @@ +{extends file="layout.tpl"} +{block name=content} + +
    + +
    + +
    + +
    +{/block} + diff --git a/code/ryzom/tools/server/ryzom_ams/www/html/templates/register_feedback.tpl b/code/ryzom/tools/server/ryzom_ams/www/html/templates/register_feedback.tpl index 43a227eac..90c40b232 100644 --- a/code/ryzom/tools/server/ryzom_ams/www/html/templates/register_feedback.tpl +++ b/code/ryzom/tools/server/ryzom_ams/www/html/templates/register_feedback.tpl @@ -8,26 +8,42 @@
    - + +
    {/block} From 24587c1d6eaa081a1b11dd15681cf21d9d60f2d3 Mon Sep 17 00:00:00 2001 From: Quitta Date: Wed, 26 Jun 2013 17:43:29 +0200 Subject: [PATCH 4/4] show name when logged in in main top bar --- .../tools/server/ryzom_ams/www/html/index.php | 14 +++++++------- .../server/ryzom_ams/www/html/templates/layout.tpl | 6 ++++-- .../server/ryzom_ams/www/html/templates/login.tpl | 4 ++-- 3 files changed, 13 insertions(+), 11 deletions(-) diff --git a/code/ryzom/tools/server/ryzom_ams/www/html/index.php b/code/ryzom/tools/server/ryzom_ams/www/html/index.php index e09d3a0f3..dfd194049 100644 --- a/code/ryzom/tools/server/ryzom_ams/www/html/index.php +++ b/code/ryzom/tools/server/ryzom_ams/www/html/index.php @@ -7,9 +7,16 @@ session_start(); //print_r($_SESSION); +//perform an action in case one is specified +if ( isset( $_POST["function"] ) ){ + require( "inc/" . $_POST["function"] . ".php" ); + $return = $_POST["function"](); +} + //Decide what page to load if(isset($_SESSION['user'])){ $page = 'home'; + $return['username'] = $_SESSION['user']; }else{ //default page $page = 'login'; @@ -19,13 +26,6 @@ if ( isset( $_GET["page"] ) ){ $page = $_GET["page"]; } -//perform an action in case one is specified -if ( isset( $_POST["function"] ) ){ - require( "inc/" . $_POST["function"] . ".php" ); - $return = $_POST["function"](); -} - - function loadpage ( $page ){ $filename = 'autoload/' . $page . '.php'; if(is_file($filename)){ diff --git a/code/ryzom/tools/server/ryzom_ams/www/html/templates/layout.tpl b/code/ryzom/tools/server/ryzom_ams/www/html/templates/layout.tpl index 5cbc80a2d..16d032be1 100644 --- a/code/ryzom/tools/server/ryzom_ams/www/html/templates/layout.tpl +++ b/code/ryzom/tools/server/ryzom_ams/www/html/templates/layout.tpl @@ -89,17 +89,19 @@ + {if isset($username)} + {/if} diff --git a/code/ryzom/tools/server/ryzom_ams/www/html/templates/login.tpl b/code/ryzom/tools/server/ryzom_ams/www/html/templates/login.tpl index 29dea8036..a31bfe6c7 100644 --- a/code/ryzom/tools/server/ryzom_ams/www/html/templates/login.tpl +++ b/code/ryzom/tools/server/ryzom_ams/www/html/templates/login.tpl @@ -15,12 +15,12 @@
    - +
    - +