ulogger-server/js/pass.js

78 lines
2.9 KiB
JavaScript
Raw Normal View History

2017-04-06 23:23:25 +02:00
/* μlogger
*
* Copyright(C) 2017 Bartek Fabiszewski (www.fabiszewski.net)
*
* This is free software; you can redistribute it and/or modify it under
2017-04-07 00:05:28 +02:00
* the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
2017-04-06 23:23:25 +02:00
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
2017-04-07 00:05:28 +02:00
* You should have received a copy of the GNU General Public License
* along with this program; if not, see <http://www.gnu.org/licenses/>.
2017-04-06 23:23:25 +02:00
*/
function changePass() {
var form = '<form id="passForm" method="post" onsubmit="submitPass(); return false">';
form += '<label><b>' + lang['oldpassword'] + '</b></label><input type="password" placeholder="' + lang['passwordenter'] + '" name="oldpass" required>';
form += '<label><b>' + lang['newpassword'] + '</b></label><input type="password" placeholder="' + lang['passwordenter'] + '" name="pass" required>';
form += '<label><b>' + lang['newpasswordrepeat'] + '</b></label><input type="password" placeholder="' + lang['passwordenter'] + '" name="pass2" required>';
form += '<button type="button" onclick="removeModal()">' + lang['cancel'] + '</button><button type="submit">' + lang['submit'] + '</button>';
2017-04-06 23:23:25 +02:00
form += '</form>';
showModal(form);
}
function submitPass() {
var form = document.getElementById('passForm');
var oldpass = form.elements['oldpass'].value;
var pass = form.elements['pass'].value;
var pass2 = form.elements['pass2'].value;
if (!oldpass || !pass || !pass2) {
2017-04-12 22:42:23 +02:00
alert(lang['allrequired']);
2017-04-06 23:23:25 +02:00
return;
}
if (pass != pass2) {
2017-04-12 22:42:23 +02:00
alert(lang['passnotmatch']);
2017-04-06 23:23:25 +02:00
return;
}
if (!pass_regex.test(pass)) {
alert(lang['passlenmin'] + '\n' + lang['passrules']);
return;
}
2017-04-06 23:23:25 +02:00
var xhr = getXHR();
2017-04-09 23:35:55 +02:00
xhr.onreadystatechange = function () {
2017-05-19 10:59:27 +02:00
if (xhr.readyState == 4) {
var error = true;
2017-04-06 23:23:25 +02:00
var message = "";
2017-05-19 10:59:27 +02:00
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"]);
error = false;
} else if (root.length) {
errorMsg = getNode(root[0], 'message');
if (errorMsg) { message = errorMsg; }
}
2017-04-06 23:23:25 +02:00
}
}
2017-05-19 10:59:27 +02:00
if (error) {
alert(lang['actionfailure'] + '\n' + message);
}
2017-04-06 23:23:25 +02:00
xhr = null;
}
}
2017-04-11 17:00:40 +02:00
xhr.open('POST', 'utils/changepass.php', true);
2017-04-06 23:23:25 +02:00
xhr.setRequestHeader('Content-type', 'application/x-www-form-urlencoded');
2017-04-12 20:16:39 +02:00
var params = 'oldpass=' + encodeURIComponent(oldpass) + '&pass=' + encodeURIComponent(pass);
params = params.replace(/%20/g, '+');
xhr.send(params);
2017-04-06 23:23:25 +02:00
return;
}