DigitalPianism_AjaxLogin - Version 0.1.1

Version Notes

- Original release.

Download this release

Release Info

Developer Digital Pianism
Extension DigitalPianism_AjaxLogin
Version 0.1.1
Comparing to
See all releases


Version 0.1.1

app/code/community/DigitalPianism/AjaxLogin/Helper/Data.php ADDED
@@ -0,0 +1,16 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class DigitalPianism_AjaxLogin_Helper_Data extends Mage_Core_Helper_Abstract {
4
+
5
+ protected $logFileName = 'digitalpianism_ajaxlogin.log';
6
+
7
+ /**
8
+ * Log data
9
+ * @param string|object|array data to log
10
+ */
11
+ public function log($data)
12
+ {
13
+ Mage::log($data, null, $this->logFileName);
14
+ }
15
+
16
+ }
app/code/community/DigitalPianism/AjaxLogin/controllers/IndexController.php ADDED
@@ -0,0 +1,115 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class DigitalPianism_AjaxLogin_IndexController extends Mage_Core_Controller_Front_Action
4
+ {
5
+
6
+ public function forgotpasswordAction()
7
+ {
8
+ $session = Mage::getSingleton('customer/session');
9
+
10
+ if ($session->isLoggedIn()) {
11
+ return;
12
+ }
13
+
14
+ $email = $this->getRequest()->getPost('email');
15
+ $result = array(
16
+ 'success' => false
17
+ );
18
+ if ($email) {
19
+ if (!Zend_Validate::is($email, 'EmailAddress')) {
20
+ $session->setForgottenEmail($email);
21
+ $result['error'] = Mage::helper('checkout')->__('Invalid email address.');
22
+ } else {
23
+ $customer = Mage::getModel('customer/customer')
24
+ ->setWebsiteId(Mage::app()->getStore()->getWebsiteId())
25
+ ->loadByEmail($email);
26
+
27
+ if ($customer->getId()) {
28
+ try {
29
+ $customerHelper = Mage::helper('customer');
30
+ if (method_exists($customerHelper, 'generateResetPasswordLinkToken')) {
31
+ $newResetPasswordLinkToken = Mage::helper('customer')->generateResetPasswordLinkToken();
32
+ $customer->changeResetPasswordLinkToken($newResetPasswordLinkToken);
33
+ $customer->sendPasswordResetConfirmationEmail();
34
+ } else {
35
+ // 1.6.0.x and earlier
36
+ $newPassword = $customer->generatePassword();
37
+ $customer->changePassword($newPassword, false);
38
+ $customer->sendPasswordReminderEmail();
39
+ $result['message'] = Mage::helper('customer')->__('A new password has been sent.');
40
+ }
41
+ $result['success'] = true;
42
+ } catch (Exception $e) {
43
+ $result['error'] = $e->getMessage();
44
+ }
45
+ }
46
+ if (!isset($result['message']) && ($result['success'] || !$customer->getId())) {
47
+ $result['message'] = Mage::helper('customer')->__('If there is an account associated with %s you will receive an email with a link to reset your password.', Mage::helper('customer')->escapeHtml($email));
48
+ }
49
+ }
50
+ } else {
51
+ $result['error'] = Mage::helper('customer')->__('Please enter your email.');
52
+ }
53
+
54
+ $this->getResponse()->setBody(Mage::helper('core')->jsonEncode($result));
55
+ }
56
+
57
+ public function loginAction()
58
+ {
59
+ $session = Mage::getSingleton('customer/session');
60
+
61
+ if ($session->isLoggedIn()) {
62
+ return;
63
+ }
64
+
65
+ $result = array(
66
+ 'success' => false
67
+ );
68
+
69
+ if ($this->getRequest()->isPost()) {
70
+ $login = $this->getRequest()->getPost('login');
71
+ if (!empty($login['username']) && !empty($login['password'])) {
72
+ try {
73
+ $session->login($login['username'], $login['password']);
74
+ $result['redirect'] = $this->_getRefererUrl() ? $this->_getRefererUrl() : Mage::getUrl('customer/account', array('_secure' => true));
75
+ $result['success'] = true;
76
+ } catch (Mage_Core_Exception $e) {
77
+ switch ($e->getCode()) {
78
+ case Mage_Customer_Model_Customer::EXCEPTION_EMAIL_NOT_CONFIRMED:
79
+ $message = Mage::helper('customer')->__('This account is not confirmed. <a href="%s">Click here</a> to resend confirmation email.', Mage::helper('customer')->getEmailConfirmationUrl($login['username']));
80
+ break;
81
+ case Mage_Customer_Model_Customer::EXCEPTION_INVALID_EMAIL_OR_PASSWORD:
82
+ $message = $e->getMessage();
83
+ break;
84
+ default:
85
+ $message = $e->getMessage();
86
+ }
87
+ $result['error'] = $message;
88
+ $session->setUsername($login['username']);
89
+ } catch (Exception $e) {
90
+ Mage::helper("ajaxlogin")->log("There has been an error during the login.");
91
+ // Mage::logException($e); // PA DSS violation: this exception log can disclose customer password
92
+ }
93
+ } else {
94
+ $result['error'] = Mage::helper('customer')->__('Login and password are required.');
95
+ }
96
+ }
97
+
98
+ $this->getResponse()->setBody(Mage::helper('core')->jsonEncode($result));
99
+ }
100
+
101
+ public function logoutAction()
102
+ {
103
+ $session = Mage::getSingleton('customer/session');
104
+
105
+ if (!$session->isLoggedIn()) {
106
+ return;
107
+ }
108
+
109
+ $session->logout()->renewSession();
110
+ $result['redirect'] = Mage::getUrl('customer/account/logoutSuccess', array('_secure' => true));
111
+ $result['success'] = true;
112
+
113
+ $this->getResponse()->setBody(Mage::helper('core')->jsonEncode($result));
114
+ }
115
+ }
app/code/community/DigitalPianism/AjaxLogin/etc/adminhtml.xml ADDED
@@ -0,0 +1,25 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0" ?>
2
+ <config>
3
+ <acl>
4
+ <resources>
5
+ <all>
6
+ <title>Allow Everything</title>
7
+ </all>
8
+ <admin>
9
+ <children>
10
+ <system>
11
+ <children>
12
+ <config>
13
+ <children>
14
+ <ajaxlogin>
15
+ <title>AJAX Login</title>
16
+ </ajaxlogin>
17
+ </children>
18
+ </config>
19
+ </children>
20
+ </system>
21
+ </children>
22
+ </admin>
23
+ </resources>
24
+ </acl>
25
+ </config>
app/code/community/DigitalPianism/AjaxLogin/etc/config.xml ADDED
@@ -0,0 +1,40 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <config>
3
+ <modules>
4
+ <DigitalPianism_AjaxLogin>
5
+ <version>0.1.1</version>
6
+ </DigitalPianism_AjaxLogin>
7
+ </modules>
8
+ <global>
9
+ <helpers>
10
+ <ajaxlogin>
11
+ <class>DigitalPianism_AjaxLogin_Helper</class>
12
+ </ajaxlogin>
13
+ </helpers>
14
+ </global>
15
+ <frontend>
16
+ <routers>
17
+ <ajaxlogin>
18
+ <use>standard</use>
19
+ <args>
20
+ <module>DigitalPianism_AjaxLogin</module>
21
+ <frontName>ajaxlogin</frontName>
22
+ </args>
23
+ </ajaxlogin>
24
+ </routers>
25
+ <layout>
26
+ <updates>
27
+ <DigitalPianism_AjaxLogin>
28
+ <file>digitalpianism/ajaxlogin.xml</file>
29
+ </DigitalPianism_AjaxLogin>
30
+ </updates>
31
+ </layout>
32
+ </frontend>
33
+ <default>
34
+ <ajaxlogin>
35
+ <options>
36
+ <enable>1</enable>
37
+ </options>
38
+ </ajaxlogin>
39
+ </default>
40
+ </config>
app/code/community/DigitalPianism/AjaxLogin/etc/system.xml ADDED
@@ -0,0 +1,40 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <config>
3
+ <tabs>
4
+ <digitalpianism translate="label" module="ajaxlogin">
5
+ <label>Digital Pianism</label>
6
+ <sort_order>101</sort_order>
7
+ </digitalpianism>
8
+ </tabs>
9
+ <sections>
10
+ <ajaxlogin translate="label" module="ajaxlogin">
11
+ <label>Ajax Login</label>
12
+ <tab>digitalpianism</tab>
13
+ <sort_order>1000</sort_order>
14
+ <show_in_default>1</show_in_default>
15
+ <show_in_website>1</show_in_website>
16
+ <show_in_store>1</show_in_store>
17
+ <groups>
18
+ <options translate="label">
19
+ <label>Settings</label>
20
+ <frontend_type>text</frontend_type>
21
+ <sort_order>0</sort_order>
22
+ <show_in_default>1</show_in_default>
23
+ <show_in_website>1</show_in_website>
24
+ <show_in_store>1</show_in_store>
25
+ <fields>
26
+ <enable translate="label">
27
+ <label>Enable</label>
28
+ <frontend_type>select</frontend_type>
29
+ <source_model>adminhtml/system_config_source_yesno</source_model>
30
+ <sort_order>1</sort_order>
31
+ <show_in_default>1</show_in_default>
32
+ <show_in_website>1</show_in_website>
33
+ <show_in_store>1</show_in_store>
34
+ </enable>
35
+ </fields>
36
+ </options>
37
+ </groups>
38
+ </ajaxlogin>
39
+ </sections>
40
+ </config>
app/design/frontend/base/default/layout/digitalpianism/ajaxlogin.xml ADDED
@@ -0,0 +1,60 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <layout version="0.1.0">
3
+
4
+ <default>
5
+ <reference name="head">
6
+ <action method="addItem">
7
+ <type>skin_css</type>
8
+ <name>css/digitalpianism/ajaxlogin/styles.css</name>
9
+ <params/>
10
+ </action>
11
+ <action method="addItem">
12
+ <type>skin_js</type>
13
+ <name>js/digitalpianism/ajaxlogin/script.js</name>
14
+ </action>
15
+ </reference>
16
+ <reference name="before_body_end">
17
+ <block type="core/template" name="ajaxlogin" />
18
+ </reference>
19
+ <reference name="ajaxlogin">
20
+ <action method="setTemplate" ifconfig="ajaxlogin/options/enable"><template>digitalpianism/ajaxlogin/index.phtml</template></action>
21
+ </reference>
22
+ </default>
23
+
24
+ <customer_logged_out>
25
+ <reference name="top.links">
26
+ <action method="removeLinkByUrl" ifconfig="ajaxlogin/options/enable">
27
+ <url helper="customer/getLoginUrl"/>
28
+ </action>
29
+ <action method="addLink" translate="label title" module="customer" ifconfig="ajaxlogin/options/enable">
30
+ <label>Log In</label>
31
+ <url helper="customer/getLoginUrl"/>
32
+ <title>Log In</title>
33
+ <prepare/>
34
+ <urlParams/>
35
+ <position>100</position>
36
+ <liParams/>
37
+ <aParams><class>ajaxlogin-login</class></aParams>
38
+ </action>
39
+ </reference>
40
+ </customer_logged_out>
41
+
42
+ <customer_logged_in>
43
+ <reference name="top.links">
44
+ <action method="removeLinkByUrl" ifconfig="ajaxlogin/options/enable">
45
+ <url helper="customer/getLogoutUrl"/>
46
+ </action>
47
+ <action method="addLink" translate="label title" module="customer" ifconfig="ajaxlogin/options/enable">
48
+ <label>Log Out</label>
49
+ <url helper="customer/getLogoutUrl"/>
50
+ <title>Log Out</title>
51
+ <prepare/>
52
+ <urlParams/>
53
+ <position>100</position>
54
+ <liParams/>
55
+ <aParams><class>ajaxlogin-logout</class></aParams>
56
+ </action>
57
+ </reference>
58
+ </customer_logged_in>
59
+
60
+ </layout>
app/design/frontend/base/default/template/digitalpianism/ajaxlogin/index.phtml ADDED
@@ -0,0 +1,195 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php if (!Mage::getSingleton('customer/session')->isLoggedIn()): ?>
2
+ <div id="ajaxlogin-login-window" style="display: none;">
3
+ <div class="page-title">
4
+ <span><?php echo $this->__('Login into your Account') ?></span>
5
+ </div>
6
+ <form action="<?php echo $this->getUrl('ajaxlogin/index/login', array('_secure'=>(!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS']==='on'))) ?>" method="post" id="ajaxlogin-login-form">
7
+ <div class="content">
8
+ <ul class="form-list">
9
+ <li>
10
+ <label for="email" class="required"><em>*</em><?php echo $this->__('Email Address') ?></label>
11
+ <div class="input-box">
12
+ <input type="text" name="login[username]" value="<?php echo $this->htmlEscape($this->getUsername()) ?>" id="email" class="input-text required-entry validate-email" title="<?php echo $this->__('Email Address') ?>" />
13
+ </div>
14
+ </li>
15
+ <li>
16
+ <label for="pass" class="required"><em>*</em><?php echo $this->__('Password') ?></label>
17
+ <div class="input-box">
18
+ <input type="password" name="login[password]" class="input-text required-entry validate-password" id="pass" title="<?php echo $this->__('Password') ?>" />
19
+ </div>
20
+ </li>
21
+ <?php echo $this->getChildHtml('form.additional.info'); ?>
22
+ </ul>
23
+ </div>
24
+ <div class="buttons-set">
25
+ <button type="button" class="button" title="<?php echo $this->__('Register') ?>" name="noaccount" id="noaccount" onclick="window.location = '<?php echo $this->getUrl('customer/account/create') ?>'"><span><span><?php echo $this->__('Register') ?></span></span></button>
26
+ <button type="submit" class="button" title="<?php echo $this->__('Login') ?>" name="send" id="send2"><span><span><?php echo $this->__('Login') ?></span></span></button>
27
+ <div class="progress-indicator">
28
+ <span class="please-wait" id="login-please-wait" style="display:none;">
29
+ <img src="<?php echo $this->getSkinUrl('images/opc-ajax-loader.gif') ?>" class="v-middle" alt=""/>
30
+ </span>
31
+ </div>
32
+ <a href="<?php echo $this->getForgotPasswordUrl() ?>" class="f-left ajaxlogin-forgot"><?php echo $this->__('Forgot Your Password?') ?></a>
33
+ </div>
34
+ </form>
35
+ <script type="text/javascript">
36
+ //<![CDATA[
37
+ var loginForm = new VarienForm('ajaxlogin-login-form', true);
38
+ //]]>
39
+ </script>
40
+ </div>
41
+ <?php endif; ?>
42
+
43
+ <?php if (!Mage::getSingleton('customer/session')->isLoggedIn()): ?>
44
+ <div id="ajaxlogin-forgot-window" style="display: none;">
45
+ <div class="page-title">
46
+ <span><?php echo $this->__('Forgot Your Password?') ?></span>
47
+ </div>
48
+ <form action="<?php echo $this->getUrl('ajaxlogin/index/forgotpassword', array('_secure'=>(!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS']==='on'))) ?>" method="post" id="ajaxlogin-forgot-password-form">
49
+ <div class="content">
50
+ <?php
51
+ $customerHelper = Mage::helper('customer');
52
+ if (method_exists($customerHelper, 'generateResetPasswordLinkToken')) : ?>
53
+ <p><?php echo $this->__('Please enter your email address below. You will receive a link to reset your password.') ?></p>
54
+ <?php else: ?>
55
+ <p><?php echo $this->__('Please enter your email below and we will send you a new password.') ?></p>
56
+ <?php endif; ?>
57
+ <ul class="form-list">
58
+ <li>
59
+ <label for="email_address" class="required"><em>*</em><?php echo $this->__('Email Address') ?></label>
60
+ <div class="input-box">
61
+ <input type="text" name="email" id="email_address" class="input-text required-entry validate-email" value="<?php echo $this->htmlEscape($this->getEmailValue()) ?>" />
62
+ </div>
63
+ </li>
64
+ <?php echo $this->getChildHtml('form.additional.info'); ?>
65
+ </ul>
66
+ </div>
67
+ <div class="buttons-set">
68
+ <button type="submit" title="<?php echo $this->__('Submit') ?>" id="btn-forgot" class="button"><span><span><?php echo $this->__('Submit') ?></span></span></button>
69
+ <div class="progress-indicator">
70
+ <span class="please-wait" id="forgot-please-wait" style="display:none;">
71
+ <img src="<?php echo $this->getSkinUrl('images/opc-ajax-loader.gif') ?>" class="v-middle" alt=""/>
72
+ </span>
73
+ </div>
74
+ <p class="back-link"><a href="<?php echo $this->helper('customer')->getLoginUrl() ?>" class="ajaxlogin-login"><?php echo $this->__('Back to Login') ?></a></p>
75
+ </div>
76
+ </form>
77
+ <script type="text/javascript">
78
+ //<![CDATA[
79
+ var forgotForm = new VarienForm('ajaxlogin-forgot-password-form', true);
80
+ //]]>
81
+ </script>
82
+ </div>
83
+ <?php endif; ?>
84
+ <?php if (Mage::getSingleton('customer/session')->isLoggedIn()): ?>
85
+ <div id="ajaxlogin-logout-window" style="display: none;">
86
+ <div class="page-title">
87
+ <span><?php echo $this->__('Logout from your Account') ?></span>
88
+ </div>
89
+ <form action="<?php echo $this->getUrl('ajaxlogin/index/logout', array('_secure'=>(!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS']==='on'))) ?>" method="post" id="ajaxlogin-logout-form">
90
+ <div class="content">
91
+ <p><?php echo $this->__('Are you sure you want to log out ?') ?></p>
92
+ </div>
93
+ <div class="buttons-set">
94
+ <button type="submit" class="button" title="<?php echo $this->__('Login') ?>" name="send" id="send2"><span><span><?php echo $this->__('Logout') ?></span></span></button>
95
+ <div class="progress-indicator">
96
+ <span class="please-wait" id="login-please-wait" style="display:none;">
97
+ <img src="<?php echo $this->getSkinUrl('images/opc-ajax-loader.gif') ?>" class="v-middle" alt=""/>
98
+ </span>
99
+ </div>
100
+ </div>
101
+ </form>
102
+ <script type="text/javascript">
103
+ //<![CDATA[
104
+ var loginForm = new VarienForm('ajaxlogin-logout-form', true);
105
+ //]]>
106
+ </script>
107
+ </div>
108
+ <?php endif; ?>
109
+
110
+ <?php if (Mage::getConfig()->getModuleConfig('Mage_Persistent')) : ?>
111
+ <?php
112
+ $isActive = Mage::getConfig()->getNode('modules/Mage_Persistent/active');
113
+ if (!$isActive || !in_array((string)$isActive, array('true', '1'))) {
114
+ return false;
115
+ }
116
+ ?>
117
+
118
+ <?php if (Mage::helper('persistent/session')->isPersistent() && !Mage::getSingleton('customer/session')->isLoggedIn()): ?>
119
+ <?php $customer = Mage::helper('persistent/session')->getCustomer(); ?>
120
+ <div id="persistent-cart-window" style="display:none;">
121
+ <div class="page-title">
122
+ <span><?php echo Mage::helper('persistent')->__('Welcome, %s!', Mage::helper('core')->escapeHtml($customer->getName(), null)) ?></span>
123
+ </div>
124
+ <div class="content">
125
+ <p><?php
126
+ echo Mage::helper('ajaxlogin')->__(
127
+ 'You are browsing our store as %s %s',
128
+ $customer->getName(),
129
+ $this->getLayout()->createBlock('persistent/header_additional')->toHtml()
130
+ );
131
+ ?></p>
132
+ <p><?php
133
+ $login = $this->__('Login');
134
+ $register = $this->__('Register');
135
+ echo Mage::helper('ajaxlogin')->__(
136
+ 'Please %s or %s a new account to place order.',
137
+ "<a href='" . $this->getUrl('customer/account/login') . "' class='ajaxlogin-login'>" . $login . "</a>",
138
+ "<a href='" . $this->getUrl('persistent/index/saveMethod') . "' class='ajaxlogin-register'>" . $register . "</a>"
139
+ );
140
+ ?></p>
141
+ </div>
142
+ </div>
143
+
144
+ <script type="text/javascript">
145
+ //<![CDATA[
146
+ document.observe("dom:loaded", function() {
147
+ persistentWindow = new AjaxLogin({
148
+ triggers: {},
149
+ size: {
150
+ maxWidth: 400
151
+ }
152
+ });
153
+ persistentWindow.update($('persistent-cart-window'))
154
+ .setModal(1)
155
+ .show();
156
+ });
157
+ //]]>
158
+ </script>
159
+
160
+ <?php endif; ?>
161
+ <?php endif; ?>
162
+
163
+ <script type="text/javascript">
164
+ document.observe("dom:loaded", function() {
165
+ var triggers = {
166
+ login: {
167
+ el : $$('.ajaxlogin-login'),
168
+ event : 'click',
169
+ window: $('ajaxlogin-login-window'),
170
+ size: {
171
+ maxWidth: 300
172
+ }
173
+ },
174
+ forgot: {
175
+ el : $$('.ajaxlogin-forgot'),
176
+ event : 'click',
177
+ window: $('ajaxlogin-forgot-window'),
178
+ size: {
179
+ maxWidth: 300
180
+ }
181
+ },
182
+ logout: {
183
+ el : $$('.ajaxlogin-logout'),
184
+ event : 'click',
185
+ window: $('ajaxlogin-logout-window'),
186
+ size: {
187
+ maxWidth: 300
188
+ }
189
+ }
190
+ };
191
+ ajaxLoginWindow = new AjaxLogin({
192
+ triggers: triggers
193
+ });
194
+ });
195
+ </script>
app/etc/modules/DigitalPianism_AjaxLogin.xml ADDED
@@ -0,0 +1,9 @@
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <config>
3
+ <modules>
4
+ <DigitalPianism_AjaxLogin>
5
+ <active>true</active>
6
+ <codePool>community</codePool>
7
+ </DigitalPianism_AjaxLogin>
8
+ </modules>
9
+ </config>
package.xml ADDED
@@ -0,0 +1,30 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <package>
3
+ <name>DigitalPianism_AjaxLogin</name>
4
+ <version>0.1.1</version>
5
+ <stability>stable</stability>
6
+ <license uri="http://opensource.org/licenses/osl-3.0.php">OSL v3.0</license>
7
+ <channel>community</channel>
8
+ <extends/>
9
+ <summary>Adds AJAX popups to the login/logout top links and forgot password functionalities.</summary>
10
+ <description>&lt;h2&gt;Overview&lt;/h2&gt;&#xD;
11
+ &#xD;
12
+ &lt;p&gt;This extension adds AJAX to the top links on Magento frontend so customers are able to connect to their account without loading an extra page.&lt;/p&gt;&#xD;
13
+ &#xD;
14
+ &lt;p&gt;They can also use the forgot password form and logout from this AJAX popup.&lt;/p&gt;&#xD;
15
+ &#xD;
16
+ &lt;h2&gt;Configuration&lt;/h2&gt;&#xD;
17
+ &#xD;
18
+ &lt;p&gt;Access the module configuration under System &gt; Configuration &gt; Digital Pianism &gt; Ajax Login.&lt;/p&gt;&#xD;
19
+ &#xD;
20
+ &lt;p&gt;The module is enabled by default but you can disable it here if you need to.&lt;/p&gt;&#xD;
21
+ &#xD;
22
+ </description>
23
+ <notes>- Original release.</notes>
24
+ <authors><author><name>Digital Pianism</name><user>digitalpianism</user><email>contact@digital-pianism.com</email></author></authors>
25
+ <date>2015-05-16</date>
26
+ <time>08:47:50</time>
27
+ <contents><target name="magecommunity"><dir name="DigitalPianism"><dir name="AjaxLogin"><dir name="Helper"><file name="Data.php" hash="1a04218d84eb0ad89d072f421cc2f993"/></dir><dir name="controllers"><file name="IndexController.php" hash="eb95f030fb4f847e68fef3d0160ea750"/></dir><dir name="etc"><file name="adminhtml.xml" hash="2569f90cd6868d15e41f4788c61e7638"/><file name="config.xml" hash="46c17d5c6280f828412003be788ff099"/><file name="system.xml" hash="71c81e7c67e405512bb5ed0729bfa2de"/></dir></dir></dir></target><target name="mageetc"><dir name="modules"><file name="DigitalPianism_AjaxLogin.xml" hash="ff28627543caa7543c763f21ef4a5683"/></dir></target><target name="magedesign"><dir name="frontend"><dir name="base"><dir name="default"><dir name="template"><dir name="digitalpianism"><dir name="ajaxlogin"><file name="index.phtml" hash="347f5dc05ff996712838850ceeb686d8"/></dir></dir></dir><dir name="layout"><dir name="digitalpianism"><file name="ajaxlogin.xml" hash="09378fb468dbe71689acd53fa75c1eac"/></dir></dir></dir></dir></dir></target><target name="mageskin"><dir name="frontend"><dir name="base"><dir name="default"><dir name="css"><dir name="digitalpianism"><dir name="ajaxlogin"><file name="styles.css" hash="8a7f560e5041e52904858828acf378e9"/></dir></dir></dir><dir name="images"><dir name="digitalpianism"><dir name="ajaxlogin"><file name="ajax-loader.gif" hash="b256d80f54c1415d7a6a6fdec39769f4"/><file name="box-content-bg.gif" hash="f5344140a3a9ad4267687b8ec40c5751"/><file name="box-header-bg.gif" hash="e1e109e8f6bfc2f2ccef04769553c60c"/><file name="cancel_round.png" hash="afcb08c1bdcdb7f9922ea289906fdfbf"/><file name="close.png" hash="0aa9c71e1e00deb929514c3b004e30c2"/><file name="shd-medium.png" hash="ed62cea276345a5003a4a6c6f47c1071"/><file name="spinner.gif" hash="73e57937304d89f251e7e540a24b095a"/></dir></dir></dir><dir name="js"><dir name="digitalpianism"><dir name="ajaxlogin"><file name="script.js" hash="c1f7f3346dda69e24be05e811df3bda8"/></dir></dir></dir></dir></dir></dir></target></contents>
28
+ <compatible/>
29
+ <dependencies><required><php><min>4.1.0</min><max>6.0.0</max></php></required></dependencies>
30
+ </package>
skin/frontend/base/default/css/digitalpianism/ajaxlogin/styles.css ADDED
@@ -0,0 +1,44 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /* window */
2
+ .ajaxlogin-window { border: 1px solid rgba(0, 0, 0, 0.3); background:#fff; z-index:999; padding: 10px; position:absolute; text-align:left;
3
+ -webkit-border-radius: 0;
4
+ -moz-border-radius: 0;
5
+ border-radius: 0;
6
+ outline: none;
7
+ -webkit-box-shadow: 0 3px 7px rgba(0, 0, 0, 0.3);
8
+ -moz-box-shadow: 0 3px 7px rgba(0, 0, 0, 0.3);
9
+ box-shadow: 0 3px 7px rgba(0, 0, 0, 0.3);
10
+ -webkit-background-clip: padding-box;
11
+ -moz-background-clip: padding-box;
12
+ background-clip: padding-box;
13
+ }
14
+
15
+ .ajaxlogin-window .page-title,
16
+ .ajaxlogin-window .page-title span { color:#0A263C; font-size:18px; font-weight: normal; text-align: center}
17
+ .ajaxlogin-window .content { padding:7px; overflow:auto; overflow-x:hidden; }
18
+ .ajaxlogin-window label { width:auto; text-align:left; margin-bottom: 0; }
19
+ .ajaxlogin-window label em { display:none }
20
+ .ajaxlogin-window ul li { line-height: normal; }
21
+ .ajaxlogin-window ul,
22
+ .ajaxlogin-window .form-list { list-style: none; margin: 0; }
23
+ .ajaxlogin-window .form-list li { margin-bottom: 10px }
24
+ .ajaxlogin-window .form-list .input-box { clear:both; }
25
+ .ajaxlogin-window .form-list input.input-text,
26
+ .ajaxlogin-window .form-list textarea { width:100% }
27
+ .ajaxlogin-window .input-box input { margin: 0
28
+ }
29
+ .ajaxlogin-window .input-box .validation-advice { line-height: normal; }
30
+ .ajaxlogin-window .close { position:absolute; top:4px; right:4px; width:16px; height:16px; background:url(../../../images/digitalpianism/ajaxlogin/cancel_round.png) no-repeat 50% 50%; }
31
+ .ajaxlogin-window .close:hover {}
32
+ .ajaxlogin-window .progress-indicator { display: block; text-align: center; float:right}
33
+ .ajaxlogin-window .please-wait { position:static; padding:0; background:none; border:none; margin:0; left:auto; top:auto; }
34
+ .ajaxlogin-window .buttons-set { margin:0; text-align:center; border-top:0 solid #e4e4e4; padding:7px; }
35
+ .ajaxlogin-window .buttons-set a { display: block; }
36
+ .ajaxlogin-window .form-list .input-box{ width:auto }
37
+ .ajaxlogin-window .buttons-set .back-link { display: block; margin: 0; padding: 0; text-align: center; }
38
+ .ajaxlogin-window .buttons-set .back-link a { }
39
+ .ajaxlogin-window .buttons-set .please-wait
40
+ .ajaxlogin-window .actionbar { padding:10px 10px 0; text-align:right; font-weight:bold; }
41
+
42
+ #ajaxlogin-mask { background: black; opacity:0.4; -ms-filter:"progid:DXImageTransform.Microsoft.Alpha(Opacity=40)"; filter:alpha(opacity=40);
43
+ position:absolute; top:0; left:0; width:100%; height:100%; z-index:990; }
44
+ * html #ajaxlogin-mask { position:absolute; }
skin/frontend/base/default/images/digitalpianism/ajaxlogin/ajax-loader.gif ADDED
Binary file
skin/frontend/base/default/images/digitalpianism/ajaxlogin/box-content-bg.gif ADDED
Binary file
skin/frontend/base/default/images/digitalpianism/ajaxlogin/box-header-bg.gif ADDED
Binary file
skin/frontend/base/default/images/digitalpianism/ajaxlogin/cancel_round.png ADDED
Binary file
skin/frontend/base/default/images/digitalpianism/ajaxlogin/close.png ADDED
Binary file
skin/frontend/base/default/images/digitalpianism/ajaxlogin/shd-medium.png ADDED
Binary file
skin/frontend/base/default/images/digitalpianism/ajaxlogin/spinner.gif ADDED
Binary file
skin/frontend/base/default/js/digitalpianism/ajaxlogin/script.js ADDED
@@ -0,0 +1,566 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /**
2
+ * Created by Raph on 10/11/2014.
3
+ */
4
+ AjaxLogin = Class.create();
5
+ AjaxLogin.prototype = {
6
+ initialize: function(config) {
7
+ this.config = Object.extend({
8
+ triggers: null,
9
+ markup:
10
+ '<div class="d-shadow-wrap">'
11
+ + '<div class="content"></div>'
12
+ + '<div class="d-sh-cn d-sh-tl"></div><div class="d-sh-cn d-sh-tr"></div>'
13
+ + '</div>'
14
+ + '<div class="d-sh-cn d-sh-bl"></div><div class="d-sh-cn d-sh-br"></div>'
15
+ + '<a href="javascript:void(0)" class="close"></a>'
16
+ }, config || {});
17
+ this.config.size = Object.extend({
18
+ width : 'auto',
19
+ height : 'auto',
20
+ maxWidth : 550,
21
+ maxHeight: 600
22
+ }, this.config.size || {});
23
+
24
+ this._prepareMarkup();
25
+ this._attachEventListeners();
26
+ this._addEventListeners();
27
+ },
28
+
29
+ show: function() {
30
+ if (!this.centered) {
31
+ this.center();
32
+ }
33
+ $$('select').invoke('addClassName', 'ajaxlogin-hidden');
34
+
35
+ if (!$('ajaxlogin-mask')) {
36
+ var mask = new Element('div');
37
+ mask.writeAttribute('id', 'ajaxlogin-mask');
38
+ var body = document.body,
39
+ element = document.documentElement,
40
+ height = Math.max(
41
+ Math.max(body.scrollHeight, element.scrollHeight),
42
+ Math.max(body.offsetHeight, element.offsetHeight),
43
+ Math.max(body.clientHeight, element.clientHeight)
44
+ );
45
+ mask.setStyle({
46
+ height: height + 'px'
47
+ });
48
+ $(document.body).insert(mask);
49
+ }
50
+
51
+ if (!window.ajaxloginMaskCounter) {
52
+ window.ajaxloginMaskCounter = 0;
53
+ }
54
+ if (!this.maskCounted) {
55
+ this.maskCounted = 1;
56
+ window.ajaxloginMaskCounter++;
57
+ }
58
+
59
+ // set highest z-index
60
+ var zIndex = 999;
61
+ $$('.ajaxlogin-window').each(function(el) {
62
+ maxIndex = parseInt(el.getStyle('zIndex'));
63
+ if (zIndex < maxIndex) {
64
+ zIndex = maxIndex;
65
+ }
66
+ });
67
+ this.window.setStyle({
68
+ 'zIndex': zIndex + 1
69
+ });
70
+
71
+ this._onKeyPressBind = this._onKeyPress.bind(this);
72
+ document.observe('keyup', this._onKeyPressBind);
73
+ this.window.show();
74
+ },
75
+
76
+ hide: function() {
77
+ if (this.modal || !this.window.visible()) {
78
+ return;
79
+ }
80
+
81
+ if (this._onKeyPressBind) {
82
+ document.stopObserving('keyup', this._onKeyPressBind);
83
+ }
84
+ if (this.config.destroy) {
85
+ this.window.remove();
86
+ } else {
87
+ this.window.hide();
88
+ }
89
+ this.maskCounted = 0;
90
+ if (!--window.ajaxloginMaskCounter) {
91
+ $('ajaxlogin-mask') && $('ajaxlogin-mask').remove();
92
+ $$('select').invoke('removeClassName', 'ajaxlogin-hidden');
93
+ }
94
+ },
95
+
96
+ setModal: function(flag) {
97
+ this.modal = flag;
98
+
99
+ if (flag) {
100
+ this.window.select('.close').invoke('hide');
101
+ } else {
102
+ this.window.select('.close').invoke('show');
103
+ }
104
+ return this;
105
+ },
106
+
107
+ update: function(content, size) {
108
+ var oldContent = this.content.down();
109
+ oldContent && $(document.body).insert(oldContent.hide());
110
+
111
+ this.content.update(content);
112
+ content.show();
113
+ this.addActionBar();
114
+ this.updateSize(size);
115
+ this.center();
116
+ return this;
117
+ },
118
+
119
+ addActionBar: function() {
120
+ this.removeActionBar();
121
+
122
+ var agreementId = this.content.down().id.replace('-window', ''),
123
+ trigger = this.config.triggers[agreementId];
124
+
125
+ if (!trigger || !trigger.actionbar) {
126
+ return;
127
+ }
128
+
129
+ this.content.insert({
130
+ after: '<div class="actionbar">' + trigger.actionbar.html + '</div>'
131
+ });
132
+ $(trigger.actionbar.el).observe(
133
+ trigger.actionbar.event,
134
+ trigger.actionbar.callback.bindAsEventListener(this, agreementId.replace('ajaxlogin-', ''))
135
+ );
136
+ },
137
+
138
+ removeActionBar: function() {
139
+ var agreementId = this.content.down().id.replace('-window', ''),
140
+ trigger = this.config.triggers[agreementId];
141
+
142
+ if (trigger && trigger.actionbar) {
143
+ var actionbar = $(trigger.actionbar.el);
144
+ if (actionbar) {
145
+ actionbar.stopObserving(trigger.actionbar.event);
146
+ }
147
+ }
148
+
149
+ this.window.select('.actionbar').invoke('remove');
150
+ },
151
+
152
+ getActionBar: function() {
153
+ return this.window.down('.actionbar');
154
+ },
155
+
156
+ center: function() {
157
+ var viewportSize = document.viewport.getDimensions(),
158
+ viewportOffset = document.viewport.getScrollOffsets(),
159
+ shadowWrap = this.window.down('.d-shadow-wrap'),
160
+ windowSize = this.window.getDimensions(),
161
+ left, top;
162
+
163
+ if ('undefined' === typeof viewportSize.width) { // mobile fix. not sure is this check is good enough.
164
+ top = viewportOffset.top + 20;
165
+ left = viewportOffset.left;
166
+ } else {
167
+ top = viewportSize.height / 2
168
+ - windowSize.height / 2
169
+ + viewportOffset.top
170
+ + parseInt(shadowWrap.getStyle('margin-top'))
171
+ + parseInt(shadowWrap.getStyle('padding-top')),
172
+ left = viewportSize.width / 2
173
+ - windowSize.width / 2
174
+ + viewportOffset.left
175
+ + parseInt(shadowWrap.getStyle('margin-left'))
176
+ + parseInt(shadowWrap.getStyle('padding-left'));
177
+
178
+ if (left < viewportOffset.left || windowSize.width > viewportSize.width) {
179
+ left = viewportOffset.left;
180
+ } else {
181
+ left -= 20; /* right shadow */
182
+ }
183
+ top = (top < viewportOffset.top ? (20 + viewportOffset.top) : top)
184
+ }
185
+
186
+ this.setPosition(left, top);
187
+ this.centered = true;
188
+
189
+ return this;
190
+ },
191
+
192
+ setPosition: function(x, y) {
193
+ this.window.setStyle({
194
+ left: x + 17 /* left border */ + 'px',
195
+ top : y + 'px'
196
+ });
197
+
198
+ return this;
199
+ },
200
+
201
+ activate: function(trigger) {
202
+ var trigger = this.config.triggers[trigger];
203
+ this.update(trigger.window.show(), trigger.size).show();
204
+ },
205
+
206
+ updateSize: function(sizeConfig) {
207
+ sizeConfig = sizeConfig || this.config.size;
208
+ // reset previous size
209
+ this.window.setStyle({
210
+ width : 'auto',
211
+ height: 'auto',
212
+ left : 0, /* thin content box fix while page is scrolled to the right */
213
+ top : 0
214
+ });
215
+ this.content.setStyle({
216
+ width : isNaN(sizeConfig.width) ? sizeConfig.width : sizeConfig.width + 'px',
217
+ height: isNaN(sizeConfig.height) ? sizeConfig.height : sizeConfig.height + 'px'
218
+ });
219
+
220
+ this.window.setStyle({
221
+ visibility: 'hidden'
222
+ }).show();
223
+
224
+ var width = this.content.getWidth() + 100, /* right shadow and borders */
225
+ viewportSize = document.viewport.getDimensions();
226
+
227
+ sizeConfig = Object.extend(this.config.size, sizeConfig || {});
228
+ if ('auto' === sizeConfig.width
229
+ && (width > sizeConfig.maxWidth || width > viewportSize.width)) {
230
+
231
+ if (width > viewportSize.width && viewportSize.width < (sizeConfig.maxWidth + 100)) {
232
+ width = viewportSize.width - 100; /* right shadow and borders */
233
+ } else {
234
+ width = sizeConfig.maxWidth;
235
+ }
236
+ this.content.setStyle({
237
+ width: width + 'px'
238
+ });
239
+ }
240
+
241
+ var actionbar = this.getActionBar(),
242
+ actionbarHeight = actionbar ? actionbar.getHeight() : 0,
243
+ height = this.content.getHeight() + actionbarHeight + 20 /* top button */;
244
+ if ('auto' === sizeConfig.height
245
+ && (height > sizeConfig.maxHeight || height > viewportSize.height)) {
246
+
247
+ if (height > viewportSize.height && viewportSize.height < (sizeConfig.maxHeight + actionbarHeight + 20)) {
248
+ height = viewportSize.height - 60; /* bottom shadow */
249
+ } else {
250
+ height = sizeConfig.maxHeight;
251
+ }
252
+ height -= actionbarHeight;
253
+ this.content.setStyle({
254
+ height: height + 'px'
255
+ });
256
+ }
257
+
258
+ // update window size. Fix for all IE browsers
259
+ var paddingHorizontal = parseInt(this.content.getStyle('padding-left')) + parseInt(this.content.getStyle('padding-right'));
260
+ //var paddingVertical = parseInt(this.content.getStyle('padding-top')) + parseInt(this.content.getStyle('padding-bottom'));
261
+ this.window.hide()
262
+ .setStyle({
263
+ width : width + paddingHorizontal + 'px',
264
+ // height : height + paddingVertical + 'px',
265
+ visibility: 'visible'
266
+ });
267
+
268
+ return this;
269
+ },
270
+
271
+ _prepareMarkup: function() {
272
+ this.window = new Element('div');
273
+ this.window.addClassName('ajaxlogin-window');
274
+ this.window.update(this.config.markup).hide();
275
+ this.content = this.window.select('.content')[0];
276
+ this.close = this.window.select('.close')[0];
277
+ $(document.body).insert(this.window);
278
+ },
279
+
280
+ _attachEventListeners: function() {
281
+ // close window
282
+ this.close.observe('click', this.hide.bind(this));
283
+ // show window
284
+ if (this.config.triggers) {
285
+ for (var i in this.config.triggers) {
286
+ var trigger = this.config.triggers[i];
287
+ if (typeof trigger === 'function') {
288
+ continue;
289
+ }
290
+ trigger.size = trigger.size || {};
291
+ for (var j in this.config.size) {
292
+ if (trigger.size[j]) {
293
+ continue;
294
+ }
295
+ trigger.size[j] = this.config.size[j];
296
+ }
297
+
298
+ trigger.el.each(function(el) {
299
+ var t = trigger;
300
+ el.observe(t.event, function(e) {
301
+ if (typeof event != 'undefined') { // ie9 fix
302
+ event.preventDefault ? event.preventDefault() : event.returnValue = false;
303
+ }
304
+ Event.stop(e);
305
+ if (!t.window) {
306
+ return;
307
+ }
308
+ this.update(t.window, t.size).show();
309
+ }.bind(this));
310
+ }.bind(this));
311
+ }
312
+ }
313
+ },
314
+
315
+ _addEventListeners: function() {
316
+ var self = this;
317
+
318
+ $('ajaxlogin-login-form') && $('ajaxlogin-login-form').observe('submit', function(e) {
319
+ if (typeof event != 'undefined') { // ie9 fix
320
+ event.preventDefault ? event.preventDefault() : event.returnValue = false;
321
+ }
322
+ Event.stop(e);
323
+
324
+ if (!loginForm.validator.validate()) {
325
+ return false;
326
+ }
327
+
328
+ $('login-please-wait').show();
329
+ $('send2').setAttribute('disabled', 'disabled');
330
+ $$('#ajaxlogin-login-form .buttons-set')[0]
331
+ .addClassName('disabled')
332
+ .setOpacity(0.5);
333
+
334
+ new Ajax.Request($('ajaxlogin-login-form').action, {
335
+ parameters: $('ajaxlogin-login-form').serialize(),
336
+ onSuccess: function(transport) {
337
+ var section = $('ajaxlogin-login-form');
338
+ if (!section) {
339
+ return;
340
+ }
341
+ var ul = section.select('.messages')[0];
342
+ if (ul) {
343
+ ul.remove();
344
+ }
345
+
346
+ var response = transport.responseText.evalJSON();
347
+ if (response.error) {
348
+ var section = $('ajaxlogin-login-form');
349
+ if (!section) {
350
+ return;
351
+ }
352
+ var ul = section.select('.messages')[0];
353
+ if (!ul) {
354
+ section.insert({
355
+ top: '<ul class="messages"></ul>'
356
+ });
357
+ ul = section.select('.messages')[0]
358
+ }
359
+ var li = $(ul).select('.error-msg')[0];
360
+ if (!li) {
361
+ $(ul).insert({
362
+ top: '<li class="error-msg"><ul></ul></li>'
363
+ });
364
+ li = $(ul).select('.error-msg')[0];
365
+ }
366
+ $(li).select('ul')[0].insert(
367
+ '<li>' + response.error + '</li>'
368
+ );
369
+ self.updateCaptcha('user_login');
370
+ }
371
+ if (response.redirect) {
372
+ document.location = response.redirect;
373
+ return;
374
+ }
375
+ $('login-please-wait').hide();
376
+ $('send2').removeAttribute('disabled');
377
+ $$('#ajaxlogin-login-form .buttons-set')[0]
378
+ .removeClassName('disabled')
379
+ .setOpacity(1);
380
+ }
381
+ });
382
+ });
383
+
384
+ $('ajaxlogin-forgot-password-form') && $('ajaxlogin-forgot-password-form').observe('submit', function(e) {
385
+ if (typeof event != 'undefined') { // ie9 fix
386
+ event.preventDefault ? event.preventDefault() : event.returnValue = false;
387
+ }
388
+ Event.stop(e);
389
+
390
+ if (!forgotForm.validator.validate()) {
391
+ return false;
392
+ }
393
+
394
+ $('forgot-please-wait').show();
395
+ $('btn-forgot').setAttribute('disabled', 'disabled');
396
+ $$('#ajaxlogin-forgot-password-form .buttons-set')[0]
397
+ .addClassName('disabled')
398
+ .setOpacity(0.5);
399
+
400
+ new Ajax.Request($('ajaxlogin-forgot-password-form').action, {
401
+ parameters: $('ajaxlogin-forgot-password-form').serialize(),
402
+ onSuccess: function(transport) {
403
+ var section = $('ajaxlogin-forgot-password-form');
404
+ if (!section) {
405
+ return;
406
+ }
407
+ var ul = section.select('.messages')[0];
408
+ if (ul) {
409
+ ul.remove();
410
+ }
411
+
412
+ $('forgot-please-wait').hide();
413
+ $('btn-forgot').removeAttribute('disabled');
414
+ $$('#ajaxlogin-forgot-password-form .buttons-set')[0]
415
+ .removeClassName('disabled')
416
+ .setOpacity(1);
417
+
418
+ var response = transport.responseText.evalJSON();
419
+
420
+ if (response.error) {
421
+ var section = $('ajaxlogin-forgot-password-form');
422
+ if (!section) {
423
+ return;
424
+ }
425
+ var ul = section.select('.messages')[0];
426
+ if (!ul) {
427
+ section.insert({
428
+ top: '<ul class="messages"></ul>'
429
+ });
430
+ ul = section.select('.messages')[0]
431
+ }
432
+ var li = $(ul).select('.error-msg')[0];
433
+ if (!li) {
434
+ $(ul).insert({
435
+ top: '<li class="error-msg"><ul></ul></li>'
436
+ });
437
+ li = $(ul).select('.error-msg')[0];
438
+ }
439
+ $(li).select('ul')[0].insert(
440
+ '<li>' + response.error + '</li>'
441
+ );
442
+ self.updateCaptcha('user_forgotpassword');
443
+ } else if (response.message) {
444
+ var section = $('ajaxlogin-login-form');
445
+ if (!section) {
446
+ return;
447
+ }
448
+ var ul = section.select('.messages')[0];
449
+ if (ul) {
450
+ ul.remove();
451
+ }
452
+ var section = $('ajaxlogin-login-form');
453
+ if (!section) {
454
+ return;
455
+ }
456
+ var ul = section.select('.messages')[0];
457
+ if (!ul) {
458
+ section.insert({
459
+ top: '<ul class="messages"></ul>'
460
+ });
461
+ ul = section.select('.messages')[0]
462
+ }
463
+ var li = $(ul).select('.success-msg')[0];
464
+ if (!li) {
465
+ $(ul).insert({
466
+ top: '<li class="success-msg"><ul></ul></li>'
467
+ });
468
+ li = $(ul).select('.success-msg')[0];
469
+ }
470
+ $(li).select('ul')[0].insert(
471
+ '<li>' + response.message + '</li>'
472
+ );
473
+ ajaxloginWindow.activate('login');
474
+ }
475
+ }
476
+ });
477
+ });
478
+
479
+ $('ajaxlogin-logout-form') && $('ajaxlogin-logout-form').observe('submit', function(e) {
480
+ if (typeof event != 'undefined') { // ie9 fix
481
+ event.preventDefault ? event.preventDefault() : event.returnValue = false;
482
+ }
483
+ Event.stop(e);
484
+
485
+ if (!loginForm.validator.validate()) {
486
+ return false;
487
+ }
488
+
489
+ $('login-please-wait').show();
490
+ $('send2').setAttribute('disabled', 'disabled');
491
+ $$('#ajaxlogin-logout-form .buttons-set')[0]
492
+ .addClassName('disabled')
493
+ .setOpacity(0.5);
494
+
495
+ new Ajax.Request($('ajaxlogin-logout-form').action, {
496
+ parameters: $('ajaxlogin-logout-form').serialize(),
497
+ onSuccess: function(transport) {
498
+ var section = $('ajaxlogin-logout-form');
499
+ if (!section) {
500
+ return;
501
+ }
502
+ var ul = section.select('.messages')[0];
503
+ if (ul) {
504
+ ul.remove();
505
+ }
506
+
507
+ var response = transport.responseText.evalJSON();
508
+ if (response.error) {
509
+ var section = $('ajaxlogin-logout-form');
510
+ if (!section) {
511
+ return;
512
+ }
513
+ var ul = section.select('.messages')[0];
514
+ if (!ul) {
515
+ section.insert({
516
+ top: '<ul class="messages"></ul>'
517
+ });
518
+ ul = section.select('.messages')[0]
519
+ }
520
+ var li = $(ul).select('.error-msg')[0];
521
+ if (!li) {
522
+ $(ul).insert({
523
+ top: '<li class="error-msg"><ul></ul></li>'
524
+ });
525
+ li = $(ul).select('.error-msg')[0];
526
+ }
527
+ $(li).select('ul')[0].insert(
528
+ '<li>' + response.error + '</li>'
529
+ );
530
+ }
531
+ if (response.redirect) {
532
+ document.location = response.redirect;
533
+ return;
534
+ }
535
+ $('login-please-wait').hide();
536
+ $('send2').removeAttribute('disabled');
537
+ $$('#ajaxlogin-logout-form .buttons-set')[0]
538
+ .removeClassName('disabled')
539
+ .setOpacity(1);
540
+ }
541
+ });
542
+ });
543
+ },
544
+
545
+ ajaxFailure: function(){
546
+ location.href = this.urls.failure;
547
+ },
548
+
549
+ _onKeyPress: function(e) {
550
+ if (e.keyCode == 27) {
551
+ this.hide();
552
+ }
553
+ },
554
+
555
+ updateCaptcha: function(id) {
556
+ var captchaEl = $(id);
557
+ if (captchaEl) {
558
+ captchaEl.captcha.refresh(captchaEl.previous('img.captcha-reload'));
559
+ // try to focus input element:
560
+ var inputEl = $('captcha_' + id);
561
+ if (inputEl) {
562
+ inputEl.focus();
563
+ }
564
+ }
565
+ }
566
+ };