Magento by default using the mailbox registration login, many users in the country currently do not use the mailbox habits, so need to use mobile phone number to achieve registration.
Use mobile phone number registration, need to relate to the place is more and miscellaneous, here only to say a ballpark and ideas.
The changes involved in mobile registration include:
1. Add Phone Number field
2. Registration process
3. Login Process
4. Forgot password, reset password by phone number
5. Background user table (grid table) displays phone number information
6. Registration and sign-in process for users who are not logged on at checkout page
7. User Information Modification page
8. Many of the features you add are associated with the user's phone number, which requires you to modify the
1. Add Phone Number field
You can search for the user to add a new property of the method, you can also install the management user properties of the plug-in, the background directly add, here is not much to say.
2. Registration process
The registration page can be added with a tab switch to register with the mailbox or by using the phone number, or you can add a new link to the register using your phone number. The latter example is used here:
The handle of the default registration page is
Customer_account_create defines its layout and so on in the customer.xml.
We can modify our own handle according to it, for example,
Customer_account_createmobile
Override customer's controller and create action
public function Createmobileaction () {if ( $this -> _getsession () -> isLoggedIn ()) { $this -> _redirect ( ' */* ' ); return ; } $this -> loadlayout (); $this -> _initlayoutmessages ( ' customer/session ' ); $this -> renderlayout (); }
Create your own register_mobile.phtml
Note here the form action can write a new action URL
in this phtml important place is the Send SMS button to set the OnClick event.
Use AJAX implementation to send text messages, record sessions and other operations. (Note Set Send SMS button, click on the interval)
Send AJAX requests, the system generates random verification code into the session, I also deposited a mobile phone number
There is also a point, is Magento mailbox field is not empty (otherwise modified too much, did not try--!) ), so there is also a need to hide a input used to store fake email (System auto-generated)
Another point:
Notice whether the mobile phone number has been registered.
$session=$this->_getSession();// 我是写在了customer的 accountController类中// 获取session你也可以写为// $session = Mage::getSingleton(‘customer/session‘);$session->setMobile($mobile);$session->setMobileCode($mobile_code);
Deposit phone number, is for users to click the registration button, the detection of the submitted mobile phone number is still used to obtain the verification code that mobile phone number, to prevent users from tampering with the phone number.
Note that the operation should wait until the call message interface returns to successful execution.
This time the user registers such as post data to Createmobilepostaction ()
We can do data validation here, including cell phone number format, whether the mobile phone number is modified, the verification code is correct and so on. The phone number is saved correctly.
3. Login Process
The front-end is directly removed for the input is the mailbox test, modify the Placeholder property prompt phone number can also be.
Data post to Method Loginpostaction ()
Here the approximate core code is:
$userName=Trim($login[' username ']);if(!strstr ($userName,' @ ') && strlen ($userName) == One){//Not a mailbox length of 11 is the mobile phone number rough detection, can be modified by itself $mobileNu= Mage::getmodel (' Customer/customer ')->getcollection ()->addattributetofilter (' Mobile ',$userName)->getfirstitem ();if($mobileNu->getdata (' Email ')){$login[' username '] =$mobileNu->getdata (' Email '); } }
The idea is actually to find the mailbox according to the mobile phone number, and then use the mailbox landing.
4. Forgot password, reset password by phone number
The Forgotten Password page also allows the user to choose whether to reset the password via the mailbox or reset the password by phone number.
The process of resetting the password by phone number is:
Enter the phone number, get the verification code, enter the verification code to submit the data, and determine if the verification code is correct, if there is a user registered with this mobile phone number, all normal, automatically jump to reset Password page, reset password, end
To reset the password front-end page, you can refer to the registration process front-end page, as needed to modify. For example post data to Forgotpasswordmobilepostaction ()
In this method, you need to detect the validity of the data, etc., all the normal generation token, and then jump to
Core code:
if($customerId) {try {$newResetPasswordLinkToken =Mage:: Helper(' Customer ') -Generateresetpasswordlinktoken ();$customer -Changeresetpasswordlinktoken ($newResetPasswordLinkToken);$url =Mage:: GetUrl("').' customer/account/resetpassword?id= '.$customerId.' &token= '.$newResetPasswordLinkToken; Mage:: App() -Getfrontcontroller () -GetResponse () -Setredirect ($url);return; } catch (Exception$exception) {Mage:: Log(' Catch ');$this -_getsession () -Adderror ($exception -GetMessage ());$this -_redirect (' */*/forgotpassword ');return; }}
5. Background user table (grid table) displays phone number information
Add a phone number display field for a table that displays user information in the background
Rewrite mage\adminhtml\block\customer\grid.php
Modification Method _preparecollection ()
Add the following $collection
->addAttributeToSelect(‘mobile‘)
Modification Method _preparecolumns ()
Add code in the appropriate location:
$this->addColumn(‘mobile‘, array( ‘header‘ =>Mage::helper(‘customer‘)->__(‘手机号‘), ‘index‘ =>‘mobile‘, ‘width‘ =>‘10‘ ));
6. Registration and sign-in process for users who are not logged on at checkout page
Modify Template\persistent\customer\form\login.phtml to
Refer to User Login page front-end modification.
7. User Information Modification page
Modify Template\customer\form\edit.phtml
To add the user to modify the phone number of the input box, you also need to get SMS verification code.
Modify the Editpostaction () method in the controller to
Note whether the mobile phone number has already been registered.
8. Many of the features you add are associated with the user's phone number, which requires you to modify the
There's nothing I can do about it.
Magento sign in with your phone number