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 c99e8567d..f8494b6a0 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 @@ -10,10 +10,10 @@ class Users{ public function check_Register($values){ // check values if ( isset( $values["Username"] ) and isset( $values["Password"] ) and isset( $values["Email"] ) ){ - $user = Users :: checkUser( $values["Username"] ); - $pass = Users :: checkPassword( $values["Password"] ); - $cpass = Users :: confirmPassword($pass); - $email = Users :: checkEmail( $values["Email"] ); + $user = Users::checkUser( $values["Username"] ); + $pass = Users::checkPassword( $values["Password"] ); + $cpass = Users::confirmPassword($pass); + $email = Users::checkEmail( $values["Email"] ); }else{ $user = ""; $pass = ""; @@ -62,6 +62,9 @@ class Users{ } } + + + /** * Function checkUser @@ -80,8 +83,8 @@ class Users{ return "Username can only contain numbers and letters."; }else if ( $username == "" ){ return "You have to fill in a username"; - /*}elseif ($this->dbs->execute("SELECT * FROM user WHERE Login = :name",array('name' => $username))->rowCount()){ - return "Username " . $username . " is in use.";*/ + }elseif ($this->checkUserNameExists($username)){ + return "Username " . $username . " is in use."; }else{ return "success"; } @@ -90,29 +93,16 @@ class Users{ } /** - * Function checkUserAlreadyExists + * Function checkUserNameExists * * @takes $username - * @return string Info: Returns true or false if the user is in the lib+shard db. - * - private function checkUserAlreadyExists( $username ) - { - global $cfg; - $dbl = new DBLayer($cfg['db']['lib']); - $dbs = new DBLayer($cfg['db']['shard']); - try{ - if ($this->dbl->execute("SELECT * FROM user WHERE Login = :name",array('name' => $username))->rowCount()){ - return true; - } - if ($this->dbs->execute("SELECT * FROM user WHERE Login = :name",array('name' => $username))->rowCount()){ - return true; - } - return false; - }catch (PDOException $e) { - //in case one of them is offline let it be hanled lateron with the - return true; - } - }*/ + * @return string Info: Returns true or false if the user is in the www db. + */ + protected function checkUserNameExists($username){ + //You should overwrite this method with your own version! + print('this is the base class!'); + + } /** @@ -172,9 +162,9 @@ class Users{ return "Email address is not valid."; }else if($email == ""){ return "You have to fill in an email address"; - /*}elseif ( $this->dbs->execute("SELECT * FROM user WHERE Email = :email",array('email' => $email))->rowCount()){ - return "Email is in use.";*/} - else{ + }else if ($this->checkEmailExists($email)){ + return "Email is in use."; + }else{ return "success"; } } @@ -182,7 +172,19 @@ class Users{ } - + /** + * Function checkEmailExists + * + * @takes $username + * @return string Info: Returns true or false if the user is in the www db. + */ + protected function checkEmailExists($email){ + //TODO: You should overwrite this method with your own version! + print('this is the base class!'); + + } + + /** * Function validEmail * diff --git a/code/ryzom/tools/server/ryzom_ams/www/html/autoload/webusers.php b/code/ryzom/tools/server/ryzom_ams/www/html/autoload/webusers.php new file mode 100644 index 000000000..48b6a1f94 --- /dev/null +++ b/code/ryzom/tools/server/ryzom_ams/www/html/autoload/webusers.php @@ -0,0 +1,29 @@ +execute("SELECT * FROM ams_user WHERE Login = :name",array('name' => $username))->rowCount(); + } + + + /** + * Function checkEmailExists + * + * @takes $username + * @return string Info: Returns true or false if the user is in the www db. + */ + protected function checkEmailExists($email){ + global $cfg; + $dbw = new DBLayer($cfg['db']['web']); + return $dbw->execute("SELECT * FROM ams_user WHERE Email = :email",array('email' => $email))->rowCount(); + } +} \ No newline at end of file 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 46dfea6b4..bd10fb1e4 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 @@ -3,7 +3,8 @@ function add_user(){ $params = Array('Username' => $_POST["Username"], 'Password' => $_POST["Password"], 'Email' => $_POST["Email"]); - $result = Users::check_Register($params); + $webUser = new WebUsers; + $result = $webUser->check_Register($params); // if all are good then create user if ( $result == "success"){ @@ -37,7 +38,7 @@ function add_user(){ function write_user($newUser){ //create salt here, because we want it to be the same on the web/server - $hashpass = crypt($newUser["pass"], Users::generateSALT()); + $hashpass = crypt($newUser["pass"], WebUsers::generateSALT()); $params = array( 'name' => $newUser["name"], @@ -51,7 +52,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); + $result = WebUsers::createUser($values); try{ //make connection with web db and put it in there 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 bfa20ee41..3ef43941d 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 @@ -101,13 +101,13 @@
  • Logout
  • + {/if}
    - {/if} @@ -245,6 +245,7 @@ + diff --git a/code/ryzom/tools/server/ryzom_ams/www/html/templates/userlist.tpl b/code/ryzom/tools/server/ryzom_ams/www/html/templates/userlist.tpl index 59cb17574..d5e076161 100644 --- a/code/ryzom/tools/server/ryzom_ams/www/html/templates/userlist.tpl +++ b/code/ryzom/tools/server/ryzom_ams/www/html/templates/userlist.tpl @@ -13,6 +13,7 @@

    The shard/lib/web db user list You are about to see it here!

    +
    lolbol