Commit d8c5e5d2 authored by Alain Takoudjou's avatar Alain Takoudjou

[erp5_web_monitoring] fix problem of changing password when current password is broken

parent fa0c0c85
/*global window, rJS, RSVP, btoa, XMLHttpRequest, Handlebars */
/*global window, rJS, RSVP, btoa, XMLHttpRequest, Handlebars, jIO */
/*jslint nomen: true, indent: 2, maxerr: 3*/
(function (window, rJS, RSVP, btoa, XMLHttpRequest, Handlebars) {
(function (window, rJS, RSVP, btoa, XMLHttpRequest, Handlebars, jIO) {
"use strict";
var gadget_klass = rJS(window),
......@@ -108,7 +108,7 @@
});
}
function checkCredential(url, title, hash) {
function checkCredential(url, title, hash, new_hash) {
// Verify if login and password are correct for this URL
if (url === undefined) {
return {status: 'OK'};
......@@ -122,6 +122,17 @@
msg: error.msg + ' (' + url + ')',
title: title
};
if (new_hash !== undefined) {
// saved password is not valid
// check if inputted password is valid
return testUrl(url, new_hash)
.then(function () {
ko_msg.hash = new_hash;
return ko_msg;
}, function () {
return ko_msg;
});
}
return ko_msg;
});
}
......@@ -152,7 +163,8 @@
attachment_id: 'enclosure',
parser: 'opml',
sub_storage: {
type: "http"
type: "http",
timeout: 25000 // timeout after 25 seconds
}
}
})
......@@ -162,25 +174,40 @@
});
})
.push(undefined, function (error) {
var message_text,
code;
if (error instanceof jIO.util.jIOError) {
message_text = error.message;
code = error.status_code;
} else {
code = error.target.status;
message_text = error.target.responseType === "text" ?
error.target.statusText : "";
}
gadget.state.message
.innerHTML = notify_msg_template({
status: 'error',
message: error.target.status +
": Failed to access OPML URL. " + error.message
message: code + ": Failed to access OPML URL. " +
message_text
});
return {data: {total_rows: 0}};
})
.push(function (opml_result) {
var i,
check_list = [true];
check_list = [true],
new_login;
if (opml_result.data.total_rows > 0) {
opml_dict.title = opml_result.data.rows[0].value.title;
if (doc.new_password) {
new_login = btoa(doc.username + ':' + doc.new_password);
}
for (i = 1; i < opml_result.data.total_rows; i += 1) {
if (opml_result.data.rows[i].value.url !== undefined) {
check_list.push(checkCredential(
opml_result.data.rows[i].value.url,
opml_result.data.rows[i].value.title,
opml_dict.basic_login
opml_dict.basic_login,
new_login
));
update_password_list.push({
base_url: opml_result.data.rows[i].value.url,
......@@ -195,14 +222,28 @@
})
.push(function (status_list) {
var i,
error_msg = '';
error_msg = '',
used_new_passwd_count = 0;
// in case the current password in opml is wrong and new
// password provided is OK, we set it as the current password in opml.
for (i = 1; i < status_list.length; i += 1) {
if (status_list[i].status !== 'OK') {
if (status_list[i].hash !== undefined) {
used_new_passwd_count += 1;
}
error_msg += 'Login/password invalid for instance: ' +
status_list[i].title + '. ' +
status_list[i].msg + '\n';
}
}
if (used_new_passwd_count > 0 &&
used_new_passwd_count === (status_list.length - 1)) {
// all backends password are OK, we only update our password
opml_dict.password = doc.new_password;
doc.new_password = '';
opml_dict.basic_login = status_list[1].hash;
return true;
}
if (error_msg !== '') {
gadget.state.message
.innerHTML = notify_msg_template({
......@@ -352,4 +393,4 @@
return saveOPML(this, form_doc, verify_password);
});
}(window, rJS, RSVP, btoa, XMLHttpRequest, Handlebars));
}(window, rJS, RSVP, btoa, XMLHttpRequest, Handlebars, jIO));
......@@ -242,7 +242,7 @@
</item>
<item>
<key> <string>serial</string> </key>
<value> <string>963.29541.62889.7577</string> </value>
<value> <string>964.28658.19106.46779</string> </value>
</item>
<item>
<key> <string>state</string> </key>
......@@ -260,7 +260,7 @@
</tuple>
<state>
<tuple>
<float>1510680916.21</float>
<float>1514476756.65</float>
<string>UTC</string>
</tuple>
</state>
......
......@@ -38,10 +38,16 @@
}
function createStorage(context, storage_spec, key) {
if (!context._remote_storage_dict.hasOwnProperty(key)) {
context._remote_storage_dict[key] = jIO.createJIO(storage_spec);
var signature;
signature = generateHash(JSON.stringify(storage_spec));
if (!context._remote_storage_dict.hasOwnProperty(key) ||
signature !== context._remote_storage_dict[key].signature) {
context._remote_storage_dict[key] = {
storage: jIO.createJIO(storage_spec),
signature: signature
};
}
return context._remote_storage_dict[key];
return context._remote_storage_dict[key].storage;
}
/**
......
......@@ -239,7 +239,7 @@
</item>
<item>
<key> <string>serial</string> </key>
<value> <string>964.6864.64042.34201</string> </value>
<value> <string>964.7018.29631.50551</string> </value>
</item>
<item>
<key> <string>state</string> </key>
......@@ -257,7 +257,7 @@
</tuple>
<state>
<tuple>
<float>1513173747.08</float>
<float>1514476144.01</float>
<string>UTC</string>
</tuple>
</state>
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment