techBandhu_asktologin - Version 0.1.5

Version Notes

First Preview Release

Download this release

Release Info

Developer Tech Bandhu
Extension techBandhu_asktologin
Version 0.1.5
Comparing to
See all releases


Version 0.1.5

app/code/community/Techbandhu/Asktologin/Block/Asktologin.php ADDED
@@ -0,0 +1,89 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Magento
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * @category Techbandhu
8
+ * @package Techbandhu_Asktologin
9
+ * @author TechBandhu <techbandhus@gmail.com>
10
+ */
11
+ class Techbandhu_Asktologin_Block_Asktologin extends Mage_Core_Block_Template
12
+ {
13
+ public function _toHtml()
14
+ {
15
+ $html = parent::_toHtml();
16
+ if(!$this->canAsktologin()){
17
+ $html = "";
18
+ }
19
+ return $html;
20
+ }
21
+
22
+ public function canAccess()
23
+ {
24
+ // Set Open Action/controller/Modules
25
+ $action = $this->getRequest()->getActionName();
26
+ $controller = $this->getRequest()->getControllerName();
27
+ $module = $this->getRequest()->getModuleName();
28
+
29
+ $openModule = array('customer');
30
+ $openController = array('account');
31
+ $openActions = array('forgotpassword','create');
32
+
33
+ $modulePattern = '/^(' . implode('|', $openModule) . ')/i';
34
+ $controllerPattern = '/^(' . implode('|', $openController) . ')/i';
35
+ $actionPattern = '/^(' . implode('|', $openActions) . ')/i';
36
+
37
+ $shouldAsk = false;
38
+
39
+ if(!Mage::getSingleton("customer/session")->isLoggedIn())
40
+ {
41
+ if (!preg_match($modulePattern, $module) && !preg_match($controllerPattern, $controller) && !preg_match($actionPattern, $action))
42
+ {
43
+ $shouldAsk = true;
44
+ }
45
+
46
+ if(Mage::getStoreConfig('tb_asktologin/asktologin_option/if_new')){
47
+ if(Mage::getModel('core/cookie')->get("asktologin")==1)
48
+ $shouldAsk = false;
49
+ }
50
+ }
51
+ return $shouldAsk;
52
+ }
53
+
54
+ public function canAsktologin()
55
+ {
56
+ $shouldAsk = false;
57
+ $config = Mage::getStoreConfig('tb_asktologin/asktologin_option/is_active');
58
+ if($config){
59
+ $shouldAsk = $this->canAccess();
60
+ }
61
+ return $shouldAsk;
62
+ }
63
+
64
+ public function newCustomer($confVariable){
65
+ $data = "false";
66
+ $config = Mage::getStoreConfig('tb_asktologin/asktologin_option/if_new');
67
+ if($config){
68
+ $period = 3600 * 24; // for next 24 hour
69
+ Mage::getModel("core/cookie")->set("asktologin", "1", 7200);
70
+ $data = "true";
71
+ }
72
+ return $data;
73
+ }
74
+
75
+ public function getLoginPostActionUrl()
76
+ {
77
+ return Mage::getUrl('asktologin/ajax/login', array('_secure'=>true));
78
+ }
79
+
80
+ public function getForgotPasswordUrl()
81
+ {
82
+ return $this->helper('customer')->getForgotPasswordUrl();
83
+ }
84
+
85
+ public function getCreateAccountUrl()
86
+ {
87
+ return $this->helper('customer')->getRegisterUrl();
88
+ }
89
+ }
app/code/community/Techbandhu/Asktologin/Helper/Data.php ADDED
@@ -0,0 +1,5 @@
 
 
 
 
 
