]> git.wh0rd.org Git - tt-rss.git/commitdiff
ajaxify change email form
authorAndrew Dolgov <fox@bah.spb.su>
Fri, 2 Mar 2007 21:10:11 +0000 (22:10 +0100)
committerAndrew Dolgov <fox@bah.spb.su>
Fri, 2 Mar 2007 21:10:11 +0000 (22:10 +0100)
functions.php
modules/pref-prefs.php
prefs.js

index 9733747014cc28480d309775082d95556c63971c..6a4d635b836449730e4ce80acead06b3e0e2da85 100644 (file)
                header("Pragma: no-cache"); // HTTP/1.0
        }
 
-       function format_warning($msg) {
-               return "<div class=\"warning\"> 
+       function format_warning($msg, $id = "") {
+               return "<div class=\"warning\" id=\"$id\"
                        <img src=\"images/sign_excl.png\">$msg</div>";
        }
 
index 2185646af56736afab999b0800d663786cf50689..047fb1865ba2e83420460b2bc2f2b8e5f6a2edf2 100644 (file)
@@ -55,9 +55,8 @@
                        }
 
                        return;
-               }
 
-               if ($subop == "Save configuration") {
+               } else if ($subop == "Save configuration") {
 
                        $_SESSION["prefs_op_result"] = "save-config";
 
                                print "Unknown option: $pref_name";
                        }
 
-               } else if ($subop == "Change e-mail") {
+               } else if ($subop == "change-email") {
 
-                       $email = db_escape_string($_GET["email"]);
+                       $email = db_escape_string($_POST["email"]);
                        $active_uid = $_SESSION["uid"];
 
-                       if ($email) {
-                               db_query($link, "UPDATE ttrss_users SET email = '$email' 
-                                               WHERE id = '$active_uid'");                             
-                       }
-
-                       return prefs_js_redirect();
+                       db_query($link, "UPDATE ttrss_users SET email = '$email' 
+                               WHERE id = '$active_uid'");                             
+               
+                       print "E-mail has been changed.";
+               
+                       return;
 
                } else if ($subop == "Reset to defaults") {
 
                                                pwd_hash = 'SHA1:".sha1("password")."')");
 
                                if (db_num_rows($result) != 0) {
-                                       print format_warning("Your password is at default value, please change it.");
+                                       print format_warning("Your password is at default value, 
+                                               please change it.", "default_pass_warning");
                                }
 
 /*                             if ($_SESSION["pwd_change_result"] == "failed") {
 
                                $_SESSION["prefs_op_result"] = "";
 
-                               print "<form action=\"backend.php\" method=\"GET\">";
+                               print "<form onsubmit='return false' id='change_email_form'>";
        
                                print "<table width=\"100%\" class=\"prefPrefsList\">";
                                print "<tr><td colspan='3'><h3>Personal data</h3></tr></td>";
        
                                print "<tr><td width=\"40%\">E-mail</td>";
                                print "<td><input class=\"editbox\" name=\"email\" 
+                                       onkeypress=\"return filterCR(event, changeUserEmail)\"
                                        value=\"$email\"></td></tr>";
        
                                print "</table>";
        
                                print "<input type=\"hidden\" name=\"op\" value=\"pref-prefs\">";
-       
-                               print "<p><input class=\"button\" type=\"submit\" 
-                                       value=\"Change e-mail\" name=\"subop\">";
+                               print "<input type=\"hidden\" name=\"subop\" value=\"change-email\">";
 
                                print "</form>";
 
+                               print "<p><input class=\"button\" type=\"submit\"
+                                       onclick=\"return changeUserEmail()\" value=\"Change e-mail\">";
+
                                print "<form onsubmit=\"return false\" 
                                        name=\"change_pass_form\" id=\"change_pass_form\">";
        
index 6256f71bf1ec1215b3a06a33a9cfe20df3689886..25f290c76537b7150320e83849aa903b089c5356 100644 (file)
--- a/prefs.js
+++ b/prefs.js
@@ -132,16 +132,23 @@ function notify_callback() {
 
 
 function changepass_callback() {
-       if (xmlhttp.readyState == 4) {
-
-               if (xmlhttp.responseText.indexOf("ERROR: ") == 0) {
-                       notify_error(xmlhttp.responseText.replace("ERROR: ", ""));
-               } else {
-                       notify_info(xmlhttp.responseText);
-               }
+       try {
+               if (xmlhttp.readyState == 4) {
+       
+                       if (xmlhttp.responseText.indexOf("ERROR: ") == 0) {
+                               notify_error(xmlhttp.responseText.replace("ERROR: ", ""));
+                       } else {
+                               notify_info(xmlhttp.responseText);
+                               var warn = document.getElementById("default_pass_warning");
+                               if (warn) warn.style.display = "none";
+                       }
+       
+                       document.forms['change_pass_form'].reset();
 
-               document.forms['change_pass_form'].reset();
-       } 
+               } 
+       } catch (e) {
+               exception_error("changepass_callback", e);
+       }
 }
 
 function updateFeedList(sort_key) {
@@ -1623,3 +1630,28 @@ function changeUserPassword() {
        return false;
 }
 
+function changeUserEmail() {
+
+       try {
+
+               if (!xmlhttp_ready(xmlhttp)) {
+                       printLockingError();
+                       return false;
+               }
+       
+               var query = Form.serialize("change_email_form");
+       
+               notify_progress("Trying to change e-mail...");
+       
+               xmlhttp.open("POST", "backend.php", true);
+               xmlhttp.onreadystatechange=notify_callback;
+               xmlhttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
+               xmlhttp.send(query);
+
+       } catch (e) {
+               exception_error("changeUserPassword", e);
+       }
+       
+       return false;
+
+}