Skip to content

Commit 40cbaf7

Browse files
author
oleg.s
committed
init
0 parents  commit 40cbaf7

File tree

4 files changed

+210
-0
lines changed

4 files changed

+210
-0
lines changed
Lines changed: 164 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,164 @@
1+
<?php
2+
require_once("Mage/Customer/controllers/AccountController.php");
3+
4+
/**
5+
* Customer account controller
6+
*/
7+
class CRW_Auth_AccountController extends Mage_Customer_AccountController
8+
{
9+
// Check user is in Unapproved grousp
10+
public function is_user_approved() {
11+
// Check Customer is loggedin or not
12+
if(Mage::getSingleton('customer/session')->isLoggedIn()){
13+
// Get group Id
14+
$groupId = Mage::getSingleton('customer/session')->getCustomerGroupId();
15+
//Get customer Group name
16+
$group = Mage::getModel('customer/group')->load($groupId);
17+
// Check approved
18+
if($group->getCode() == 'Unapproved')
19+
// User is unapproved
20+
return false;
21+
else
22+
// User is approved now
23+
return true;
24+
}
25+
else {
26+
// User is unapproved
27+
return false;
28+
}
29+
}
30+
31+
/**
32+
* Customer login form page
33+
*/
34+
public function indexAction()
35+
{
36+
if($this->is_user_approved()) {
37+
$this->getResponse()->setHeader('Login-Required', 'true');
38+
$this->loadLayout();
39+
$this->_initLayoutMessages('customer/session');
40+
$this->_initLayoutMessages('catalog/session');
41+
$this->renderLayout();
42+
}
43+
else {
44+
$session->addError($this->__('You must be an approved user'));
45+
$this->logoutAction();
46+
}
47+
}
48+
49+
/**
50+
* Login post action
51+
*/
52+
public function loginPostAction()
53+
{
54+
if (!$this->_validateFormKey()) {
55+
$this->_redirect('*/*/');
56+
return;
57+
}
58+
59+
if ($this->_getSession()->isLoggedIn()) {
60+
$this->_redirect('*/*/');
61+
return;
62+
}
63+
$session = $this->_getSession();
64+
65+
if ($this->getRequest()->isPost()) {
66+
$login = $this->getRequest()->getPost('login');
67+
if (!empty($login['username']) && !empty($login['password'])) {
68+
try {
69+
$session->login($login['username'], $login['password']);
70+
if ($session->getCustomer()->getIsJustConfirmed()) {
71+
$this->_welcomeCustomer($session->getCustomer(), true);
72+
}
73+
} catch (Mage_Core_Exception $e) {
74+
switch ($e->getCode()) {
75+
case Mage_Customer_Model_Customer::EXCEPTION_EMAIL_NOT_CONFIRMED:
76+
$value = $this->_getHelper('customer')->getEmailConfirmationUrl($login['username']);
77+
$message = $this->_getHelper('customer')->__('This account is not confirmed. <a href="%s">Click here</a> to resend confirmation email.', $value);
78+
break;
79+
case Mage_Customer_Model_Customer::EXCEPTION_INVALID_EMAIL_OR_PASSWORD:
80+
$message = $e->getMessage();
81+
break;
82+
default:
83+
$message = $e->getMessage();
84+
}
85+
$session->addError($message);
86+
$session->setUsername($login['username']);
87+
} catch (Exception $e) {
88+
// Mage::logException($e); // PA DSS violation: this exception log can disclose customer password
89+
}
90+
} else {
91+
$session->addError($this->__('Login and password are required.'));
92+
}
93+
}
94+
// Check if customer is an approved
95+
if($this->is_user_approved()) {
96+
$this->_loginPostRedirect();
97+
}
98+
else {
99+
$session->addError($this->__('You must be an approved user'));
100+
$this->logoutAction();
101+
}
102+
}
103+
104+
/**
105+
* Create customer account action
106+
*/
107+
public function createPostAction()
108+
{
109+
/** @var $session Mage_Customer_Model_Session */
110+
$session = $this->_getSession();
111+
if ($session->isLoggedIn()) {
112+
$this->_redirect('*/*/');
113+
return;
114+
}
115+
$session->setEscapeMessages(true); // prevent XSS injection in user input
116+
if (!$this->getRequest()->isPost()) {
117+
$errUrl = $this->_getUrl('*/*/create', array('_secure' => true));
118+
$this->_redirectError($errUrl);
119+
return;
120+
}
121+
122+
$customer = $this->_getCustomer();
123+
124+
try {
125+
$errors = $this->_getCustomerErrors($customer);
126+
// Check if customer is an approved
127+
if($this->is_user_approved()) {
128+
$this->_loginPostRedirect();
129+
}
130+
else {
131+
$session->addError($this->__('You must be an approved user'));
132+
133+
}
134+
135+
if (empty($errors)) {
136+
$customer->cleanPasswordsValidationData();
137+
$customer->save();
138+
$this->_dispatchRegisterSuccess($customer);
139+
$this->_successProcessRegistration($customer);
140+
$this->logoutAction();
141+
return;
142+
} else {
143+
$this->_addSessionError($errors);
144+
}
145+
} catch (Mage_Core_Exception $e) {
146+
$session->setCustomerFormData($this->getRequest()->getPost());
147+
if ($e->getCode() === Mage_Customer_Model_Customer::EXCEPTION_EMAIL_EXISTS) {
148+
$url = $this->_getUrl('customer/account/forgotpassword');
149+
$message = $this->__('There is already an account with this email address. If you are sure that it is your email address, <a href="%s">click here</a> to get your password and access your account.', $url);
150+
$session->setEscapeMessages(false);
151+
} else {
152+
$message = $e->getMessage();
153+
}
154+
$session->addError($message);
155+
} catch (Exception $e) {
156+
$session->setCustomerFormData($this->getRequest()->getPost())
157+
->addException($e, $this->__('Cannot save the customer.'));
158+
}
159+
$errUrl = $this->_getUrl('*/*/create', array('_secure' => true));
160+
$this->_redirectError($errUrl);
161+
}
162+
163+
}
164+
?>
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<?xml version="1.0"?>
2+
<config>
3+
<modules>
4+
<CRW_Auth>
5+
<version>0.1.0</version>
6+
</CRW_Auth>
7+
</modules>
8+
<frontend>
9+
<routers>
10+
<customer>
11+
<args>
12+
<modules>
13+
<CRW_Auth before="Mage_Customer">CRW_Auth</CRW_Auth>
14+
</modules>
15+
</args>
16+
</customer>
17+
</routers>
18+
</frontend>
19+
</config>

