From 42395d28746c8f6d7493234b1faae2910de5eddb Mon Sep 17 00:00:00 2001 From: Andrew Dolgov Date: Fri, 2 Mar 2007 22:10:11 +0100 Subject: [PATCH] ajaxify change email form --- functions.php | 4 ++-- modules/pref-prefs.php | 32 ++++++++++++++------------- prefs.js | 50 ++++++++++++++++++++++++++++++++++-------- 3 files changed, 60 insertions(+), 26 deletions(-) diff --git a/functions.php b/functions.php index 97337470..6a4d635b 100644 --- a/functions.php +++ b/functions.php @@ -3174,8 +3174,8 @@ header("Pragma: no-cache"); // HTTP/1.0 } - function format_warning($msg) { - return "
+ function format_warning($msg, $id = "") { + return "
$msg
"; } diff --git a/modules/pref-prefs.php b/modules/pref-prefs.php index 2185646a..047fb186 100644 --- a/modules/pref-prefs.php +++ b/modules/pref-prefs.php @@ -55,9 +55,8 @@ } return; - } - if ($subop == "Save configuration") { + } else if ($subop == "Save configuration") { $_SESSION["prefs_op_result"] = "save-config"; @@ -113,17 +112,17 @@ 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") { @@ -181,7 +180,8 @@ 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") { @@ -204,7 +204,7 @@ $_SESSION["prefs_op_result"] = ""; - print "
"; + print ""; print ""; print ""; @@ -216,17 +216,19 @@ print ""; print ""; print "

Personal data

E-mail
"; print ""; - - print "

"; + print ""; print "

"; + print "

"; + print "

"; diff --git a/prefs.js b/prefs.js index 6256f71b..25f290c7 100644 --- 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; + +} -- 2.39.5