Commit 60ce3924 authored by Alain Takoudjou's avatar Alain Takoudjou Committed by Rafael Monnerat

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

parent d0bacf31
/*global window, rJS, RSVP, btoa, XMLHttpRequest, Handlebars */ /*global window, rJS, RSVP, btoa, XMLHttpRequest, Handlebars, jIO */
/*jslint nomen: true, indent: 2, maxerr: 3*/ /*jslint nomen: true, indent: 2, maxerr: 3*/
(function (window, rJS, RSVP, btoa, XMLHttpRequest, Handlebars) { (function (window, rJS, RSVP, btoa, XMLHttpRequest, Handlebars, jIO) {
"use strict"; "use strict";
var gadget_klass = rJS(window), var gadget_klass = rJS(window),
...@@ -108,7 +108,7 @@ ...@@ -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 // Verify if login and password are correct for this URL
if (url === undefined) { if (url === undefined) {
return {status: 'OK'}; return {status: 'OK'};
...@@ -122,6 +122,17 @@ ...@@ -122,6 +122,17 @@
msg: error.msg + ' (' + url + ')', msg: error.msg + ' (' + url + ')',
title: title 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; return ko_msg;
}); });
} }
...@@ -152,7 +163,8 @@ ...@@ -152,7 +163,8 @@
attachment_id: 'enclosure', attachment_id: 'enclosure',
parser: 'opml', parser: 'opml',
sub_storage: { sub_storage: {
type: "http" type: "http",
timeout: 25000 // timeout after 25 seconds
} }
} }
}) })
...@@ -162,25 +174,40 @@ ...@@ -162,25 +174,40 @@
}); });
}) })
.push(undefined, function (error) { .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 gadget.state.message
.innerHTML = notify_msg_template({ .innerHTML = notify_msg_template({
status: 'error', status: 'error',
message: error.target.status + message: code + ": Failed to access OPML URL. " +
": Failed to access OPML URL. " + error.message message_text
}); });
return {data: {total_rows: 0}}; return {data: {total_rows: 0}};
}) })
.push(function (opml_result) { .push(function (opml_result) {
var i, var i,
check_list = [true]; check_list = [true],
new_login;
if (opml_result.data.total_rows > 0) { if (opml_result.data.total_rows > 0) {
opml_dict.title = opml_result.data.rows[0].value.title; 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) { for (i = 1; i < opml_result.data.total_rows; i += 1) {
if (opml_result.data.rows[i].value.url !== undefined) { if (opml_result.data.rows[i].value.url !== undefined) {
check_list.push(checkCredential( check_list.push(checkCredential(
opml_result.data.rows[i].value.url, opml_result.data.rows[i].value.url,
opml_result.data.rows[i].value.title, opml_result.data.rows[i].value.title,
opml_dict.basic_login opml_dict.basic_login,
new_login
)); ));
update_password_list.push({ update_password_list.push({
base_url: opml_result.data.rows[i].value.url, base_url: opml_result.data.rows[i].value.url,
...@@ -195,14 +222,28 @@ ...@@ -195,14 +222,28 @@
}) })
.push(function (status_list) { .push(function (status_list) {
var i, 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) { for (i = 1; i < status_list.length; i += 1) {
if (status_list[i].status !== 'OK') { if (status_list[i].status !== 'OK') {
if (status_list[i].hash !== undefined) {
used_new_passwd_count += 1;
}
error_msg += 'Login/password invalid for instance: ' + error_msg += 'Login/password invalid for instance: ' +
status_list[i].title + '. ' + status_list[i].title + '. ' +
status_list[i].msg + '\n'; 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 !== '') { if (error_msg !== '') {
gadget.state.message gadget.state.message
.innerHTML = notify_msg_template({ .innerHTML = notify_msg_template({
...@@ -352,4 +393,4 @@ ...@@ -352,4 +393,4 @@
return saveOPML(this, form_doc, verify_password); return saveOPML(this, form_doc, verify_password);
}); });
}(window, rJS, RSVP, btoa, XMLHttpRequest, Handlebars)); }(window, rJS, RSVP, btoa, XMLHttpRequest, Handlebars, jIO));
...@@ -242,7 +242,7 @@ ...@@ -242,7 +242,7 @@
</item> </item>
<item> <item>
<key> <string>serial</string> </key> <key> <string>serial</string> </key>
<value> <string>963.29541.62889.7577</string> </value> <value> <string>964.28658.19106.46779</string> </value>
</item> </item>
<item> <item>
<key> <string>state</string> </key> <key> <string>state</string> </key>
...@@ -260,7 +260,7 @@ ...@@ -260,7 +260,7 @@
</tuple> </tuple>
<state> <state>
<tuple> <tuple>
<float>1510680916.21</float> <float>1514476756.65</float>
<string>UTC</string> <string>UTC</string>
</tuple> </tuple>
</state> </state>
......
...@@ -38,10 +38,16 @@ ...@@ -38,10 +38,16 @@
} }
function createStorage(context, storage_spec, key) { function createStorage(context, storage_spec, key) {
if (!context._remote_storage_dict.hasOwnProperty(key)) { var signature;
context._remote_storage_dict[key] = jIO.createJIO(storage_spec); 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 @@ ...@@ -239,7 +239,7 @@
</item> </item>
<item> <item>
<key> <string>serial</string> </key> <key> <string>serial</string> </key>
<value> <string>964.6864.64042.34201</string> </value> <value> <string>964.7018.29631.50551</string> </value>
</item> </item>
<item> <item>
<key> <string>state</string> </key> <key> <string>state</string> </key>
...@@ -257,7 +257,7 @@ ...@@ -257,7 +257,7 @@
</tuple> </tuple>
<state> <state>
<tuple> <tuple>
<float>1513173747.08</float> <float>1514476144.01</float>
<string>UTC</string> <string>UTC</string>
</tuple> </tuple>
</state> </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