1

I'm working on a plugin for ICN and I've managed to have it log in automatically retrieving the username/password from a file by an id which is passed as a parameter in the url. Once a user has logged in there will be no need to relog, however after some time the 'session expiration' will kick in and even after reloading I can't get it to log in again. This might be due to the fact that I'm basing my decision on a single javascript object: ecm.model.desktop.connected.

Right now if ecm.model.desktop.connected is false it will try to log in, this works well until the session expiration, which apparently does not set the ecm.model.desktop.connected to false, it's still set to true. So I'm hoping to learn a way to tell if the session has expired.

This here is my login code:

if (ecm.model.desktop.connected == false || ecm.model.desktop.userId != loginConfig[loginID].username) {
     var http2 = new XMLHttpRequest();
     var url2 = "/navigator/logon.do";
     var params2 = "userid=" + loginConfig[loginID].username + "&password=" + loginConfig[loginID].password;
     http2.open("POST", url2, false);
     http2.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
     http2.onreadystatechange = function() {//Call a function when the state changes.
          if (http2.readyState == 4 && http2.status == 200) {

          }
     };
     http2.send(params2);
     window.location.reload();
}
4

1 回答 1

0

我管理了一个解决方法,完全使用设置为在“x”分钟内过期的 cookie 来避免会话过期,从而创建一种我自己的会话。首先,我检查是否创建了 cookie,如果不是,则意味着它已经过期或从未创建过,所以我创建它并对 logoff.do 和 reload() 站点进行同步 POST 调用。

一旦创建并重新加载后,我会再次检查 cookie 是否存在,因为它确实会检查 ecm.model.desktop.connected 是否为 false 或用户是否尝试使用不同的 ID 登录。如果发生这种情况,我将让它登录,使用正确的用户名/密码对 logon.do 进行同步 POST 调用,然后重新加载()。

所有完成后,用户现在可以访问我的插件提供的功能。

于 2014-08-01T18:03:44.357 回答