1
+ <?php
2
+ class Techbandhu_Asktologin_Helper_Data extends Mage_Core_Helper_Abstract
3
+ {
4
+
5
+ }
app/code/community/Techbandhu/Asktologin/controllers/AjaxController.php ADDED
@@ -0,0 +1,45 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Magento
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * @category Techbandhu
8
+ * @package Techbandhu_Asktologin
9
+ * @author TechBandhu <techbandhus@gmail.com>
10
+ */
11
+ class Techbandhu_Asktologin_AjaxController extends Mage_Core_Controller_Front_Action
12
+ {
13
+ public function preDispatch()
14
+ {
15
+ parent::preDispatch();
16
+ }
17
+
18
+ /**
19
+ * @uses ajax login
20
+ * @author TechBandhu <techbandhus@gmail.com>
21
+ * */
22
+ public function loginAction(){
23
+ $username = $this->getRequest()->getPost('asktologin_username', false);
24
+ $password = $this->getRequest()->getPost('asktologin_password', false);
25
+ $session = Mage::getSingleton('customer/session');
26
+
27
+ $result = array('success' => false);
28
+
29
+ if ($username && $password) {
30
+ try {
31
+ $session->login($username, $password);
32
+ } catch (Exception $e) {
33
+ $result['error'] = $e->getMessage();
34
+ }
35
+ if (! isset($result['error'])) {
36
+ $result['success'] = true;
37
+ }
38
+ } else {
39
+ $result['error'] = $this->__(
40
+ 'Please enter a username and password.');
41
+ }
42
+ $this->getResponse()->setBody(Zend_Json::encode($result));
43
+ }
44
+
45
+ }
app/code/community/Techbandhu/Asktologin/etc/config.xml ADDED
@@ -0,0 +1,63 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <config>
3
+ <modules>
4
+ <Techbandhu_Asktologin>
5
+ <version>0.1.5</version>
6
+ </Techbandhu_Asktologin>
7
+ </modules>
8
+ <frontend>
9
+ <routers>
10
+ <asktologin>
11
+ <use>standard</use>
12
+ <args>
13
+ <module>Techbandhu_Asktologin</module>
14
+ <frontName>asktologin</frontName>
15
+ </args>
16
+ </asktologin>
17
+ </routers>
18
+ <layout>
19
+ <updates>
20
+ <asktologin>
21
+ <file>asktologin.xml</file>
22
+ </asktologin>
23
+ </updates>
24
+ </layout>
25
+ </frontend>
26
+ <adminhtml>
27
+ <acl>
28
+ <resources>
29
+ <all>
30
+ <title>Allow Everything</title>
31
+ </all>
32
+ <admin>
33
+ <children>
34
+ <system>
35
+ <children>
36
+ <config>
37
+ <children>
38
+ <tb_asktologin>
39
+ <title>Ask To Login</title>
40
+ <sort_order>10</sort_order>
41
+ </tb_asktologin>
42
+ </children>
43
+ </config>
44
+ </children>
45
+ </system>
46
+ </children>
47
+ </admin>
48
+ </resources>
49
+ </acl>
50
+ </adminhtml>
51
+ <global>
52
+ <blocks>
53
+ <asktologin>
54
+ <class>Techbandhu_Asktologin_Block</class>
55
+ </asktologin>
56
+ </blocks>
57
+ <helpers>
58
+ <asktologin>
59
+ <class>Techbandhu_Asktologin_Helper</class>
60
+ </asktologin>
61
+ </helpers>
62
+ </global>
63
+ </config>
app/code/community/Techbandhu/Asktologin/etc/system.xml ADDED
@@ -0,0 +1,51 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <config>
3
+ <tabs>
4
+ <techbandhu_tab translate="label">
5
+ <label>TechBandhu</label>
6
+ <sort_order>100</sort_order>
7
+ </techbandhu_tab>
8
+ </tabs>
9
+ <sections>
10
+ <tb_asktologin translate="label" module="asktologin">
11
+ <label>TechBandhu Ask To Login</label>
12
+ <tab>techbandhu_tab</tab>
13
+ <frontend_type>text</frontend_type>
14
+ <sort_order>30</sort_order>
15
+ <show_in_default>1</show_in_default>
16
+ <show_in_website>1</show_in_website>
17
+ <show_in_store>1</show_in_store>
18
+ <groups>
19
+ <asktologin_option translate="label" module="asktologin">
20
+ <label>Techbandhu Ask To Login</label>
21
+ <frontend_type>text</frontend_type>
22
+ <sort_order>100</sort_order>
23
+ <show_in_default>1</show_in_default>
24
+ <show_in_website>1</show_in_website>
25
+ <show_in_store>1</show_in_store>
26
+ <fields>
27
+ <is_active translate="label">
28
+ <label>Active</label>
29
+ <frontend_type>select</frontend_type>
30
+ <source_model>adminhtml/system_config_source_yesno</source_model>
31
+ <sort_order>10</sort_order>
32
+ <show_in_default>1</show_in_default>
33
+ <show_in_website>1</show_in_website>
34
+ <show_in_store>1</show_in_store>
35
+ </is_active>
36
+ <if_new translate="label">
37
+ <label>For first time only</label>
38
+ <frontend_type>select</frontend_type>
39
+ <source_model>adminhtml/system_config_source_yesno</source_model>
40
+ <sort_order>20</sort_order>
41
+ <show_in_default>1</show_in_default>
42
+ <show_in_website>1</show_in_website>
43
+ <show_in_store>1</show_in_store>
44
+ <comment>Ask to login if user is new to site.</comment>
45
+ </if_new>
46
+ </fields>
47
+ </asktologin_option>
48
+ </groups>
49
+ </tb_asktologin>
50
+ </sections>
51
+ </config>
app/design/frontend/base/default/layout/asktologin.xml ADDED
@@ -0,0 +1,12 @@
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <layout>
3
+ <default>
4
+ <reference name="head">
5
+ <action method="addJs"><script>prototype/window.js</script></action>
6
+ <action method="addItem"><type>js_css</type><name>prototype/windows/themes/default.css</name></action>
7
+ </reference>
8
+ <reference name="content">
9
+ <block type="asktologin/asktologin" name="asktologin" template="asktologin/index.phtml" />
10
+ </reference>
11
+ </default>
12
+ </layout>
app/design/frontend/base/default/template/asktologin/index.phtml ADDED
@@ -0,0 +1,60 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <script type="text/javascript">// <![CDATA[
2
+ document.observe("dom:loaded", function() {
3
+ winAsktologin = new Window({className:'dialog',title:"Ask to login",resizable:false,draggable:false,closable:<?php echo $this->newCustomer()?>,closeOnEsc:<?php echo $this->newCustomer()?>,width:450,height:220,minimizable:false,maximizable:false,showEffectOptions:{duration:0.5},hideEffectOptions:{duration:0.5}});
4
+ winAsktologin.setZIndex(100);
5
+ winAsktologin.showCenter(true);
6
+ winAsktologin.setContent("login-to-buy", false, false);
7
+
8
+ Event.observe('login-button', 'click', function(event){
9
+ $('asktologin-login-form').request({
10
+ onSuccess: function(r){
11
+ var result = r.responseText.evalJSON();
12
+ if(result.success) {
13
+ window.location = window.location;
14
+ } else {
15
+ $('loginerror').show().update(result.error);
16
+ }
17
+ }
18
+ });
19
+ });
20
+ });
21
+
22
+ // ]]>
23
+ </script>
24
+
25
+ <div id="login-to-buy" style="display:none; padding: 10px;">
26
+ <div class="page-title"><h1 class="login-title"><?php echo $this->__('Please login to access site.') ?></h1></div>
27
+ <div id="loginerror" class="error-msg" style="display:none;"></div>
28
+ <div id="login-form-div">
29
+ <form id="asktologin-login-form" method="POST" action="<?php echo $this->getLoginPostActionUrl();?>">
30
+ <ul class="form-list">
31
+ <li>
32
+ <label for="email" class="required"><em>*</em><?php echo $this->__('Email Address') ?></label>
33
+ <div class="input-box">
34
+ <input type="text" name="asktologin_username" value="<?php echo $this->escapeHtml($this->getUsername()) ?>" id="email" class="input-text required-entry validate-email" title="<?php echo $this->__('Email Address') ?>" />
35
+ </div>
36
+ </li>
37
+ <li>
38
+ <label for="pass" class="required"><em>*</em><?php echo $this->__('Password') ?></label>
39
+ <div class="input-box">
40
+ <input type="password" name="asktologin_password" class="input-text required-entry validate-password" id="pass" title="<?php echo $this->__('Password') ?>" />
41
+ </div>
42
+ </li>
43
+ <li><a href="<?php echo $this->getForgotPasswordUrl() ?>" class="f-left"><?php echo $this->__('Forgot Your Password?') ?></a></li>
44
+ <li>
45
+ <button id="login-button" type="button"><?php echo $this->__('Login'); ?></button>
46
+ </li>
47
+ </ul>
48
+ </form>
49
+ </div>
50
+ <div>
51
+ <a href="<?php echo $this->getCreateAccountUrl() ?>" class="f-right"><?php echo $this->__('New Customers?') ?></a>
52
+ </div>
53
+ </div>
54
+
55
+ <style>
56
+ .overlay_dialog{
57
+ background-color:#000;
58
+ }
59
+ h1.login-title {color:#fff;}
60
+ </style>
app/etc/modules/Techbandhu_Asktologin.xml ADDED
@@ -0,0 +1,20 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <!--
3
+ /**
4
+ * Magento
5
+ *
6
+ * NOTICE OF LICENSE
7
+ *
8
+ * @category Techbandhu
9
+ * @package Techbandhu_Asktologin
10
+ * @author TechBandhu <techbandhus@gmail.com>
11
+ */
12
+ -->
13
+ <config>
14
+ <modules>
15
+ <Techbandhu_Asktologin>
16
+ <active>true</active>
17
+ <codePool>community</codePool>
18
+ </Techbandhu_Asktologin>
19
+ </modules>
20
+ </config>
package.xml ADDED
@@ -0,0 +1,18 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <package>
3
+ <name>techBandhu_asktologin</name>
4
+ <version>0.1.5</version>
5
+ <stability>stable</stability>
6
+ <license>http://opensource.org/licenses/osl-3.0.php</license>
7
+ <channel>community</channel>
8
+ <extends/>
9
+ <summary>forced popup login boxes</summary>
10
+ <description>Forced popup login boxes</description>
11
+ <notes>First Preview Release</notes>
12
+ <authors><author><name>Tech Bandhu</name><user>techbandhu</user><email>techbandhus@gmail.com</email></author></authors>
13
+ <date>2013-11-13</date>
14
+ <time>09:44:01</time>
15
+ <contents><target name="mageetc"><dir name="modules"><file name="Techbandhu_Asktologin.xml" hash="0cdd96d33eb6120502589f33e1ad7f1e"/></dir></target><target name="magecommunity"><dir name="Techbandhu"><dir name="Asktologin"><dir name="Block"><file name="Asktologin.php" hash="73455a02ecea4b313bc79b97c7738680"/></dir><dir name="Helper"><file name="Data.php" hash="9604c16af193df5636c7bc11a1b01fe9"/></dir><dir name="controllers"><file name="AjaxController.php" hash="c97e26a7a8a87e251ad8177eba9c465d"/></dir><dir name="etc"><file name="config.xml" hash="84689c0bf51a753efc3a1680554cdbed"/><file name="system.xml" hash="f1e8a092fd1762d8798de31c3e50a442"/></dir></dir></dir></target><target name="magedesign"><dir name="frontend"><dir name="base"><dir name="default"><dir name="layout"><file name="asktologin.xml" hash="074477a5bc691a6473f77e31b6bea11b"/></dir><dir name="template"><dir name="asktologin"><file name="index.phtml" hash="0488ecd5be474eb8ea6a471363b5991a"/></dir></dir></dir></dir></dir></target></contents>
16
+ <compatible/>
17
+ <dependencies><required><php><min>5.1.0</min><max>6.0.0</max></php></required></dependencies>
18
+ </package>