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]"   方便后台接收,  


这个是个粗略的版本,   基本可以解决上面所说的需求.  希望帮到大家

评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值