The day before yesterday, the director of the company raised a demand, the realization of my company's registered members of the registration of mobile phone number login This feature, then this feature is easy to modify, in my previous blog post has given the treatment method, but here is a problem, if the implementation of the mobile phone number to log in, Then you need to register at the time to ensure that the member's mobile phone number is unique, that is, the mobile phone number has not been registered, then how to detect the number of the phone is registered?
First, the reference inspection mailbox
Because of the registration page, there are steps to check whether the user name and mailbox are repeated, the preliminary idea is to refer to the method of checking the mailbox to resolve, but view user_passport.dwt as follows:
Seems to be able to open as above the phone number of the input tag to add a onblur event, but looked for and found, and did not find the phone number of the input tag where, but found the following code:
Suddenly, because the default Ecshop registration page mobile phone number is not required options, and can be managed in the background, and these options in the Ecshop data table Esc_reg_fields table, so the reference to detect the method of email failed!
Second, the solution
By viewing the Code of the page, when the user clicks the Register button, there is a return register (), the method in the Js/user.js file, so we can start from this method, after verifying the phone number of the regular match, the mobile phone number is registered verification.
2.1. Modify the User.js file
Find the following code in the User.js file:
1 if (mobile_phone.length>0) 2 {3 var reg =/^[\d|\-|\s]+$/; 4 if (! reg.test (mobile_phone)) 5 {6 msg + = Mobile_phone_invalid + ' \ n '; 7 }8 }
Replace it with the following code:
1 if(mobile_phone.length>0)2 {3 varReg =/(^1[3|5|8][0-9]{9}$)/;;4 if(!reg.test (mobile_phone))5 {6msg + = Mobile_phone_invalid + ' \ n ';7 }8
9 Else{Ten //the request must be a synchronous request, the No side MSG assignment fails, and the registration is submitted. One $.ajax ({ AType: ' GET ', -URL: ' User.php?act=check_mobile_phone ', - data: {Mobile_phone:mobile_phone}, theAsyncfalse, -DataType: ' Text ', -Successfunction(data) { - if(data = = ' false ') + { -msg + = mobile_phone_invalid2+ ' \ n '; + } A Else at { - - } - } - }); - in -}
to}
2.2, add check_mobile_phone processing in user.php
Find the following code in user.php:
1 /*Verify that the user's email address is registered*/2 ElseIf($action= = ' Check_email ')3 {4 $email=Trim($_get[' Email ']);5 if($user->check_email ($email))6 {7 Echo' False ';8 }9 ElseTen { One Echo' OK '; A } -}
Copy it and add it below it and modify it as follows:
1 /*Verify that the user's phone number is registered*/2 ElseIf($action= = ' Check_mobile_phone ')3 {4 $mobile _phone=Trim($_get[' Mobile_phone ']);5 if($user->check_mobile_phone ($mobile _phone))//If you have already been registered6 {7 Echo' False ';8 }9 ElseTen { One Echo' OK '; A } -}
2.3. Add Check_mobile_phone function in integrate.php
Find the following code in includes/modules/integrates/integrate.php:
1 functionCheck_email ($email)2 {3 if(!Empty($email))4 {5 /*Check if email is duplicated*/6 $sql= "Select".$this->field_id.7"From".$this->table ($this->user_table).8"WHERE".$this->field_email. =$email‘ ";9 if($this->db->getone ($sql,true) > 0)Ten { One $this->error =err_email_exists; A return true; - } - return false; the } -}
Copy it and add it below it and modify it as follows:
functionCheck_mobile_phone ($mobile _phone) { if(!Empty($mobile _phone)) { /*Check if the phone number is duplicated*/ $sql= "Select".$this->field_id. "From".$this->table ($this->user_table). "WHERE mobile_phone= '$mobile _phone‘ "; if($this->db->getone ($sql,true) > 0) { return true; } return false; } }
At this point, the problem is resolved, this scenario does not use the Ecshop itself encapsulated Ajax.call (...) Method, Ajax.call (...) method is actually quite convenient, but according to the return value of its callback function to change the value of the MSG in the register () function, this I have no way to do, but also a little bit of regret it, put forward here, blog Park inside the Bo friends if there is a good way, please do not hesitate to enlighten!
Ecshop implementation of registration page mobile phone number unique authentication