phpcmsv9 後臺會員註冊資訊補完開發
開發原因:
有了解過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()方法和註冊相關的私有方法 (模板檔案暫時先不修改)
<?php defined('IN_PHPCMS') or exit('No permission resources.'); pc_base::load_app_class('admin','admin',0); pc_base::load_app_func('global','');//匯入程式處理函式 class stu_reg extends admin { function __construct() { parent::__construct(); //載入使用者model $this->db = pc_base::load_model('member_model'); $this->_init_phpsso(); pc_base::load_sys_class('form'); } public function init() { if(isset($_POST['dosubmit'])) { $info = array(); if(!$this->_checkname($_POST['info']['username'])){ showmessage(L('member_exist')); } $info = $this->_checkuserinfo($_POST['info']); if(!$this->_checkpasswd($info['password'])){ showmessage(L('password_format_incorrect')); } $info['regip'] = ip(); $info['overduedate'] = strtotime($info['overduedate']); $status = $this->client->ps_member_register($info['username'], $info['password'], $info['email'], $info['regip']); if($status > 0) { unset($info[pwdconfirm]); $info['phpssouid'] = $status; //取phpsso密碼隨機數 $memberinfo = $this->client->ps_get_member_info($status); $memberinfo = unserialize($memberinfo); $info['encrypt'] = $memberinfo['random']; $info['password'] = password($info['password'], $info['encrypt']); $info['regdate'] = $info['lastdate'] = SYS_TIME; //預設學生模型ID為10 這裡可以自己制定; $info['modelid'] = 10; //學生使用者組看需要改, 這裡預設為2 $info['groupid'] = 2; $this->db->insert($info); if($userid = $this->db->insert_id()){ //datail表單會出現在模板 $detail = $_POST['detail']; //把返回的學生ID裝入陣列 $detail['userid'] = $userid; //設定使用者的模型ID為10 $this->db->set_model(10); $this->db->insert($detail); //這裡的跳轉也要修改 showmessage(L('operation_success'),'?m=student&c=stu_reg&a=init'); } } elseif($status == -4) { showmessage(L('username_deny'), HTTP_REFERER); } elseif($status == -5) { showmessage(L('email_deny'), HTTP_REFERER); } else { showmessage(L('operation_failure'), HTTP_REFERER); } } else { include $this->admin_tpl('stu_reg'); } } private function _checkuserinfo($data, $is_edit=0) { if(!is_array($data)){ showmessage(L('need_more_param'));return false; } elseif (!is_username($data['username']) && !$is_edit){ showmessage(L('username_format_incorrect'));return false; } elseif (!isset($data['userid']) && $is_edit) { showmessage(L('username_format_incorrect'));return false; } elseif (empty($data['email']) || !is_email($data['email'])){ showmessage(L('email_format_incorrect'));return false; } return $data; } private function _checkpasswd($password){ if (!is_password($password)){ return false; } return true; } private function _checkname($username) { $username = trim($username); if ($this->db->get_one(array('username'=>$username))){ return false; } return true; } /** * 初始化phpsso * about phpsso, include client and client configure * @return string phpsso_api_url phpsso地址 */ private function _init_phpsso() { pc_base::load_app_class('client', '', 0); define('APPID', pc_base::load_config('system', 'phpsso_appid')); $phpsso_api_url = pc_base::load_config('system', 'phpsso_api_url'); $phpsso_auth_key = pc_base::load_config('system', 'phpsso_auth_key'); $this->client = new client($phpsso_api_url, $phpsso_auth_key); return $phpsso_api_url; } } ?>
(2) 直接複製member/templates/member_add.tpl.php 到 student/templates/stu_reg.tpl.php (stu_reg.tpl.php需要自己建立)
<?php
defined('IN_ADMIN') or exit('No permission resources.');
include $this->admin_tpl('header', 'admin');
?>
<div class="pad-lr-10">
<script language="javascript" type="text/javascript" src="<?php echo JS_PATH?>formvalidator.js" charset="UTF-8"></script>
<script language="javascript" type="text/javascript" src="<?php echo JS_PATH?>formvalidatorregex.js" charset="UTF-8"></script>
<script type="text/javascript">
<!--
$(function(){
$.formValidator.initConfig({autotip:true,formid:"myform",onerror:function(msg){}});
$("#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({
type : "get",
url : "",
data :"m=member&c=member&a=public_checkname_ajax",
datatype : "html",
async:'false',
success : function(data){
if( data == "1" ) {
return true;
} else {
return false;
}
},
buttons: $("#dosubmit"),
onerror : "<?php echo L('deny_register').L('or').L('user_already_exist')?>",
onwait : "<?php echo L('connecting_please_wait')?>"
});
$("#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')?>"});
$("#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')?>"});
$("#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')?>"});
$("#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({
type : "get",
url : "",
data :"m=member&c=member&a=public_checkemail_ajax",
datatype : "html",
async:'false',
success : function(data){
if( data == "1" ) {
return true;
} else {
return false;
}
},
buttons: $("#dosubmit"),
onerror : "<?php echo L('deny_register').L('or').L('email_already_exist')?>",
onwait : "<?php echo L('connecting_please_wait')?>"
});
$("#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({
type : "get",
url : "",
data :"m=member&c=index&a=public_checknickname_ajax",
datatype : "html",
async:'false',
success : function(data){
if( data == "1" ) {
return true;
} else {
return false;
}
},
buttons: $("#dosubmit"),
onerror : "<?php echo L('already_exist').L('already_exist')?>",
onwait : "<?php echo L('connecting_please_wait')?>"
}).defaultPassed();
});
//-->
</script>
<div class="common-form">
<form name="myform" action="?m=student&c=stu_reg&a=init" method="post" id="myform">
<fieldset>
<legend><?php echo L('basic_configuration')?></legend>
<table width="100%" class="table_form">
<tr>
<td width="80">使用者名稱 </td>
<td><input type="text" name="info[username]" class="input-text" id="username"></input></td>
</tr>
<tr>
<td>密碼 </td>
<td><input type="password" name="info[password]" class="input-text" id="password" value=""></input></td>
</tr>
<tr>
<td>確認密碼</td>
<td><input type="password" name="info[pwdconfirm]" class="input-text" id="pwdconfirm" value=""></input></td>
</tr>
<tr>
<td>暱稱 </td>
<td><input type="text" name="info[nickname]" id="nickname" value="" class="input-text"></input></td>
</tr>
<tr>
<td>電子郵箱</td>
<td>
<input type="text" name="info[email]" value="" class="input-text" id="email" size="30"></input>
</td>
</tr>
<tr>
<td>真實姓名: </td>
<td><input type="text" name="detail[realname]" id="realname" value="" class="input-text"></input></td>
</tr>
<tr>
<td>QQ號碼: </td>
<td><input type="text" name="detail[qqnum]" id="qqnum" value="" class="input-text"></input></td>
</tr>
</table>
</fieldset>
<div class="bk15"></div>
<input name="dosubmit" type="submit" id="dosubmit" value="<?php echo L('submit')?>">
</div>
</body>
</html>
一些語言包相關的就自己改吧..我這裡只改了幾個, 要注意的是提交按鈕, 原來的有個class樣式預設是不會顯示按鈕的, 需要把它去掉, 還有from的表 action也要注意修改,
學生詳細資訊中 name="detail[xxxxx]" 方便後臺接收,
這個是個粗略的版本, 基本可以解決上面所說的需求. 希望幫到大家