Standard user-registered controller

Source: Internet
Author: User
Standard user-registered controller

The user registration code consists of at least three parts:
A. registration form;
B. client javascript verification code;
C. Code for receiving server-side verification and form information.

Therefore, you need to write a controller class for the registration module: RegisterController. php:
The code is as follows:
Include_once 'goodstypecontroller. php ';
Class RegisterController extends GoodstypeController {

// This method loads the single page of the registry.
Function registerAction (){
// Obtain information about major categories and latest products
Self: $ smarty-> caching = 2;
If (! Self: $ smarty-> is_cached ('Reg/regist. tpl ')){
$ This-> getTypeInfo (new GoodsType ());
Self: $ smarty-> cache_lifetime = 3600*24*10;
}
Self: $ smarty-> display ('Reg/regist. tpl ');
}

// Ajax verifies whether the user name has been registered.
Function checkusernameAction (){
$ Username = trim ($ _ POST ['name']);
$ Model_user = new User ();
$ Count = $ model_user-> selectCount ("username = '$ username '");
If ($ count> 0 ){
Echo 'false ';
} Else {
Echo 'true ';
}
}

// Verify the verification code using ajax.
Function checkrandcodeAction (){
If ($ _ POST ['code']! = $ _ SESSION ['checkcode']) {
Echo "false ";
} Else {
Echo "true ";
}
}

/*
This method is used to register information into the database.
The server verification process is as follows:
Determine whether cross-origin submission, whether the verification code is correct, whether the required information is null, registration information is imported into the database, and the session value is assigned after successful registration, and enter the member center.
*/
Function regokAction (){
If ($ _ SERVER ['request _ method'] = 'post '){
$ Model_user = new User ();

$ Checkcode = $ _ POST ['checkcode'];
If (! $ Checkcode | $ checkcode! = $ _ SESSION ['checkcode']) {
Echo "script" alert ('incorrect verification code! '); History. back (); script "; die;
}
Unset ($ _ SESSION ['checkcode']);

Include_once HELPER_DIR. 'commonfunction. class. php ';
$ Membername = CommonFunction: filter_html (trim ($ _ POST ['membername']);
$ Password = CommonFunction: filter_html (trim ($ _ POST ['password0']);
$ Pwdquestion = CommonFunction: filter_html (trim ($ _ POST ['pwdquestion ']);
$ Pwdanswer = CommonFunction: filter_html (trim ($ _ POST ['pwdanswer ']);
$ Email = CommonFunction: filter_html (trim ($ _ POST ['email ']);

If (! $ Membername |! $ Password |! $ Email |! $ Pwdquestion |! $ Pwdanswer ){
Echo "script" alert ('The registration information is incomplete. Please repeat it! '); History. back (); script "; die;
}

$ Count = $ model_user-> selectCount ("username = '$ membername '");
If ($ count> 0 ){
Echo "script" alert ('The user name already exists. please register again! '); History. back (); script "; die;
}

$ Data ['username'] = $ membername;
$ Data ['password'] = $ password;
$ Data ['pwdquestion '] = $ pwdquestion;
$ Data ['pwdanswer'] = $ pwdanswer;
$ Data ['email '] = $ email;
$ Data ['realname'] = CommonFunction: filter_html (trim ($ _ POST ['realname']);
$ Data ['sex'] =_ _ POST ['sex'];
$ Data ['address'] = CommonFunction: filter_html (trim ($ _ POST ['address']);
$ Data ['QQ'] = CommonFunction: filter_html (trim ($ _ POST ['QQ']);
$ Data ['tel'] = CommonFunction: filter_html (trim ($ _ POST ['tel']);
$ Data ['regip'] = CommonFunction: get_clientip ();

If ($ model_user-> insert ($ data )){
$ _ SESSION ['username'] = $ membername;
$ _ SESSION ['password'] = md5 ($ password );
Echo "script" alert ('registration successful! '); Window. location. href ='/'; script "; die;
} Else {
Echo "script" alert ('registration failed! '); History. back (); script ";
}
}
}

}
?>

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.