extend session of Liferay when performing AJAX call

柔情痞子 提交于 2019-11-30 05:27:05

I had same issue and solved it. The main idea is to override session.js into ext-plugin, and add some additional method:

extendExternal: function() {
  var instance = this;

  if (instance != undefined) {
    instance.extend();
  }
}

also setCookie method should be updated:

 setCookie: function(status) {
   var instance = this;

   var currentTime = new Date().getTime();

   var options = {
      secure: A.UA.secure,
      path: "/"
   };

   A.Cookie.set(instance._cookieKey, status || currentTime, options);
 }

In order to use the same cookie path for each page.

And some global ajax event can be used for 'automatical' call of extendExternal method:

AUI().use('event', function(A){
 A.on('io:start', function(transactionid, arguments){
   if (Liferay.Session._cookieKey != undefined && Liferay.Session._cookieKey != null) {
     if (arguments != 'sessionExtend') {
       Liferay.Session.extendExternal();
     }
   }
 });
});

in this case extend method have to be updated with:

// added in order to differentiate session extend ajax calls and other ajax call, to     avoid infinit loop
 A.io.request(instance._sessionUrls.extend, {
    arguments: 'sessionExtend'
 });

You can check solution here.

Liferay.Session.extend(); is the answer, i didnt notice that the session is extended when testing the code

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!