So during login, I want to check if the user is in a specific customer group and prevent login if that check fails.
I have extended the AccountController, and added in a quick check:
$customer = Mage::getModel('customer/customer')->loadByEmail($login['username']);
if ($customer->getGroupId() != 2) {
$msg = Mage::getSingleton('core/session')->addError($this->__('You must have a wholesale account to access this area.'));
header('Location: '. Mage::getUrl('customer/account/login'));
exit;
}
However, running this returns session error message, “Customer website ID must be specified when using the website scope”.
Basically, I just need to grab the group id of the user who is attempting to login, and I figured I could grab this through the method supplied in the customer model, loadByEmail(). But yeah, it’s Friday, and apparently the MageLords want me to stay late.
I have tried a number of methods to get this working, including allowing the login, then checking the ID, then doing $session->logout() if the check fails, but this was preventing me from displaying a session error message since the logout() method is clearing all session messages (including ‘core/session’).
Any ideas?
You should set
website_idbefore working withloadByEmailmethod. I know, it seems weird, but this is dictated by the fact, thatcustomercould be a website-scoped entity. So theloadByEmailmethod will throw exception ifcustomermodel is not assigned to any website.