From 8db2ff5da679b3c2d5a53f67f67863d786057f36 Mon Sep 17 00:00:00 2001
From: Marcel Korpel
Date: Sun, 19 Jul 2015 22:32:06 +0200
Subject: Set correct 'My Account' link after changing username
Don't print messages (and the account form) in process_account_form()
anymore, but return them to the caller. When updating accounts, this
function will be called before the headers are written.
If a username has been changed by process_account_form(), the headers
now show the updated username from the database in the 'My Account'
link. Clicking on it immediately after changing a username will no
longer lead to a non-existing URL.
Signed-off-by: Marcel Korpel
Signed-off-by: Lukas Fleischer
---
web/lib/acctfuncs.inc.php | 31 ++++++++++++++++---------------
1 file changed, 16 insertions(+), 15 deletions(-)
(limited to 'web/lib/acctfuncs.inc.php')
diff --git a/web/lib/acctfuncs.inc.php b/web/lib/acctfuncs.inc.php
index 9d6f5ee4..f718a773 100644
--- a/web/lib/acctfuncs.inc.php
+++ b/web/lib/acctfuncs.inc.php
@@ -89,13 +89,14 @@ function display_account_form($A,$U="",$T="",$S="",$E="",$P="",$C="",$R="",
* @param string $UID The user ID of the modified account
* @param string $N The username as present in the database
*
- * @return string|void Return void if successful, otherwise return error
+ * @return array Boolean indicating success and message to be printed
*/
function process_account_form($TYPE,$A,$U="",$T="",$S="",$E="",$P="",$C="",
$R="",$L="",$I="",$K="",$PK="",$J="",$UID=0,$N="") {
global $SUPPORTED_LANGS;
$error = '';
+ $message = '';
if (is_ipbanned()) {
$error = __('Account registration has been disabled ' .
@@ -247,10 +248,8 @@ function process_account_form($TYPE,$A,$U="",$T="",$S="",$E="",$P="",$C="",
}
if ($error) {
- print "\n";
- display_account_form($A, $U, $T, $S, $E, "", "",
- $R, $L, $I, $K, $PK, $J, $UID, $N);
- return;
+ $message = "\n";
+ return array(false, $message);
}
if ($TYPE == "new") {
@@ -278,25 +277,25 @@ function process_account_form($TYPE,$A,$U="",$T="",$S="",$E="",$P="",$C="",
$q.= "$I, $K)";
$result = $dbh->exec($q);
if (!$result) {
- print __("Error trying to create account, %s%s%s.",
+ $message = __("Error trying to create account, %s%s%s.",
"", htmlspecialchars($U,ENT_QUOTES), "");
- return;
+ return array(false, $message);
}
$uid = $dbh->lastInsertId();
account_set_ssh_keys($uid, $ssh_keys, $ssh_fingerprints);
- print __("The account, %s%s%s, has been successfully created.",
+ $message = __("The account, %s%s%s, has been successfully created.",
"", htmlspecialchars($U,ENT_QUOTES), "");
- print "\n";
+ $message .= "
\n";
if ($send_resetkey) {
send_resetkey($email, true);
- print __("A password reset key has been sent to your e-mail address.");
- print "
\n";
+ $message .= __("A password reset key has been sent to your e-mail address.");
+ $message .= "
\n";
} else {
- print __("Click on the Login link above to use your account.");
- print "\n";
+ $message .= __("Click on the Login link above to use your account.");
+ $message .= "\n";
}
} else {
/* Modify an existing account. */
@@ -341,13 +340,15 @@ function process_account_form($TYPE,$A,$U="",$T="",$S="",$E="",$P="",$C="",
$ssh_key_result = account_set_ssh_keys($UID, $ssh_keys, $ssh_fingerprints);
if ($result === false || $ssh_key_result === false) {
- print __("No changes were made to the account, %s%s%s.",
+ $message = __("No changes were made to the account, %s%s%s.",
"", htmlspecialchars($U,ENT_QUOTES), "");
} else {
- print __("The account, %s%s%s, has been successfully modified.",
+ $message = __("The account, %s%s%s, has been successfully modified.",
"", htmlspecialchars($U,ENT_QUOTES), "");
}
}
+
+ return array(true, $message);
}
/**
--
cgit v1.2.3-24-g4f1b