phpcms v9实现会员在一个页面修改昵称、手机号、邮箱、密码等信息
有的时候需要会员在一个页面就可以同时修改昵称、手机号码、邮箱、密码等信息,而phpcms默认的是将几者分开处理的,这样极大的不方便,为此,根据项目需求,半吊子程序猿的我写了一个小函数来实现这个功能,不喜勿喷咯,哈哈!
第一步:将以下代码放入\phpcms\modules\member\index.php中:
public function gai_intro() {if(isset($_POST['dosubmit'])) {$updateinfo = array();//修改手机号码if($_POST['mobile'] && $this->memberinfo['mobile'] != $_POST['mobile']) {//如果接收到数据且与数据库中记录的值不相符才进行操作$mobile = $_POST['mobile'];$this->db->update(array('mobile'=>$mobile), array('userid'=>$this->memberinfo['userid']));}//修改姓名$nickname = $_POST['nickname'];if($nickname) {$this->db->update(array('nickname'=>$nickname), array('userid'=>$this->memberinfo['userid']));if(!isset($cookietime)) {$get_cookietime = param::get_cookie('cookietime');}$_cookietime = $cookietime ? intval($cookietime) : ($get_cookietime ? $get_cookietime : 0);$cookietime = $_cookietime ? TIME + $_cookietime : 0;param::set_cookie('_nickname', $nickname, $cookietime);}//修改会员邮箱if($this->memberinfo['email'] != $_POST['email'] && is_email($_POST['email'])) {$email = $_POST['email'];$this->db->update(array('email'=>$email), array('userid'=>$this->memberinfo['userid']));//将新邮箱写入phpsso中if(pc_base::load_config('system', 'phpsso')) {//初始化phpsso$this->_init_phpsso();$res = $this->client->ps_member_edit('', $email, '', '', $this->memberinfo['phpssouid'], $this->memberinfo['encrypt']);$message_error = array('-1'=>L('user_not_exist'), '-2'=>L('old_password_incorrect'), '-3'=>L('email_already_exist'), '-4'=>L('email_error'), '-5'=>L('param_error'));if ($res < 0) showmessage($message_error[$res]);}}//当旧密码和新密码均存在时进行下列操作if($_POST['password'] && $_POST['newpassword']){if(!is_password($_POST['password'])) {showmessage(L('password_format_incorrect'), HTTP_REFERER);}//判断传入的旧密码是否与数据库中的密码相符if($this->memberinfo['password'] != password($_POST['password'], $this->memberinfo['encrypt'])) {showmessage(L('old_password_incorrect'), HTTP_REFERER);}if(!is_password($_POST['newpassword'])) {showmessage(L('password_format_incorrect'), HTTP_REFERER);}$newpassword = password($_POST['newpassword'], $this->memberinfo['encrypt']);$updateinfo['password'] = $newpassword;//将新密码写入_member表中$this->db->update($updateinfo, array('userid'=>$this->memberinfo['userid']));//将新密码写入phpsso中if(pc_base::load_config('system', 'phpsso')) {//初始化phpsso$this->_init_phpsso();$res = $this->client->ps_member_edit('', '', $_POST['password'], $_POST['newpassword'], $this->memberinfo['phpssouid'], $this->memberinfo['encrypt']);$message_error = array('-1'=>L('user_not_exist'), '-2'=>L('old_password_incorrect'), '-3'=>L('email_already_exist'), '-4'=>L('email_error'), '-5'=>L('param_error'));if ($res < 0) showmessage($message_error[$res]);}}//当旧密码和新密码均存在时进行以上操作showmessage(L('operation_success'), HTTP_REFERER);} else {$show_validator = true;$memberinfo = $this->memberinfo;include template('member', 'gai_intro');}}
第二步:对应的在\phpcms\templates\default\member\中新建一个gai_intro.html文件,文件中包含下列代码:
<form method="post" action="index.php?m=member&c=index&a=gai_intro" id="myform" name="myform"><li><span>姓名:</span><input name="nickname" type="text" id="nickname" value="{$memberinfo['nickname']}"></li><li><span>手机号码:</span><input name="mobile" type="text" id="mobile" value="{$memberinfo['mobile']}"></li><li><span>邮箱:</span><input name="email" type="text" id="email" value="{$memberinfo['email']}"></li><li><span>旧密码:</span><input name="password" type="password" id="password" value="" placeholder="不修改留空即可"></li><li><span>新密码:</span><input name="newpassword" type="password" id="newpassword" value="" placeholder="修改密码后需要重新登录哦"></li><li><span> </span><input name="dosubmit" type="submit" id="dosubmit" value="提交"></li>
</form>
OK,大功告成啦!