Magento for mobile and username login

Source: Internet
Author: User

By default, Magento only supports mailbox logons, so we need to modify the code. The idea is that you can find your mailbox by entering your phone number and user name.

First you need to rewrite the controller, add the configuration file
<rewrite>
< module name _ controller _account>
<from><! [cdata[#^/customer/account/#]]></from>
<to>/icustomer/account/</to>
</Module Name _ Controller _account>
Now, you need to create a new accountcontroller.php controller in the Controller folder under your module, and then rewrite the inside Oh loginpostaction This method:

Public Function loginpostaction ()
{
if (! $this->_validateformkey ()) {
$this->_redirect (' */*/');
Return
}

if ($this->_getsession ()->isloggedin ()) {
$this->_redirect (' */*/');
Return
}
$session = $this->_getsession ();

if ($this->getrequest ()->ispost ()) {

$login = $this->getrequest ()->getpost (' login ');
$data = $login ["username"];
Phone number and user name login process
if (! ( int) ($DATA))
{
If the input is a character, through the username email query out
$read = Mage::getsingleton ("Core/resource")->getconnection (' Core_read ');
$sql = "SELECT * from ' customer_entity ' where username = ' {$data} '";
$result = $read->fetchrow ($sql);
$dataA = $result ["Email"];
$login [' username '] = $dataA;

}else
{
If you enter a number, you can check the email by phone number.
$read = Mage::getsingleton ("Core/resource")->getconnection (' Core_read ');
$sql = "SELECT * from ' customer_entity ' where Customer_mobile_number = ' {$data} '";
$result = $read->fetchrow ($sql);
$dataA = $result ["Email"];
$login [' username '] = $dataA;
}

if (!empty ($login [' username ']) &&!empty ($login [' password ']) {
try {
$session->login ($login [' username '], $login [' Password ']);
if ($session->getcustomer ()->getisjustconfirmed ()) {
$this->_welcomecustomer ($session->getcustomer (), true);
}
} catch (Mage_core_exception $e) {
Switch ($e->getcode ()) {
Case mage_customer_model_customer::exception_email_not_confirmed:
$value = $this->_gethelper (' Customer ')->getemailconfirmationurl ($login [' username ']);
$message = $this->_gethelper (' Customer ')->__ (' The account has not been confirmed. <a href= "%s" > click here </a> get confirmation email. ', $value);
Break
Case Mage_customer_model_customer::exception_invalid_email_or_password:
$message = $e->getmessage ();
Break
Default
$message = $e->getmessage ();
}
$session->adderror ($message);
$session->setusername ($login [' username ']);
} catch (Exception $e) {
Mage::logexception ($e); PA DSS violation:this Exception Log can disclose customer password
}
} else {
$session->adderror ($this->__ (' Username and password error '));
}
}

$this->_loginpostredirect ();
}

Only need to add an if judgment statement to the controller can be very simple to achieve the use of mobile phone number and user name login.


Magento for mobile and username login

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.