Version Notes
Very first release
Download this release
Release Info
| Developer | Magento Core Team |
| Extension | notifications_sessionticker |
| Version | 0.1.0 |
| Comparing to | |
| See all releases | |
Version 0.1.0
- app/code/local/Notifications/SessionTicker/Block/Sessionticker.php +27 -0
- app/code/local/Notifications/SessionTicker/Helper/Data.php +17 -0
- app/code/local/Notifications/SessionTicker/controllers/SessiontickerController.php +21 -0
- app/code/local/Notifications/SessionTicker/etc/config.xml +46 -0
- app/design/frontend/base/default/layout/sessionticker.xml +10 -0
- app/etc/modules/Notifications_SessionTicker.xml +9 -0
- js/notifications/sessionTicker.js +52 -0
- package.xml +18 -0
app/code/local/Notifications/SessionTicker/Block/Sessionticker.php
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<?php
|
| 2 |
+
class Notifications_SessionTicker_Block_Sessionticker extends Mage_Core_Block_Abstract
|
| 3 |
+
{
|
| 4 |
+
var $helper = NULL;
|
| 5 |
+
|
| 6 |
+
/* constructor to initialize helper property */
|
| 7 |
+
public function __construct() {
|
| 8 |
+
$this->helper = Mage::helper('sessionticker');
|
| 9 |
+
}
|
| 10 |
+
|
| 11 |
+
/**
|
| 12 |
+
* append sessionticker js class and object to initiate xmlHttpRequests in background and check login status on regular cookie lifetime interval
|
| 13 |
+
* @param script name
|
| 14 |
+
* @return Notifications_SessionTicker_Block_Sessionticker
|
| 15 |
+
*/
|
| 16 |
+
public function initiateRequests($script) {
|
| 17 |
+
if($this->helper->isCustomerLoggedIn()) {
|
| 18 |
+
$headBlock = $this->getLayout()->getBlock('head');
|
| 19 |
+
$headBlock->addJs($script);
|
| 20 |
+
$tickInterval = Mage::getModel('core/cookie')->getLifetime() * 1000; // frontend session cookie lifetime in miliseconds
|
| 21 |
+
$headBlock->append(
|
| 22 |
+
$this->getLayout()->createBlock('core/text', 'sessionticker-initiation')->setText('<script type="text/javascript">var isLoggedIn=true; document.observe("dom:loaded", function(){'.'new sessionTimeoutTick('.$tickInterval.', "'. $this->helper->getTickUrl() .'");});'.'</script>')
|
| 23 |
+
);
|
| 24 |
+
}
|
| 25 |
+
return $this;
|
| 26 |
+
}
|
| 27 |
+
}
|
app/code/local/Notifications/SessionTicker/Helper/Data.php
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<?php
|
| 2 |
+
class Notifications_SessionTicker_Helper_Data extends Mage_Customer_Helper_Data
|
| 3 |
+
{
|
| 4 |
+
public function isCustomerLoggedIn()
|
| 5 |
+
{
|
| 6 |
+
return $this->_getCustomerSession()->isLoggedIn();
|
| 7 |
+
}
|
| 8 |
+
|
| 9 |
+
private function _getCustomerSession()
|
| 10 |
+
{
|
| 11 |
+
return Mage::getSingleton('customer/session');
|
| 12 |
+
}
|
| 13 |
+
|
| 14 |
+
public function getTickUrl() {
|
| 15 |
+
return $this->_getUrl('sessionticker/sessionticker/tick');
|
| 16 |
+
}
|
| 17 |
+
}
|
app/code/local/Notifications/SessionTicker/controllers/SessiontickerController.php
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<?php
|
| 2 |
+
class Notifications_SessionTicker_SessiontickerController extends Mage_Core_Controller_Front_Action
|
| 3 |
+
{
|
| 4 |
+
public function tickAction()
|
| 5 |
+
{
|
| 6 |
+
$this->_getResponse()->setHeader('Last-Modified', gmdate("D, d M Y H:i:s") . ' GMT');
|
| 7 |
+
$this->_getResponse()->setHeader('Expires', gmdate("D, d M Y H:i:s") . ' GMT', true);
|
| 8 |
+
$this->_getResponse()->setHeader('Pragma', 'no-cache', true);
|
| 9 |
+
$this->_getResponse()->setHeader('Cache-Control', 'no-store, no-cache, must-revalidate, max-age=0', true);
|
| 10 |
+
$this->getResponse()->setBody($this->getLayout()->createBlock('core/text')->setText(json_encode( array('ok' => $this->getHelper()->isCustomerLoggedIn() ) ))->toHtml());
|
| 11 |
+
}
|
| 12 |
+
|
| 13 |
+
public function getHelper() {
|
| 14 |
+
return Mage::helper('sessionticker');
|
| 15 |
+
}
|
| 16 |
+
|
| 17 |
+
protected function _getResponse()
|
| 18 |
+
{
|
| 19 |
+
return Mage::app()->getResponse();
|
| 20 |
+
}
|
| 21 |
+
}
|
app/code/local/Notifications/SessionTicker/etc/config.xml
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<?xml version="1.0" encoding="utf-8"?>
|
| 2 |
+
<!--
|
| 3 |
+
/**************************************************************************************\
|
| 4 |
+
* Name: config.xml *
|
| 5 |
+
* Author: Ankit Jadav *
|
| 6 |
+
* Version: 0.1.0 *
|
| 7 |
+
* Description: configuration file for sessionticker module *
|
| 8 |
+
\**************************************************************************************/
|
| 9 |
+
-->
|
| 10 |
+
<config>
|
| 11 |
+
<modules>
|
| 12 |
+
<Notifications_SessionTicker>
|
| 13 |
+
<version>0.1.0</version>
|
| 14 |
+
</Notifications_SessionTicker>
|
| 15 |
+
</modules>
|
| 16 |
+
<frontend>
|
| 17 |
+
<routers>
|
| 18 |
+
<sessionticker>
|
| 19 |
+
<use>standard</use>
|
| 20 |
+
<args>
|
| 21 |
+
<module>Notifications_SessionTicker</module>
|
| 22 |
+
<frontName>sessionticker</frontName>
|
| 23 |
+
</args>
|
| 24 |
+
</sessionticker>
|
| 25 |
+
</routers>
|
| 26 |
+
<layout>
|
| 27 |
+
<updates>
|
| 28 |
+
<sessionticker module="Notifications_SessionTicker">
|
| 29 |
+
<file>sessionticker.xml</file>
|
| 30 |
+
</sessionticker>
|
| 31 |
+
</updates>
|
| 32 |
+
</layout>
|
| 33 |
+
</frontend>
|
| 34 |
+
<global>
|
| 35 |
+
<blocks>
|
| 36 |
+
<sessionticker>
|
| 37 |
+
<class>Notifications_SessionTicker_Block</class>
|
| 38 |
+
</sessionticker>
|
| 39 |
+
</blocks>
|
| 40 |
+
<helpers>
|
| 41 |
+
<sessionticker>
|
| 42 |
+
<class>Notifications_SessionTicker_Helper</class>
|
| 43 |
+
</sessionticker>
|
| 44 |
+
</helpers>
|
| 45 |
+
</global>
|
| 46 |
+
</config>
|
app/design/frontend/base/default/layout/sessionticker.xml
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<?xml version="1.0"?>
|
| 2 |
+
<layout version="0.1.0">
|
| 3 |
+
<default>
|
| 4 |
+
<reference name="head">
|
| 5 |
+
<block type="sessionticker/sessionticker" name="sessionticker.block" as="sessionticker_block">
|
| 6 |
+
<action method="initiateRequests"><script>notifications/sessionTicker.js</script></action>
|
| 7 |
+
</block>
|
| 8 |
+
</reference>
|
| 9 |
+
</default>
|
| 10 |
+
</layout>
|
app/etc/modules/Notifications_SessionTicker.xml
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<?xml version="1.0"?>
|
| 2 |
+
<config>
|
| 3 |
+
<modules>
|
| 4 |
+
<Notifications_SessionTicker>
|
| 5 |
+
<codePool>local</codePool>
|
| 6 |
+
<active>true</active>
|
| 7 |
+
</Notifications_SessionTicker>
|
| 8 |
+
</modules>
|
| 9 |
+
</config>
|
js/notifications/sessionTicker.js
ADDED
|
@@ -0,0 +1,52 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/*********************************************************************************\
|
| 2 |
+
* Name: SessionTicker *
|
| 3 |
+
* Author: Ankit Jadav *
|
| 4 |
+
* Version: 0.1.0 *
|
| 5 |
+
* Description: notify logged in user if session expires *
|
| 6 |
+
\*********************************************************************************/
|
| 7 |
+
|
| 8 |
+
function sessionTimeoutTick(tickInterval, loginCheckUrl) {
|
| 9 |
+
if(loginCheckUrl == null) return false;
|
| 10 |
+
if(parseInt(tickInterval) <= 0) {
|
| 11 |
+
tickInterval = 60*15*1000; // by default set call timeout to 15 minutes
|
| 12 |
+
}
|
| 13 |
+
this.t_check = null;
|
| 14 |
+
this.tickInterval = tickInterval;
|
| 15 |
+
this.loginCheckUrl = loginCheckUrl;
|
| 16 |
+
|
| 17 |
+
this.queueAsynchRequest();
|
| 18 |
+
}
|
| 19 |
+
|
| 20 |
+
/**
|
| 21 |
+
* queue xmlHttpRequest
|
| 22 |
+
* @param
|
| 23 |
+
* @return
|
| 24 |
+
*/
|
| 25 |
+
sessionTimeoutTick.prototype.queueAsynchRequest = function(){
|
| 26 |
+
obj = this;
|
| 27 |
+
this.t_check = setTimeout(function(){ obj.checkIsLoggedIn(); }, obj.tickInterval);
|
| 28 |
+
}
|
| 29 |
+
|
| 30 |
+
/**
|
| 31 |
+
* send xmlHttpRequest and notify or queue next request based on response
|
| 32 |
+
* @param
|
| 33 |
+
* @return
|
| 34 |
+
*/
|
| 35 |
+
sessionTimeoutTick.prototype.checkIsLoggedIn = function(){
|
| 36 |
+
var dt = new Date();
|
| 37 |
+
var loginCheckUrl = (this.loginCheckUrl).substr(0, (pos=(this.loginCheckUrl).indexOf('?')!=-1?pos:(this.loginCheckUrl).length))+'?'+dt.getTime();
|
| 38 |
+
obj = this;
|
| 39 |
+
new Ajax.Request(loginCheckUrl, {
|
| 40 |
+
method: "post",
|
| 41 |
+
onComplete: function(transport) {
|
| 42 |
+
var data = (transport.responseText).evalJSON();
|
| 43 |
+
if(data.ok) {
|
| 44 |
+
clearInterval(this.t_check);
|
| 45 |
+
obj.queueAsynchRequest();
|
| 46 |
+
} else if(window.isLoggedIn) {
|
| 47 |
+
alert('You have been signed out due to inactivity. Please sign in again.');
|
| 48 |
+
location.reload();
|
| 49 |
+
}
|
| 50 |
+
}
|
| 51 |
+
});
|
| 52 |
+
}
|
package.xml
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<?xml version="1.0"?>
|
| 2 |
+
<package>
|
| 3 |
+
<name>notifications_sessionticker</name>
|
| 4 |
+
<version>0.1.0</version>
|
| 5 |
+
<stability>stable</stability>
|
| 6 |
+
<license uri="http://www.opensource.org/licenses/osl-3.0.php">OSL</license>
|
| 7 |
+
<channel>community</channel>
|
| 8 |
+
<extends/>
|
| 9 |
+
<summary>Notify customer when session expires</summary>
|
| 10 |
+
<description>This extension let the customer know when he/she forcefully been logged out.</description>
|
| 11 |
+
<notes>Very first release</notes>
|
| 12 |
+
<authors><author><name>Ankit</name><user>auto-converted</user><email>ankit_jadavce@yahoo.com</email></author></authors>
|
| 13 |
+
<date>2012-05-10</date>
|
| 14 |
+
<time>11:18:23</time>
|
| 15 |
+
<contents><target name="magelocal"><dir name="Notifications"><dir name="SessionTicker"><dir name="Block"><file name="Sessionticker.php" hash="98d20a4c5da3318f0e07b719fe53d11a"/></dir><dir name="Helper"><file name="Data.php" hash="72461b08dde3fbb9e16737052f7f503e"/></dir><dir name="controllers"><file name="SessiontickerController.php" hash="5a45706565b2f6f17db69f3e88878492"/></dir><dir name="etc"><file name="config.xml" hash="bbf5eb20e37705c151daf538147f82b8"/></dir></dir></dir></target><target name="magedesign"><dir name="frontend"><dir name="base"><dir name="default"><dir name="layout"><file name="sessionticker.xml" hash="052649d167eb7e301fad2a1562c72130"/></dir></dir></dir></dir></target><target name="mageetc"><dir name="modules"><file name="Notifications_SessionTicker.xml" hash="99dcb3715bd70042ba7ae3daeac7e187"/></dir></target><target name="mage"><dir name="js"><dir name="notifications"><file name="sessionTicker.js" hash="9651462244aa083b083d59e3474f781d"/></dir></dir></target></contents>
|
| 16 |
+
<compatible/>
|
| 17 |
+
<dependencies/>
|
| 18 |
+
</package>
|
