exit_document ("<success request=\"$reason\"></success>");
}
+function success_changepass ($username) {
+ $res = "<success request=\"changepass\"><user>" .
+ htmlspecialchars ($username) .
+ "</user></success>";
+ exit_document ($res);
+}
+
function success_newuser ($username) {
$res = "<success request=\"newuser\"><user>" .
- htmlspecialchars ($user) .
+ htmlspecialchars ($username) .
"</user></success>";
exit_document ($res);
}
error ("server");
}
+function error_wrongpass () {
+ error ("wrongpass");
+}
+
function error_unauthorized () {
error ("unauthorized");
}
return null;
}
+function setcookies ($user, $pwd) {
+ // cookie will be valid for 2 weeks. I've chosen that value
+ // arbitrarily, and it may change in the future.
+ $time = time () + 14 * 60 * 24 * 60;
+ setcookie (sprintf ("%sauth", DBPREFIX), md5 ($pwd), $time, "" , "", false, true);
+ setcookie (sprintf ("%suser", DBPREFIX), $user, $time, "" , "", false, true);
+}
+
function check_auth ($con, $user, $pwd, $auth_only) {
$authentificated = false;
if (isset ($pwd)) {
if ($con->checkpwdmd5 ($user, md5 ($pwd))) {
- // cookie will be valid for 2 weeks. I've chosen that value
- // arbitrarily, and it may change in the future.
- $time = time () + 14 * 60 * 24 * 60;
- setcookie (sprintf ("%sauth", DBPREFIX), md5 ($pwd), $time, "" , "", false, true);
- setcookie (sprintf ("%suser", DBPREFIX), $user, $time, "" , "", false, true);
+ setcookies ($user, $pwd);
$authentificated = true;
if ($auth_only) {
success_auth ($user);
} catch (Exception $e) {}
success_delete_feature ($feature);
+ case "changepass":
+ $currpass = unquote ($_POST ["pass_current"]);
+ if (!$con->checkpwdmd5 ($user, md5 ($currpass))) {
+ error_wrongpass ();
+ }
+ $newpass = unquote ($_POST ["pass_new"]);
+ try {
+ $con->setpwd ($user, $newpass);
+ } catch (Exception $e) {
+ error_server ();
+ }
+ setcookies ($user, $newpass);
+ success_changepass ($user);
+ break;
case "newuser":
if ($user != "admin") {
error_unauthorized ();
if (!$newuser_name) {
error_request ();
}
+ if ($con->user_exists ($newuser_name)) {
+ error_newuser_exists ();
+ }
$newuser_password = unquote ($_POST ["newuser_password"]);
try {
- $con->setpwd ($newuser_name, $newuser_password, false);
+ $con->setpwd ($newuser_name, $newuser_password);
} catch (Exception $e) {
- if ($e->getMessage () == anydbConnection::err_query) {
- error_newuser_exists ();
- } else {
- error_server ();
- }
+ error_server ();
}
success_newuser ($newuser_name);
break;
UnconsistentError: "<?php ptrans('Server reply was inconsistent.')?>",
DelSucces: "<?php ptrans('Removal took place correctly.')?>",
UpdateSucces: "<?php ptrans('Save took place correctly.')?>",
+ userPasswordmatchError: "<?php ptrans('Passwords do not match.')?>",
+ changeSamePass: "<?php ptrans('New password is the same as old password.')?>",
+ changePassBadPass: "<?php ptrans('Bad password.')?>",
+ changePassSuccess: "<?php ptrans('Password changed correctly.')?>",
newUserNonameError: "<?php ptrans('User name has not been set.')?>",
- newUserPasswordmatchError: "<?php ptrans('Passwords do not match.')?>",
newUserExistsError: "<?php ptrans('User already exists in database.')?>",
newUserSuccess: "<?php ptrans('User added correctly.')?>"
};
<div id="header">
<?php other_languages($lang) ?>
<div id="user_management">
- <p id="logout"><a href="logout.php"><?php ptrans('Logout')?></a></p>
- <p id="add_user"><a href=""><?php ptrans('Add a co-administrator')?></a></p>
+ <p id="logout" class="user_link"><a href="logout.php"><?php ptrans('Logout')?></a></p>
+ <p id="change_pass" class="user_link"><a href=""><?php ptrans('Change my password')?></a></p>
+ <p id="add_user" class="user_link"><a href=""><?php ptrans('Add a co-administrator')?></a></p>
</div>
- <div id="newuser_area">
- <input id="newuser_close" type="image" src="openlayers/theme/default/img/close.gif"
+ <div id="user_area">
+ <input id="user_close" type="image" src="openlayers/theme/default/img/close.gif"
title="<?php ptrans('close without saving')?>" alt="<?php ptrans('close')?>">
+ <form id="changepass" method="post">
+ <label for="pass_current"><?php ptrans('current password:')?></label>
+ <br>
+ <input id="pass_current" name="pass_current" type="password">
+ <br>
+ <label for="pass_new"><?php ptrans('new password:')?></label>
+ <br>
+ <input id="pass_new" name="pass_new" type="password">
+ <br>
+ <label for="pass_new_confirm"><?php ptrans('confirm new password:')?></label>
+ <br>
+ <input id="pass_new_confirm" name="pass_new_confirm" type="password">
+ <br>
+ <input id="pass_submit" name="pass_submit" type="submit" value="<?php ptrans('Validate password')?>">
+ <input type="hidden" name="request" value="changepass">
+ </form>
<form id="newuser" method="post">
<label for="newuser_name"><?php ptrans('user name:')?></label>
<br>
<input id="newuser_submit" name="newuser_submit" type="submit" value="<?php ptrans('Validate user')?>">
<input type="hidden" name="request" value="newuser">
</form>
- <p id="newuser_comm" class="center"></p>
- <p id="newuser_throbber" class="throbber center">
+ <p id="user_comm" class="center"></p>
+ <p id="user_throbber" class="throbber center">
<?php ptrans('Connecting')?>
<img src="media/newuser-throbber.gif">
</p>
showEditor: function (feature) {
$("#newfeature_button").hide();
- userMgr.closeAddUser();
+ userMgr.close();
if (feature.fid) {
$("#delete").show();
},
addNewFeature: function () {
- userMgr.closeAddUser();
+ userMgr.close();
function cancel() {
$(document).unbind("keydown");
AjaxMgr.add({
form: form,
oncomplete: OpenLayers.Function.bind(this.ajaxReply, this),
- onsend: function() { $("#editor_throbber").css("visibility", "visible"); }
+ throbberid: "editor_throbber"
});
},
AjaxMgr.add({
form: form,
oncomplete: OpenLayers.Function.bind(this.ajaxReply, this),
- onsend: function() { $("#editor_throbber").css("visibility", "visible"); }
+ throbberid: "editor_throbber"
});
},
ajaxReply: function (data) {
- $("#editor_throbber").css("visibility", "hidden");
if (!data) {
this.commError(SypStrings.ServerError);
return;
$('#api_frame').one("load", function() {
self.running = false;
self._reqEnd();
+ if (query.throbberid) {
+ $("#" + query.throbberid).css("visibility", "hidden");
+ }
if (typeof (query.oncomplete) == "function") {
var body = null;
try {
query.form.attr("method", "post");
this.running = true;
query.form.get(0).submit();
+ if (query.throbberid) {
+ $("#" + query.throbberid).css("visibility", "visible");
+ }
if (typeof (query.onsend) == "function") {
query.onsend();
}
pwdMgr.commError("");
var req = {
form: $("#login_form"),
+ throbberid: "pwd_throbber",
onsend: function() {
- $("#pwd_throbber").css("visibility", "visible");
$("#login_error").hide();
// we need a timeout; otherwise those fields will not be submitted
},
ajaxReply: function (data) {
- $("#pwd_throbber").css("visibility", "hidden");
// here, we need a timeout because onsend timeout sometimes has not been triggered yet
window.setTimeout(function() {
$("#login_submit, #user, #password").removeAttr("disabled");
var userMgr = {
_adduserDisplayed: false,
- _deluserDisplayed: false,
+ _changepassDisplayed: false,
init: function() {
+ $("#user_close").unbind("click").click(function () {
+ userMgr.close()
+ });
+
+ $("#change_pass").unbind("click").click(function() {
+ userMgr.toggleChangePass();
+ return false;
+ });
+ $("#changepass").unbind("submit").submit(function() {
+ try {
+ userMgr.changepass();
+ } catch(e) {}
+ return false;
+ });
+
if (sypSettings.loggedUser != "admin") {
return;
}
$("#add_user").show();
-
- $("#add_user").click(function () {
+ $("#add_user").unbind("click").click(function () {
userMgr.toggleAddUser();
return false;
});
- $("#newuser_close").click(function () {
- userMgr.closeAddUser()
- });
- $("#newuser").submit(function() {
+ $("#newuser").unbind("submit").submit(function() {
try {
userMgr.add();
} catch(e) {}
return false;
});
+
+ },
+
+ disableForms: function() {
+ $("#newuser_name, #newuser_password, #newuser_password_confirm, #newuser_submit").attr("disabled", "disabled");
+ $("#pass_current, #pass_new, #pass_new_confirm, #pass_submit").attr("disabled", "disabled");
+ },
+
+ enableForms: function() {
+ $("#newuser_name, #newuser_password, #newuser_password_confirm, #newuser_submit").removeAttr("disabled");
+ $("#pass_current, #pass_new, #pass_new_confirm, #pass_submit").removeAttr("disabled");
+ },
+
+ resetForms: function() {
+ $("#newuser_name, #newuser_password, #newuser_password_confirm").val("");
+ $("#pass_current, #pass_new, #pass_new_confirm").val("");
},
uninit: function() {
- if (this._adduserDisplayed) {
- this.closeAddUser();
- }
+ this.close();
$("#add_user").unbind("click");
$("#add_user").hide();
- $("#newuser_close").unbind("click");
+ $("#change_pass").unbind("click");
+ $("#user_close").unbind("click");
$("#newuser").unbind("submit");
+ $("#changepass").unbind("submit");
+ },
+
+ close: function() {
+ this.closeChangePass();
+ this.closeAddUser();
+ },
+
+ toggleChangePass: function() {
+ if (this._changepassDisplayed) {
+ this.closeChangePass();
+ } else {
+ this.showChangePass();
+ }
+ },
+
+ showChangePass: function() {
+ if (!Admin.cancelCurrentFeature()) {
+ return;
+ }
+ this.closeAddUser();
+
+ $(document).unbind("keydown").keydown(function(e) {
+ if (e.keyCode == 27) {
+ userMgr.closeChangePass()
+ e.preventDefault();
+ }
+ });
+
+ this.resetForms();
+ this.enableForms();
+ $("#user_area, #changepass").show();
+ this.commError("");
+
+ // XXX: setTimeout needed because otherwise, map becomes hidden in IE. Why ??
+ window.setTimeout(function() {
+ $("#pass_current").focus();
+ }, 0);
+
+ this._changepassDisplayed = true;
+ },
+
+ closeChangePass: function() {
+ if (!this._changepassDisplayed) {
+ return;
+ }
+ $("#user_area, #changepass").hide();
+ $(document).unbind("keydown");
+ this._changepassDisplayed = false;
+ },
+
+ changepass: function() {
+ var newpass = $("#pass_new").val();
+ var newpass_confirm = $("#pass_new_confirm").val();
+ if (newpass != newpass_confirm) {
+ this.commError(SypStrings.userPasswordmatchError);
+ $("#pass_new").focus().select();
+ return;
+ }
+
+ var curpass = $("#pass_current").val();
+ if (newpass == curpass) {
+ this.commError(SypStrings.changeSamePass);
+ $("#pass_new").focus().select();
+ return;
+ }
+
+ this.commError("");
+
+ AjaxMgr.add({
+ form: $("#changepass"),
+ oncomplete: OpenLayers.Function.bind(this.ajaxReply, this),
+ throbberid: "user_throbber",
+ onsend: function() {
+ // we need a timeout; otherwise those fields will not be submitted
+ window.setTimeout(function() {
+ // removes focus from #password before disabling it. Otherwise, opera
+ // prevents re-focusing it after re-enabling it.
+ $("#pass_current, #pass_new, #pass_new_confirm").blur();
+ userMgr.disableForms();
+ }, 0);
+ }
+ });
},
toggleAddUser: function() {
return;
}
+ this.closeChangePass();
+
$(document).unbind("keydown").keydown(function(e) {
if (e.keyCode == 27) {
userMgr.closeAddUser()
}
});
- Admin.reset();
- $("#newuser_area").show();
- $("#newuser_name, #newuser_password, #newuser_password_confirm").val("");
- $("#newuser_name, #newuser_password, #newuser_password_confirm, #newuser_submit").removeAttr('disabled');
- $("#newuser_name").focus();;
+ $("#user_area, #newuser").show();
+ this.resetForms();
+ this.enableForms();
this.commError("");
+ // XXX: setTimeout needed because otherwise, map becomes hidden in IE. Why ??
+ window.setTimeout(function() {
+ $("#newuser_name").focus();
+ }, 0);
+
this._adduserDisplayed = true;
},
closeAddUser: function() {
- $("#newuser_area").hide();
+ if (!this._adduserDisplayed) {
+ return;
+ }
+ $("#user_area, #newuser").hide();
$(document).unbind("keydown");
this._adduserDisplayed = false;
},
var newuser_pass = $("#newuser_password").val();
var newuser_pass_confirm = $("#newuser_password_confirm").val();
if (newuser_pass != newuser_pass_confirm) {
- this.commError(SypStrings.newUserPasswordmatchError);
+ this.commError(SypStrings.userPasswordmatchError);
$("#newuser_password").focus().select();
return;
}
AjaxMgr.add({
form: $("#newuser"),
oncomplete: OpenLayers.Function.bind(this.ajaxReply, this),
- onsend: function() { $("#newuser_throbber").css("visibility", "visible"); }
+ throbberid: "user_throbber",
+ onsend: function() {
+ // we need a timeout; otherwise those fields will not be submitted
+ window.setTimeout(function() {
+ // removes focus from #password before disabling it. Otherwise, opera
+ // prevents re-focusing it after re-enabling it.
+ $("#newuser_name, #newuser_password, #newuser_password_confirm").blur();
+ userMgr.disableForms();
+ }, 0);
+ }
});
},
ajaxReply: function (data) {
- $("#newuser_throbber").css("visibility", "hidden");
if (!data) {
+ // here, we need a timeout because onsend timeout sometimes has not been triggered yet
+ var self = this;
+ window.setTimeout(function() {
+ self.enableForms();
+ }, 0);
this.commError(SypStrings.ServerError);
return;
}
+ var needFormEnabling = true;
+ var focusEl = null;
+
var xml = new OpenLayers.Format.XML().read(data);
switch (xml.documentElement.nodeName.toLowerCase()) {
case "error":
break;
case "server":
this.commError(SypStrings.ServerError);
- $("#newuser_name").focus().select();
+ if (this._adduserDisplayed) {
+ focusEl = $("#newuser_name");
+ } else if (this._changepassDisplayed) {
+ focusEl = $("#pass_current");
+ }
break;
case "request":
this.commError(SypStrings.RequestError);
- $("#newuser_name").focus().select();
+ if (this._adduserDisplayed) {
+ focusEl = $("#newuser_name");
+ } else if (this._changepassDisplayed) {
+ focusEl = $("#pass_current");
+ }
+ break;
+ case "wrongpass":
+ this.commError(SypStrings.changePassBadPass);
+ focusEl = $("#pass_current");
break;
case "newuser_exists":
this.commError(SypStrings.newUserExistsError);
- $("#newuser_name").focus().select();
+ focusEl = $("#newuser_name");
break;
default:
this.commError(SypStrings.UnconsistentError);
- $("#newuser_name").focus().select();
+ if (this._adduserDisplayed) {
+ focusEl = $("#newuser_name");
+ } else if (this._changepassDisplayed) {
+ focusEl = $("#pass_current");
+ }
break;
}
break;
switch (xml.documentElement.getAttribute("request")) {
case "newuser":
this.commSuccess(SypStrings.newUserSuccess);
- $("#newuser_name, #newuser_password, #newuser_password_confirm, #newuser_submit").attr('disabled', 'disabled');
+ needFormEnabling = false;
+ break;
+ case "changepass":
+ this.commSuccess(SypStrings.changePassSuccess);
+ needFormEnabling = false;
break;
default:
this.commError(SypStrings.UnconsistentError);
- $("newuser_name").focus().select();
+ focusEl = $("newuser_name");
break;
}
break;
default:
this.commError(SypStrings.UnconsistentError);
- $("newuser_name").focus().select();
+ focusEl = $("newuser_name");
break;
}
+
+ if (needFormEnabling) {
+ // here, we need a timeout because onsend timeout sometimes has not been triggered yet
+ var self = this;
+ window.setTimeout(function() {
+ self.enableForms();
+ if (focusEl) {
+ focusEl.select().focus();
+ }
+ }, 0);
+ } else {
+ if (focusEl) {
+ focusEl.focus().select();
+ }
+ }
+
},
commSuccess: function (message) {
- $("#newuser_comm").text(message);
- $("#newuser_comm").removeClass("error success").addClass("success");
+ $("#user_comm").text(message);
+ $("#user_comm").removeClass("error success").addClass("success");
},
commError: function (message) {
- $("#newuser_comm").text(message);
- $("#newuser_comm").removeClass("error success").addClass("error");
+ $("#user_comm").text(message);
+ $("#user_comm").removeClass("error success").addClass("error");
}
}