From 502cb9fadcfdd7a28fba067a3b44049a78c1b64c Mon Sep 17 00:00:00 2001 From: Quitta Date: Mon, 2 Sep 2013 19:43:53 +0200 Subject: [PATCH] taking away the functions checkUser, checkEmail, checkpassword out of the module, the webuser/user handles this! --HG-- branch : quitta-gsoc-2013 --- .../ryzom_ams/ams_lib/autoload/users.php | 4 +- .../ryzommanage/autoload/webusers.php | 239 ++++++++++++++++++ .../ryzommanage/ryzommanage.module | 24 +- 3 files changed, 253 insertions(+), 14 deletions(-) create mode 100644 code/ryzom/tools/server/ryzom_ams/drupal_module/ryzommanage/autoload/webusers.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 8d07283e6..e03a8fdff 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 @@ -72,7 +72,7 @@ class Users{ * @takes $username * @return string Info: Returns a string based on if the username is valid, if valid then "success" is returned */ - private function checkUser( $username ) + public function checkUser( $username ) { if ( isset( $username ) ){ if ( strlen( $username ) > 12 ){ @@ -111,7 +111,7 @@ class Users{ * @takes $pass * @return string Info: Returns a string based on if the password is valid, if valid then "success" is returned */ - private function checkPassword( $pass ) + public function checkPassword( $pass ) { if ( isset( $pass ) ){ if ( strlen( $pass ) > 20 ){ diff --git a/code/ryzom/tools/server/ryzom_ams/drupal_module/ryzommanage/autoload/webusers.php b/code/ryzom/tools/server/ryzom_ams/drupal_module/ryzommanage/autoload/webusers.php new file mode 100644 index 000000000..7b980e79d --- /dev/null +++ b/code/ryzom/tools/server/ryzom_ams/drupal_module/ryzommanage/autoload/webusers.php @@ -0,0 +1,239 @@ +uId = $UId; + } + + public function set($values){ + $this->uId = $values['UId']; + $this->login = $values['Login']; + $this->email = $values['Email']; + $this->firstname = $values['FirstName']; + $this->lastname = $values['LastName']; + $this->gender = $values['Gender']; + $this->country = $values['Country']; + $this->receiveMail = $values['ReceiveMail']; + $this->language = $values['Language']; + } + + /** + * Function checkUserNameExists + * + * @takes $username + * @return string Info: Returns true or false if the user is in the web db. + */ + protected function checkUserNameExists($username){ + return db_query("SELECT COUNT(*) FROM {users} WHERE name = :name", array(':name' => $username))->fetchField(); + } + + + /** + * Function checkEmailExists + * + * @takes $username + * @return string Info: Returns true or false if the user is in the www db. + */ + protected function checkEmailExists($email){ + return db_query("SELECT COUNT(*) FROM {users} WHERE mail = :mail", array(':mail' => $email))->fetchField(); + } + + + /** + * Function checkUserPassMatch + * + * @takes $username,$password + * @return string Info: Returns true or false if a login match is found in the web db + */ + public function checkLoginMatch($username,$password){ + $dbw = new DBLayer("web"); + $statement = $dbw->execute("SELECT * FROM ams_user WHERE Login=:user", array('user' => $username)); + $row = $statement->fetch(); + + $salt = substr($row['Password'],0,2); + $hashed_input_pass = crypt($password, $salt); + if($hashed_input_pass == $row['Password']){ + return $row; + }else{ + return "fail"; + } + } + + //returns te id for a given username + public static function getId($username){ + $dbw = new DBLayer("web"); + $statement = $dbw->execute("SELECT * FROM ams_user WHERE Login=:username", array('username' => $username)); + $row = $statement->fetch(); + return $row['UId']; + } + + //returns te id for a given username + public static function getIdFromEmail($email){ + $dbw = new DBLayer("web"); + $statement = $dbw->execute("SELECT * FROM ams_user WHERE Email=:email", array('email' => $email)); + $row = $statement->fetch(); + if(!empty($row)){ + return $row['UId']; + }else{ + return "FALSE"; + } + } + + public function getUId(){ + return $this->uId; + } + + public function getUsername(){ + $dbw = new DBLayer("web"); + if(! isset($this->login) || $this->login == ""){ + $statement = $dbw->execute("SELECT * FROM ams_user WHERE UId=:id", array('id' => $this->uId)); + $row = $statement->fetch(); + $this->set($row); + } + return $this->login; + } + + public function getEmail(){ + $dbw = new DBLayer("web"); + if(! isset($this->email) || $this->email == ""){ + $statement = $dbw->execute("SELECT * FROM ams_user WHERE UId=:id", array('id' => $this->uId)); + $row = $statement->fetch(); + $this->set($row); + } + return $this->email; + } + + public function getInfo(){ + $dbw = new DBLayer("web"); + if(! (isset($this->firstname) && isset($this->lastname) && isset($this->gender) && isset($this->country) && isset($this->receiveMail) ) || + $this->firstname == "" || $this->lastname == "" || $this->gender == "" || $this->country == "" || $this->receiveMail == ""){ + $statement = $dbw->execute("SELECT * FROM ams_user WHERE UId=:id", array('id' => $this->uId)); + $row = $statement->fetch(); + $this->set($row); + } + $result = Array('FirstName' => $this->firstname, 'LastName' => $this->lastname, 'Gender' => $this->gender, 'Country' => $this->country, 'ReceiveMail' => $this->receiveMail); + return $result; + } + + public function getReceiveMail(){ + $dbw = new DBLayer("web"); + if(! isset($this->receiveMail) || $this->receiveMail == ""){ + $statement = $dbw->execute("SELECT * FROM ams_user WHERE UId=:id", array('id' => $this->uId)); + $row = $statement->fetch(); + $this->set($row); + } + return $this->receiveMail; + } + + public function getLanguage(){ + $dbw = new DBLayer("web"); + if(! isset($this->language) || $this->language == ""){ + $statement = $dbw->execute("SELECT * FROM ams_user WHERE UId=:id", array('id' => $this->uId)); + $row = $statement->fetch(); + $this->set($row); + } + return $this->language; + } + + public function isLoggedIn(){ + if(isset($_SESSION['user'])){ + return true; + } + return false; + } + + public function setPassword($user, $pass){ + $reply = WebUsers::setAmsPassword($user, $pass); + $values = Array('user' => $user, 'pass' => $pass); + try { + //make connection with and put into shard db + $dbw = new DBLayer("web"); + $dbw->execute("UPDATE ams_user SET Password = :pass WHERE Login = :user ",$values); + } + catch (PDOException $e) { + //ERROR: the web DB is offline + } + return $reply; + } + + public function setEmail($user, $mail){ + $reply = WebUsers::setAmsEmail($user, $mail); + $values = Array('user' => $user, 'mail' => $mail); + try { + //make connection with and put into shard db + $dbw = new DBLayer("web"); + $dbw->execute("UPDATE ams_user SET Email = :mail WHERE Login = :user ",$values); + } + catch (PDOException $e) { + //ERROR: the web DB is offline + } + return $reply; + } + + public static function setReceiveMail($user, $receivemail){ + $values = Array('user' => $user, 'receivemail' => $receivemail); + try { + //make connection with and put into shard db + $dbw = new DBLayer("web"); + $dbw->execute("UPDATE ams_user SET ReceiveMail = :receivemail WHERE UId = :user ",$values); + } + catch (PDOException $e) { + //ERROR: the web DB is offline + } + } + + public static function setLanguage($user, $language){ + $values = Array('user' => $user, 'language' => $language); + try { + //make connection with and put into shard db + $dbw = new DBLayer("web"); + $dbw->execute("UPDATE ams_user SET Language = :language WHERE UId = :user ",$values); + } + catch (PDOException $e) { + //ERROR: the web DB is offline + } + } + + public function getUsers(){ + $dbl = new DBLayer("web"); + $data = $dbl->executeWithoutParams("SELECT * FROM ams_user"); + return $data; + } + + public static function getAllUsersQuery(){ + return "SELECT * FROM ams_user"; + } + + public static function createWebuser($name, $pass, $mail){ + + //register account with the correct language (check if cookie is already set)! + if ( isset( $_COOKIE['Language'] ) ) { + $lang = $_COOKIE['Language']; + }else{ + global $DEFAULT_LANGUAGE; + $lang = $DEFAULT_LANGUAGE; + } + + $values = Array('name' => $name, 'pass' => $pass, 'mail' => $mail, 'lang' => $lang); + + try { + $dbw = new DBLayer("web"); + return $dbw->executeReturnId("INSERT INTO ams_user (Login, Password, Email, Language) VALUES (:name, :pass, :mail, :lang)",$values); + } + catch (PDOException $e) { + //ERROR: the web DB is offline + } + } + +} \ No newline at end of file diff --git a/code/ryzom/tools/server/ryzom_ams/drupal_module/ryzommanage/ryzommanage.module b/code/ryzom/tools/server/ryzom_ams/drupal_module/ryzommanage/ryzommanage.module index 6684ec0c8..73670cb2a 100644 --- a/code/ryzom/tools/server/ryzom_ams/drupal_module/ryzommanage/ryzommanage.module +++ b/code/ryzom/tools/server/ryzom_ams/drupal_module/ryzommanage/ryzommanage.module @@ -56,9 +56,9 @@ function ryzommanage_form_alter(&$form, &$form_state, $form_id) function _webpage_registration(&$form_state) { - - $user = checkUser($form_state['account']['name']['#value']); - $email = validEmail($form_state['account']['mail']['#value']); + $webUser = new WebUsers(); + $user = $webUser->checkUser($form_state['account']['name']['#value']); + $email = $webUser->validEmail($form_state['account']['mail']['#value']); if ($user != "success") { form_set_error('name', t($user)); @@ -71,12 +71,13 @@ function _webpage_registration(&$form_state) function _webpage_profile(&$form_state) { - $email = validEmail($form_state['account']['mail']['#value']); + $webUser = new WebUsers(); + $email = $webUser->validEmail($form_state['account']['mail']['#value']); if ($email != "success") { form_set_error('mail', t('Not a valid email address, please check it and try again.')); } - if ((checkPassword($form_state['account']['pass']['#value']['pass1']) == "success" ) and ( $form_state['account']['pass']['#value']['pass1'] == + if (($webUser->checkPassword($form_state['account']['pass']['#value']['pass1']) == "success" ) and ( $form_state['account']['pass']['#value']['pass1'] == $form_state['account']['pass']['#value']['pass2'] )) { } } @@ -329,7 +330,7 @@ function return_client_httpdata() * Info: Returns a string based on if the username is valid, if valid then "success" is returned * */ -function checkUser($username) +/*function checkUser($username) { if (isset($username)) { if (strlen($username) > 12) { @@ -349,7 +350,7 @@ function checkUser($username) return "success"; } return "fail"; -} +}*/ /** * * Function checkPassword @@ -360,7 +361,7 @@ function checkUser($username) * Info: Returns a string based on if the password is valid, if valid then "success" is returned * */ -function checkPassword($pass) +/*function checkPassword($pass) { if (isset($pass)) { if (strlen($pass) > 20) { @@ -372,7 +373,7 @@ function checkPassword($pass) } } return "fail"; -} +}*/ /** * * Function confirmPassword @@ -402,7 +403,7 @@ function confirmPassword() * * */ -function checkEmail($email) +/*function checkEmail($email) { if (isset($email)) { if (!validEmail($email)) { @@ -461,7 +462,7 @@ function validEmail($email) } } return $isValid; -} +}*/ /** * @@ -503,7 +504,6 @@ function createUser($values, $user_id) //Create the user on the shard + in case shard is offline put copy of query in query db //returns: ok, shardoffline or liboffline $result = WebUsers::createUser($params, $user_id); - echo $result; //createPermissions(array($login)); }