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 640849011..7083d6bfa 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 @@ -156,7 +156,7 @@ class Users{ * @takes $email * @return */ - private function checkEmail( $email ) + public function checkEmail( $email ) { if ( isset( $email ) ){ if ( !Users::validEmail( $email ) ){ @@ -381,7 +381,31 @@ class Users{ try { $dbl = new DBLayer($cfg['db']['lib']); $dbl->execute("INSERT INTO ams_querycache (type, query) VALUES (:type, :query)",array("type" => "changepass", - "query" => json_encode(array($values["name"],$values["pass"])))); + "query" => json_encode(array($values["user"],$values["pass"])))); + return "shardoffline"; + }catch (PDOException $e) { + return "liboffline"; + } + } + } + + protected function setAmsEmail($user, $mail){ + + global $cfg; + $values = Array('user' => $user, 'mail' => $mail); + + try { + //make connection with and put into shard db + $dbs = new DBLayer($cfg['db']['shard']); + $dbs->execute("UPDATE user SET Email = :mail WHERE Login = :user ",$values); + return "ok"; + } + catch (PDOException $e) { + //oh noooz, the shard is offline! Put in query queue at ams_lib db! + try { + $dbl = new DBLayer($cfg['db']['lib']); + $dbl->execute("INSERT INTO ams_querycache (type, query) VALUES (:type, :query)",array("type" => "changemail", + "query" => json_encode(array($values["user"],$values["mail"])))); return "shardoffline"; }catch (PDOException $e) { return "liboffline"; 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 index 4427fa578..af851e273 100644 --- a/code/ryzom/tools/server/ryzom_ams/www/html/autoload/webusers.php +++ b/code/ryzom/tools/server/ryzom_ams/www/html/autoload/webusers.php @@ -60,6 +60,16 @@ class WebUsers extends Users{ return $row['Login']; } + public function getEmail($id){ + global $cfg; + + $dbw = new DBLayer($cfg['db']['web']); + $statement = $dbw->execute("SELECT * FROM ams_user WHERE UId=:id", array('id' => $id)); + $row = $statement->fetch(); + return $row['Email']; + } + + public function isLoggedIn(){ if(isset($_SESSION['user'])){ return true; @@ -89,4 +99,19 @@ class WebUsers extends Users{ return $reply; } + public function setEmail($user, $mail){ + global $cfg; + $reply = WebUsers::setAmsEmail($user, $mail); + $values = Array('user' => $user, 'mail' => $mail); + try { + //make connection with and put into shard db + $dbw = new DBLayer($cfg['db']['web']); + $dbw->execute("UPDATE ams_user SET Email = :mail WHERE Login = :user ",$values); + } + catch (PDOException $e) { + //ERROR: the web DB is offline + } + return $reply; + } + } \ No newline at end of file diff --git a/code/ryzom/tools/server/ryzom_ams/www/html/func/change_mail.php b/code/ryzom/tools/server/ryzom_ams/www/html/func/change_mail.php new file mode 100644 index 000000000..99a173519 --- /dev/null +++ b/code/ryzom/tools/server/ryzom_ams/www/html/func/change_mail.php @@ -0,0 +1,80 @@ +checkEmail($_POST['NewEmail']); + if ( $reply != "success" ){ + $result['EMAIL_ERROR'] = 'TRUE'; + }else{ + $result['EMAIL_ERROR'] = 'FALSE'; + } + $result['prevNewEmail'] = $_POST["NewEmail"]; + + if ($reply== "success"){ + $status = WebUsers::setEmail($target_username, $_POST["NewEmail"] ); + if($status == 'ok'){ + $result['SUCCESS_MAIL'] = "OK"; + }else if($status == 'shardoffline'){ + $result['SUCCESS_MAIL'] = "SHARDOFF"; + } + $result['permission'] = $_SESSION['permission']; + $result['no_visible_elements'] = 'FALSE'; + $result['target_id'] = $_POST['target_id']; + if(isset($_GET['id'])){ + if(WebUsers::isAdmin() && ($_POST['target_id'] != $_SESSION['id'])){ + $result['isAdmin'] = "TRUE"; + } + } + helpers :: loadtemplate( 'settings', $result); + exit; + + }else{ + $result['EMAIL'] = $reply; + $result['permission'] = $_SESSION['permission']; + $result['no_visible_elements'] = 'FALSE'; + $return['username'] = $_SESSION['user']; + $result['target_id'] = $_POST['target_id']; + if(isset($_GET['id'])){ + if(WebUsers::isAdmin() && ($_POST['target_id'] != $_SESSION['id'])){ + $result['isAdmin'] = "TRUE"; + } + } + helpers :: loadtemplate( 'settings', $result); + exit; + } + + }else{ + //ERROR: permission denied! + } + + }else{ + //ERROR: The form was not filled in correclty + } + }else{ + //ERROR: user is not logged in + exit; + } + + }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/html/func/change_password.php b/code/ryzom/tools/server/ryzom_ams/www/html/func/change_password.php index 05da2655b..cbeb4306a 100644 --- a/code/ryzom/tools/server/ryzom_ams/www/html/func/change_password.php +++ b/code/ryzom/tools/server/ryzom_ams/www/html/func/change_password.php @@ -18,7 +18,6 @@ function change_password(){ $adminChangesOther = true; $_POST["CurrentPass"] = "dummypass"; } - $id = $_POST['target_id']; $webUser = new WebUsers(); $params = Array( 'user' => $target_username, 'CurrentPass' => $_POST["CurrentPass"], 'NewPass' => $_POST["NewPass"], 'ConfirmNewPass' => $_POST["ConfirmNewPass"], 'adminChangesOther' => $adminChangesOther); @@ -29,9 +28,9 @@ function change_password(){ $hashpass = crypt($_POST["NewPass"], WebUsers::generateSALT()); $status = WebUsers::setPassword($target_username, $hashpass); if($status == 'ok'){ - $succresult['SUCCESS'] = "OK"; + $succresult['SUCCESS_PASS'] = "OK"; }else if($status == 'shardoffline'){ - $succresult['SUCCESS'] = "SHARDOFF"; + $succresult['SUCCESS_PASS'] = "SHARDOFF"; } $succresult['permission'] = $_SESSION['permission']; $succresult['no_visible_elements'] = 'FALSE'; @@ -51,6 +50,7 @@ function change_password(){ $result['prevConfirmNewPass'] = $_POST["ConfirmNewPass"]; $result['permission'] = $_SESSION['permission']; $result['no_visible_elements'] = 'FALSE'; + $return['username'] = $_SESSION['user']; $result['target_id'] = $_POST['target_id']; if(isset($_GET['id'])){ if(WebUsers::isAdmin() && ($_POST['target_id'] != $_SESSION['id'])){ diff --git a/code/ryzom/tools/server/ryzom_ams/www/html/inc/settings.php b/code/ryzom/tools/server/ryzom_ams/www/html/inc/settings.php index 2248b7d70..a85877cda 100644 --- a/code/ryzom/tools/server/ryzom_ams/www/html/inc/settings.php +++ b/code/ryzom/tools/server/ryzom_ams/www/html/inc/settings.php @@ -8,10 +8,12 @@ function settings(){ $result['isAdmin'] = "TRUE"; } $result['target_id'] = $_GET['id']; + $result['current_mail'] = WebUsers::getEmail($_GET['id']); }else{ $result['target_id'] = $_SESSION['id']; + $result['current_mail'] = WebUsers::getEmail($_SESSION['id']); } - + return $result; }else{ //ERROR: not logged in! diff --git a/code/ryzom/tools/server/ryzom_ams/www/html/templates/settings.tpl b/code/ryzom/tools/server/ryzom_ams/www/html/templates/settings.tpl index 2606cee35..46c3da902 100644 --- a/code/ryzom/tools/server/ryzom_ams/www/html/templates/settings.tpl +++ b/code/ryzom/tools/server/ryzom_ams/www/html/templates/settings.tpl @@ -52,15 +52,15 @@ - {if isset($SUCCESS) and $SUCCESS eq "OK"} + {if isset($SUCCESS_PASS) and $SUCCESS_PASS eq "OK"}
- Your password has been changed! + The password has been changed!
{/if} - {if isset($SUCCESS) and $SUCCESS eq "SHARDOFF"} + {if isset($SUCCESS_PASS) and $SUCCESS_PASS eq "SHARDOFF"}
- Your password has been changed, though the shard seems offline, it may take some time to see the change on the shard. + The password has been changed, though the shard seems offline, it may take some time to see the change on the shard.
{/if} @@ -87,18 +87,34 @@
-
+ Change Email -
+
- -
+ + {if isset($EMAIL_ERROR) and $EMAIL_ERROR eq "TRUE"}{$EMAIL}{/if} + +
-
- +
+ + {if isset($SUCCESS_MAIL) and $SUCCESS_MAIL eq "OK"} +
+ The email has been changed! +
+ {/if} + + {if isset($SUCCESS_MAIL) and $SUCCESS_MAIL eq "SHARDOFF"} +
+ The email has been changed, though the shard seems offline, it may take some time to see the change on the shard. +
+ {/if} + + +