当前位置:首页 > CMS教程 > phpcms > 列表

phpcmsv9 后台会员注册信息补完开发

发布:smiling 来源: PHP粉丝网  添加日期:2014-10-24 16:30:37 浏览: 评论:0 

开发原因:

有了解过phpcmsv9 的会员注册的都会知道,v9存储会员数据会有多张数据表,其中member表为主表,其他的表为对应会员模型的附表,我们在后台注册了会员,但始终都需要会员登陆到会员中心去填写剩余的信息,大家知道客户的需求是合 (bian) 理 (tai) 的,有可能就会有需要后台注册的时候连同会员的详细信息都填上去..

因此这个开发就产生了.

开发过程:

涉及的模块   /modules/member/

新建的模块   /modules/student/,例子,以后台注册学生时同时补充学生信息.

一. 复制dianping模块,重命名为student,把入面的dianping.php 改名为 stu_reg.php 并打开,改好类名,我们跳过安装步骤.

(1)向menu表添加我们需要用的控制器信息,`name`='student',`parentid` = 29,`m`='student',`c`='stu_reg',`a`='init'其他默认.

(2)向module表添加这个模块的信息 `module`='student',`name`='学生后台注册',`installdate`和`updatedate`选到当天,其他默认.

(3)在用户->管理会员模型->普通会员选择字段管理->添加自己所需的字段,配合注册模板.

(3)更新缓存

二.参考原后台注册控制器 member/member.php 里面的 add() 方法和 member/templates/member_add.tpl.php 入面的表单和表单验证.

