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