app/etc/modules/CRW_Auth.xml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<?xml version="1.0"?>
2+
<config>
3+
<modules>
4+
<CRW_Auth>
5+
<active>true</active>
6+
<codePool>local</codePool>
7+
</CRW_Auth>
8+
</modules>
9+
</config>

package.xml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<?xml version="1.0"?>
2+
<package>
3+
<name>CRW_Auth</name>
4+
<version>1.0.0</version>
5+
<stability>beta</stability>
6+
<license>OSL v3.0</license>
7+
<channel>community</channel>
8+
<extends/>
9+
<summary>Aproove user module</summary>
10+
<description>Module extends Core_Account_Controller</description>
11+
<notes>Special for CRW theme</notes>
12+
<authors><author><name>Computools</name><user>admin</user><email>dmitriy.asaulenko@computools.com</email></author></authors>
13+
<date>2016-05-23</date>
14+
<time>09:15:20</time>
15+
<contents><target name="mageetc"><dir name="modules"><file name="CRW_Auth.xml" hash="1a4ee46795c769e8c60403bff87d6d6c"/></dir></target><target name="magelocal"><dir name="CRW"><dir name="Auth"><dir name="controllers"><file name="AccountController.php" hash="9896cefe2054fa42ec4f376b5960a405"/></dir><dir name="etc"><file name="config.xml" hash="985fce4d0799d509e0e2c6b37c1efcbb"/></dir></dir></dir></target></contents>
16+
<compatible/>
17+
<dependencies><required><php><min>5.3.1</min><max>5.6.0</max></php></required></dependencies>
18+
</package>

0 commit comments

Comments
 (0)