(1) stu_reg.php中的 __construct(),init()方法和注册相关的私有方法,模板文件暂时先不修改.

  1. <?php   
  2. defined('IN_PHPCMS'or exit('No permission resources.');   
  3. pc_base::load_app_class('admin','admin',0);   
  4. pc_base::load_app_func('global','');//导入程序处理函数   
  5. class stu_reg extends admin {   
  6.     function __construct() {   
  7.         parent::__construct();   
  8.         //加载用户model   
  9.         $this->db = pc_base::load_model('member_model');   
  10.         $this->_init_phpsso();   
  11.         pc_base::load_sys_class('form');   
  12.     }   
  13.        
  14.     public function init() {   
  15.         if(isset($_POST['dosubmit'])) {   
  16.             $info = array();   
  17.             if(!$this->_checkname($_POST['info']['username'])){   
  18.                 showmessage(L('member_exist'));   
  19.             }   
  20.             $info = $this->_checkuserinfo($_POST['info']);   
  21.             if(!$this->_checkpasswd($info['password'])){   
  22.                 showmessage(L('password_format_incorrect'));   
  23.             }   
  24.             $info['regip'] = ip();   
  25.             $info['overduedate'] = strtotime($info['overduedate']);   
  26.    
  27.             $status = $this->client->ps_member_register($info['username'], $info['password'], $info['email'], $info['regip']);   
  28.    
  29.             if($status > 0) {   
  30.                 unset($info[pwdconfirm]);   
  31.                 $info['phpssouid'] = $status;   
  32.                 //取phpsso密码随机数   
  33.                 $memberinfo = $this->client->ps_get_member_info($status);   
  34.                 $memberinfo = unserialize($memberinfo);   
  35.                 $info['encrypt'] = $memberinfo['random'];   
  36.                 $info['password'] = password($info['password'], $info['encrypt']);   
  37.                 $info['regdate'] = $info['lastdate'] = SYS_TIME;   
  38.                 //默认学生模型ID为10 这里可以自己制定;   
  39.                 $info['modelid'] = 10;   
  40.                 //学生用户组看需要改, 这里默认为2   
  41.                 $info['groupid'] = 2;   
  42.                 $this->db->insert($info);   
  43.                 if($userid = $this->db->insert_id()){   
  44.                     //datail表单会出现在模板   
  45.                     $detail = $_POST['detail'];   
  46.                     //把返回的学生ID装入数组   
  47.                     $detail['userid'] = $userid;   
  48.                     //设定用户的模型ID为10   
  49.                     $this->db->set_model(10);   
  50.                     $this->db->insert($detail);   
  51.                     //这里的跳转也要修改   
  52.                     showmessage(L('operation_success'),'?m=student&c=stu_reg&a=init');   
  53.                 }   
  54.             } elseif($status == -4) {   
  55.                 showmessage(L('username_deny'), HTTP_REFERER);   
  56.             } elseif($status == -5) {   
  57.                 showmessage(L('email_deny'), HTTP_REFERER);   
  58.             } else {   
  59.                 showmessage(L('operation_failure'), HTTP_REFERER);   
  60.             }   
  61.         } else {   
  62.             include $this->admin_tpl('stu_reg');   
  63.         }   
  64.            
  65.     }   
  66.    
  67.     private function _checkuserinfo($data$is_edit=0) {   
  68.         if(!is_array($data)){   
  69.             showmessage(L('need_more_param'));return false;   
  70.         } elseif (!is_username($data['username']) && !$is_edit){   
  71.             showmessage(L('username_format_incorrect'));return false;   
  72.         } elseif (!isset($data['userid']) && $is_edit) {   
  73.             showmessage(L('username_format_incorrect'));return false;   
  74.         }  elseif (emptyempty($data['email']) || !is_email($data['email'])){   
  75.             showmessage(L('email_format_incorrect'));return false;   
  76.         }   
  77.         return $data;   
  78.     }   
  79.            
  80.     private function _checkpasswd($password){   
  81.         if (!is_password($password)){   
  82.             return false;   
  83.         }   
  84.         return true;   
  85.     }   
  86.        
  87.     private function _checkname($username) {   
  88.         $username =  trim($username);   
  89.         if ($this->db->get_one(array('username'=>$username))){   
  90.             return false;   
  91.         }   
  92.         return true;   
  93.     }   
  94.        
  95.     /**  
  96.      * 初始化phpsso  
  97.      * about phpsso, include client and client configure  
  98.      * @return string phpsso_api_url phpsso地址  
  99.      */   
  100.     private function _init_phpsso() {   
  101.         pc_base::load_app_class('client''', 0);   
  102.         define('APPID', pc_base::load_config('system''phpsso_appid'));   
  103.         $phpsso_api_url = pc_base::load_config('system''phpsso_api_url');  
  104.         $phpsso_auth_key = pc_base::load_config('system''phpsso_auth_key');   
  105.         $this->client = new client($phpsso_api_url$phpsso_auth_key);   
  106.         return $phpsso_api_url;  //开源软件:phpfensi.com 
  107.     }   
  108. }   
  109. ?>   

(2) 直接复制member/templates/member_add.tpl.php 到 student/templates/stu_reg.tpl.php (stu_reg.tpl.php需要自己创建).

  1. <?php   
  2. defined('IN_ADMIN'or exit('No permission resources.');   
  3. include $this->admin_tpl('header''admin');   
  4. ?>   
  5. <div class="pad-lr-10">    
  6. <script language="javascript" type="text/javascript" src="<?php echo JS_PATH?>formvalidator.js" charset="UTF-8"></script>   
  7. <script language="javascript" type="text/javascript" src="<?php echo JS_PATH?>formvalidatorregex.js" charset="UTF-8"></script>   
  8. <script type="text/javascript">   
  9. <!--   
  10. $(function(){   
  11.     $.formValidator.initConfig({autotip:true,formid:"myform",onerror:function(msg){}});   
  12.    
  13.     $("#username").formValidator({onshow:"<?php echo L('input').L('username')?>",onfocus:"<?php echo L('username').L('between_2_to_20')?>"}).inputValidator({min:2,max:20,onerror:"<?php echo L('username').L('between_2_to_20')?>"}).regexValidator({regexp:"ps_username",datatype:"enum",onerror:"<?php echo L('username').L('format_incorrect')?>"}).ajaxValidator({   
  14.         type : "get",   
  15.         url : "",   
  16.         data :"m=member&c=member&a=public_checkname_ajax",   
  17.         datatype : "html",   
  18.         async:'false',   
  19.         success : function(data){   
  20.             if( data == "1" ) {   
  21.                 return true;   
  22.             } else {   
  23.                 return false;   
  24.             }   
  25.         },   
  26.         buttons: $("#dosubmit"),   
  27.         onerror : "<?php echo L('deny_register').L('or').L('user_already_exist')?>",   
  28.         onwait : "<?php echo L('connecting_please_wait')?>"   
  29.     });   
  30.     $("#password").formValidator({onshow:"<?php echo L('input').L('password')?>",onfocus:"<?php echo L('password').L('between_6_to_20')?>"}).inputValidator({min:6,max:20,onerror:"<?php echo L('password').L('between_6_to_20')?>"});   
  31.     $("#pwdconfirm").formValidator({onshow:"<?php echo L('input').L('cofirmpwd')?>",onfocus:"<?php echo L('input').L('passwords_not_match')?>",oncorrect:"<?php echo L('passwords_match')?>"}).compareValidator({desid:"password",operateor:"=",onerror:"<?php echo L('input').L('passwords_not_match')?>"});   
  32.     $("#point").formValidator({tipid:"pointtip",onshow:"<?php echo L('input').L('point').L('point_notice')?>",onfocus:"<?php echo L('point').L('between_1_to_8_num')?>"}).regexValidator({regexp:"^\\d{1,8}$",onerror:"<?php echo L('point').L('between_1_to_8_num')?>"});   
  33.     $("#email").formValidator({onshow:"<?php echo L('input').L('email')?>",onfocus:"<?php echo L('email').L('format_incorrect')?>",oncorrect:"<?php echo L('email').L('format_right')?>"}).inputValidator({min:2,max:32,onerror:"<?php echo L('email').L('between_2_to_32')?>"}).regexValidator({regexp:"email",datatype:"enum",onerror:"<?php echo L('email').L('format_incorrect')?>"}).ajaxValidator({   
  34.         type : "get",   
  35.         url : "",   
  36.         data :"m=member&c=member&a=public_checkemail_ajax",   
  37.         datatype : "html",   
  38.         async:'false',   
  39.         success : function(data){      
  40.             if( data == "1" ) {   
  41.                 return true;   
  42.             } else {   
  43.                 return false;   
  44.             }   
  45.         },   
  46.         buttons: $("#dosubmit"),   
  47.         onerror : "<?php echo L('deny_register').L('or').L('email_already_exist')?>",   
  48.         onwait : "<?php echo L('connecting_please_wait')?>"   
  49.     });   
  50.     $("#nickname").formValidator({onshow:"<?php echo L('input').L('nickname')?>",onfocus:"<?php echo L('nickname').L('between_2_to_20')?>"}).inputValidator({min:2,max:20,onerror:"<?php echo L('nickname').L('between_2_to_20')?>"}).regexValidator({regexp:"ps_username",datatype:"enum",onerror:"<?php echo L('nickname').L('format_incorrect')?>"}).ajaxValidator({   
  51.         type : "get",   
  52.         url : "",   
  53.         data :"m=member&c=index&a=public_checknickname_ajax",   
  54.         datatype : "html",   
  55.         async:'false',   
  56.         success : function(data){   
  57.             if( data == "1" ) {   
  58.                 return true;   
  59.             } else {   
  60.                 return false;   
  61.             }   
  62.         },   
  63.         buttons: $("#dosubmit"),   
  64.         onerror : "<?php echo L('already_exist').L('already_exist')?>",   
  65.         onwait : "<?php echo L('connecting_please_wait')?>"   
  66.     }).defaultPassed();   
  67. });   
  68. //-->   
  69. </script>   
  70. <div class="common-form">   
  71. <form name="myform" action="?m=student&c=stu_reg&a=init" method="post" id="myform">   
  72. <fieldset>   
  73.     <legend><?php echo L('basic_configuration')?></legend>   
  74.     <table width="100%" class="table_form">   
  75.         <tr>   
  76.             <td width="80">用户名 </td>    
  77.             <td><input type="text" name="info[username]"  class="input-text" id="username"></input></td>   
  78.         </tr>   
  79.         <tr>   
  80.             <td>密码 </td>    
  81.             <td><input type="password" name="info[password]" class="input-text" id="password" value=""></input></td>   
  82.         </tr>   
  83.         <tr>   
  84.             <td>确认密码</td>    
  85.             <td><input type="password" name="info[pwdconfirm]" class="input-text" id="pwdconfirm" value=""></input></td>   
  86.         </tr>   
  87.         <tr>   
  88.             <td>昵称 </td>    
  89.             <td><input type="text" name="info[nickname]" id="nickname" value="" class="input-text"></input></td>   
  90.         </tr>   
  91.         <tr>   
  92.             <td>电子邮箱</td>   
  93.             <td>   
  94.             <input type="text" name="info[email]" value="" class="input-text" id="email" size="30"></input>   
  95.             </td>   
  96.         </tr>   
  97.         <tr>   
  98.             <td>真实姓名: </td>    
  99.             <td><input type="text" name="detail[realname]" id="realname" value="" class="input-text"></input></td>   
  100.         </tr>   
  101.         <tr>   
  102.             <td>QQ号码: </td>    
  103.             <td><input type="text" name="detail[qqnum]" id="qqnum" value="" class="input-text"></input></td>   
  104.         </tr>   
  105.     </table>   
  106. </fieldset>   
  107.    
  108.     <div class="bk15"></div>   
  109.     <input name="dosubmit" type="submit" id="dosubmit" value="<?php echo L('submit')?>">   
  110. </div>   
  111. </body>   
  112. </html> 

一些语言包相关的就自己改吧..我这里只改了几个,要注意的是提交按钮,原来的有个class样式默认是不会显示按钮的,需要把它去掉,还有from的表 action也要注意修改,学生详细信息中 name="detail[xxxxx]" 方便后台接收.

Tags: phpcmsv9后台会员 phpcms会员注册

分享到: