简体   繁体   中英

make logout from profile after timeout

The dleMonitor and script in the code below are not working. Why? I think that timeout block need to be set in template file. I just want to make logout from profile after timeout. Help me please.

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
          "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:ui="http://java.sun.com/jsf/facelets"
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:p="http://primefaces.org/ui">
<h:head>
  <meta content="text/html; charset=UTF-8" http-equiv="Content-Type"/>
  <title>
    <ui:insert name="title">CMS</ui:insert>
  </title>
  <link rel="stylesheet" type="text/css" href="/cms/css/style.css"/>
  <h:outputScript name="jsf.js" library="javax.faces" target="head"/>
  <script type="text/javascript">
     var timeOut = 1000 * 60 * 1; // 30 minutes
     var lastActivity = new Date().getTime();
     var checkTimeout;
     checkTimeOut = function(){
     if(new Date().getTime() > lastActivity + timeOut){
         window.location.replace('http://sidanmor.com');
     }else{
         window.setTimeout(checkTimeOut, 1000); // check once per second
     }
  }
  </script>
</h:head>

<body>
<p:idleMonitor timeout="5000" listener="#{LogoutServlet.service()}"
               onidle="PF('alertExpire').show();">
</p:idleMonitor>
<p:idleMonitor widgetVar="idle" timeout="300" onidle="alert('OK')" />
<div id="minHeight"></div>
<div id="outer">
  <div id="clearheader"></div>
  <div id="nav">
    <ui:include src="/templates/#{mainCms.edition}/nav.xhtml" />
  </div>

  <div id="content">
    <ui:insert name="content" > Content area. </ui:insert>
  </div>
  <div id="clearfooter"></div>
</div>
<div id="footer">
    <a href="http://com.ua/" target="_blank" title="&quot;Дт&quot;">www.com.ua</a>
    </p>
</div>
<div id="header">
  <a href="/cms" class="logo" title="ом">
    <span class="main">г</span>
  </a>
</div>
</body>
</html>

I'll assume that this code

window.location.replace('http://sidanmor.com');

logs you out from the system. So here

var checkTimeout;
checkTimeOut = function(){
    if(new Date().getTime() > lastActivity + timeOut){
        window.location.replace('http://sidanmor.com');
    }else{
        window.setTimeout(checkTimeOut, 1000); // check once per second
    }
}

you are assigning the function into checkTimeout variable without executing it, so adding this

checkTimeout(); // runs the function

will execute the function and run it again every second.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM