|
I have a working remember me checkbox. Below are modified instructions from previous posts on how i got it working and how to write it so that it is not modifying core code.
1st
Create app/etc/modules/MyModule_all.xml
<?xml version="1.0" encoding="utf-8"?>
<MyModule_Core> <active>true</active> <codePool>local</codePool> </MyModule_Core>
Create app/code/local/MyModule/Core/Model/etc/config.xml
<?xml version="1.0" encoding="utf-8"?> <config> <global> <models> <core> <rewrite> <cookie>MyModule_Core_Model_Cookie</cookie> </rewrite> </core> </models> </global> </config>
Create app/code/local/MyModule/Core/Model/Cookie.php
<?php
class MyModule_Core_Model_Cookie extends Mage_Core_Model_Cookie { const XML_PATH_COOKIE_LIFETIME_LONG = 'web/cookie2/cookie_lifetime2';
public function getLifetime() { if (isset($_POST['rememberme'])){ $lifetime = Mage::getStoreConfig(self::XML_PATH_COOKIE_LIFETIME_LONG, $this->getStore()); return $lifetime; }else{ if (null !== $this->_lifetime) { $lifetime = $this->_lifetime; } else { $lifetime = Mage::getStoreConfig(self::XML_PATH_COOKIE_LIFETIME, $this->getStore()); } if (!is_numeric($lifetime)) { $lifetime = 3600; } return $lifetime; } }
}
?>
main thing to note in the above and what i changed from the original posted file is the line
if (isset($_POST['rememberme'])){
in the original post it says to use
if (isset($_REQUEST['rememberme'])){
for me this did not work, but using POST did.
Next create app/code/local/MyModule/Core/Model/etc/system.xml
<?xml version="1.0" encoding="utf-8"?> <config> <sections> <web> <groups> <cookie2 translate="label"> <label>Session Cookie User Management</label> <frontend_type>text</frontend_type> <sort_order>51</sort_order> <show_in_default>1</show_in_default> <show_in_website>1</show_in_website> <show_in_store>1</show_in_store> <fields> <cookie_lifetime2 translate="label"> <label>Cookie Lifetime</label> <frontend_type>text</frontend_type> <sort_order>30</sort_order> <show_in_default>1</show_in_default> <show_in_website>1</show_in_website> <show_in_store>1</show_in_store> </cookie_lifetime2>
</fields> </cookie2> </groups> </web> </sections> </config>
Next add the following code to app/design/frontend/YourInstanceName/YourThemeName/template/customer/form/login.phtml
<div> <input type="checkbox" name="rememberme" value="remember"> Remember me. </div>
use the div block to style it how you like, make sure to place it in the html of the login form.
To test i set normal cookie lifetime to 60 seconds, new cookie lifetime to 360 seconds. If i log in and don’t select remember me I get logged off after a minute, if i log in and click the remember me box i get logged off after 6 minutes.
Thanks to all the previous posters for this made working out how to do it so much easier!
Shaun
|