Better handle ajax errors
This commit is contained in:
parent
4dd920ae41
commit
52a36c2957
16
auth.php
16
auth.php
@ -32,7 +32,7 @@ session_start();
|
||||
$sid = session_id();
|
||||
|
||||
// check for forced login to authorize admin in case of public access
|
||||
$force_login = (isset($_REQUEST['force_login']) ? $_REQUEST['force_login'] : false);
|
||||
$force_login = isset($_REQUEST['force_login']) ? $_REQUEST['force_login'] : false;
|
||||
if ($force_login) {
|
||||
uConfig::$require_authentication = true;
|
||||
}
|
||||
@ -41,10 +41,10 @@ $user = new uUser();
|
||||
$user->getFromSession();
|
||||
if (!$user->isValid && (uConfig::$require_authentication || defined('client'))) {
|
||||
/* authentication */
|
||||
$login = (isset($_REQUEST['user']) ? $_REQUEST['user'] : NULL);
|
||||
$pass = (isset($_REQUEST['pass']) ? $_REQUEST['pass'] : NULL);
|
||||
$ssl = ((!isset($_SERVER['HTTPS']) || $_SERVER['HTTPS'] == "" || $_SERVER['HTTPS'] == "off") ? "http" : "https");
|
||||
$auth_error = (isset($_REQUEST['auth_error']) ? $_REQUEST['auth_error'] : 0);
|
||||
$login = isset($_REQUEST['user']) ? $_REQUEST['user'] : NULL;
|
||||
$pass = isset($_REQUEST['pass']) ? $_REQUEST['pass'] : NULL;
|
||||
$ssl = (!isset($_SERVER['HTTPS']) || $_SERVER['HTTPS'] == "" || $_SERVER['HTTPS'] == "off") ? "http" : "https";
|
||||
$auth_error = isset($_REQUEST['auth_error']) ? $_REQUEST['auth_error'] : false;
|
||||
|
||||
if (!$login) {
|
||||
// not authenticated and username not submited
|
||||
@ -87,9 +87,10 @@ if (!$user->isValid && (uConfig::$require_authentication || defined('client')))
|
||||
<input type="password" name="pass"><br>
|
||||
<br>
|
||||
<input type="submit" value="' . $lang["login"] . '">
|
||||
' . (($force_login == 1) ? "<input type=\"hidden\" name=\"force_login\" value=\"1\">" : "") . '
|
||||
' . (($force_login) ? '<input type="hidden" name="force_login" value="1">
|
||||
<div id="cancel"><a href="index.php">' . $lang["cancel"] . '</a></div>' : '') . '
|
||||
</form>
|
||||
<div id="error">' . (($auth_error == 1) ? $lang["authfail"] : "") . '</div>
|
||||
<div id="error">' . (($auth_error) ? $lang["authfail"] : "") . '</div>
|
||||
</div>
|
||||
</body>
|
||||
</html>';
|
||||
@ -114,6 +115,7 @@ if (!$user->isValid && (uConfig::$require_authentication || defined('client')))
|
||||
} else {
|
||||
// unsuccessful
|
||||
$error = "?auth_error=1";
|
||||
if ($force_login) { $error .= "&force_login=1"; }
|
||||
// destroy session
|
||||
$_SESSION = NULL;
|
||||
if (isset($_COOKIE[session_name('ulogger')])) {
|
||||
|
@ -278,6 +278,10 @@ button {
|
||||
margin-right: 5px;
|
||||
}
|
||||
|
||||
#cancel {
|
||||
margin-top: 0.5em;
|
||||
}
|
||||
|
||||
.red-button {
|
||||
color: white;
|
||||
float: right;
|
||||
|
@ -28,7 +28,7 @@
|
||||
*/
|
||||
class uConfig {
|
||||
// version number
|
||||
static $version = "0.2";
|
||||
static $version = "0.3-beta";
|
||||
|
||||
// default map drawing framework
|
||||
static $mapapi = "openlayers";
|
||||
|
14
js/admin.js
14
js/admin.js
@ -81,9 +81,11 @@ function submitUser(action) {
|
||||
}
|
||||
var xhr = getXHR();
|
||||
xhr.onreadystatechange = function() {
|
||||
if (xhr.readyState == 4 && xhr.status == 200) {
|
||||
var xml = xhr.responseXML;
|
||||
if (xhr.readyState == 4) {
|
||||
var error = true;
|
||||
var message = "";
|
||||
if (xhr.status == 200) {
|
||||
var xml = xhr.responseXML;
|
||||
if (xml) {
|
||||
var root = xml.getElementsByTagName('root');
|
||||
if (root.length && getNode(root[0], 'error') == 0) {
|
||||
@ -95,12 +97,16 @@ function submitUser(action) {
|
||||
f.remove(f.selectedIndex);
|
||||
selectUser(f);
|
||||
}
|
||||
return;
|
||||
}
|
||||
error = false;
|
||||
} else if (root.length) {
|
||||
errorMsg = getNode(root[0], 'message');
|
||||
if (errorMsg) { message = errorMsg; }
|
||||
}
|
||||
}
|
||||
}
|
||||
if (error) {
|
||||
alert(lang['actionfailure'] + '\n' + message);
|
||||
}
|
||||
xhr = null;
|
||||
}
|
||||
}
|
||||
|
14
js/pass.js
14
js/pass.js
@ -46,20 +46,26 @@ function submitPass() {
|
||||
|
||||
var xhr = getXHR();
|
||||
xhr.onreadystatechange = function () {
|
||||
if (xhr.readyState == 4 && xhr.status == 200) {
|
||||
var xml = xhr.responseXML;
|
||||
if (xhr.readyState == 4) {
|
||||
var error = true;
|
||||
var message = "";
|
||||
if (xhr.status == 200) {
|
||||
var xml = xhr.responseXML;
|
||||
if (xml) {
|
||||
var root = xml.getElementsByTagName('root');
|
||||
if (root.length && getNode(root[0], 'error') == 0) {
|
||||
removeModal();
|
||||
alert(lang["actionsuccess"]);
|
||||
return;
|
||||
}
|
||||
error = false;
|
||||
} else if (root.length) {
|
||||
errorMsg = getNode(root[0], 'message');
|
||||
if (errorMsg) { message = errorMsg; }
|
||||
}
|
||||
}
|
||||
}
|
||||
if (error) {
|
||||
alert(lang['actionfailure'] + '\n' + message);
|
||||
}
|
||||
xhr = null;
|
||||
}
|
||||
}
|
||||
|
14
js/track.js
14
js/track.js
@ -65,9 +65,11 @@ function submitTrack(action) {
|
||||
}
|
||||
var xhr = getXHR();
|
||||
xhr.onreadystatechange = function() {
|
||||
if (xhr.readyState == 4 && xhr.status == 200) {
|
||||
var xml = xhr.responseXML;
|
||||
if (xhr.readyState == 4) {
|
||||
var error = true;
|
||||
var message = "";
|
||||
if (xhr.status == 200) {
|
||||
var xml = xhr.responseXML;
|
||||
if (xml) {
|
||||
var root = xml.getElementsByTagName('root');
|
||||
if (root.length && getNode(root[0], 'error') == 0) {
|
||||
@ -82,12 +84,16 @@ function submitTrack(action) {
|
||||
} else {
|
||||
f.options[f.selectedIndex].innerHTML = htmlEncode(trackName);
|
||||
}
|
||||
return;
|
||||
}
|
||||
error = false;
|
||||
} else if (root.length) {
|
||||
errorMsg = getNode(root[0], 'message');
|
||||
if (errorMsg) { message = errorMsg; }
|
||||
}
|
||||
}
|
||||
}
|
||||
if (error) {
|
||||
alert(lang['actionfailure'] + '\n' + message);
|
||||
}
|
||||
xhr = null;
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user