建站帮助

诚信合作, 高质专业!

Phpcms v9会员中心修改邮箱/密码分拆优化的方法

2019-10-25 12:07:11 浏览 我要评论

用过Phpcms v9会员中心的朋友可能会发现:默认Phpcms v9会员中心的账号管理里边的【修改邮箱/密码】是放在一个页面内,于是会在如果不用修改密码只是要修改邮箱的情况出现一些困扰,比较久没写原装教程了,今天CMSYOU在这里与大家分享Phpcms v9会员中心修改邮箱/密码分拆优化的方法!

先来了解下Phpcms v9默认会员中心的账号管理里边的修改邮箱/密码页面:

Phpcms v9默认会员中心的账号管理里边的修改邮箱/密码页面

有些会员可能在这里修改的就会碰到疑问:修改邮箱的同时怎么还需要修改密码?

基于此,很有必要把修改邮箱和修改密码分拆,避免一些不需要的麻烦。

Phpcms v9会员中心修改邮箱/密码分拆优化的方法:

1、修改phpcms/modules/member/index.php中的account_manage_password方法:

$updateinfo = array();
if(!is_password($_POST['info']['password'])) {
showmessage(L('password_format_incorrect'), HTTP_REFERER);
}
if($this->memberinfo['password'] != password($_POST['info']['password'], $this->memberinfo['encrypt'])) {
showmessage(L('old_password_incorrect'), HTTP_REFERER);
}
 
//修改会员邮箱
if($this->memberinfo['email'] != $_POST['info']['email'] && is_email($_POST['info']['email'])) {
$email = $_POST['info']['email'];
$updateinfo['email'] = $_POST['info']['email'];
} else {
$email = '';
}
if(!is_password($_POST['info']['newpassword']) || is_badword($_POST['info']['newpassword'])) {
showmessage(L('password_format_incorrect'), HTTP_REFERER);
}
$newpassword = password($_POST['info']['newpassword'], $this->memberinfo['encrypt']);
$updateinfo['password'] = $newpassword;
 
$this->db->update($updateinfo, array('userid'=>$this->memberinfo['userid']));
if(pc_base::load_config('system', 'phpsso')) {
//初始化phpsso
$this->_init_phpsso();
$res = $this->client->ps_member_edit('', $email, $_POST['info']['password'], $_POST['info']['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);

修改为:

$updateinfo = array();
if(!is_password($_POST['info']['newpassword']) || is_badword($_POST['info']['newpassword'])) {
showmessage(L('password_format_incorrect'), HTTP_REFERER);
}
if(trim($_POST['info']['newpassword']) != trim($_POST['info']['renewpassword'])) {
showmessage(L('passwords_not_match'), HTTP_REFERER);
}
$newpassword = password(trim($_POST['info']['newpassword']), $this->memberinfo['encrypt']);
$updateinfo['password'] = $newpassword;
 
$this->db->update($updateinfo, array('userid'=>$this->memberinfo['userid']));
if(pc_base::load_config('system', 'phpsso')) {
//初始化phpsso
$this->_init_phpsso();
$res = $this->client->ps_member_edit($this->memberinfo['username'], $this->memberinfo['email'], '', $_POST['info']['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);

这一步中,将原有的account_manage_password方法简化,做成只修改会员密码。

2、配套修改前台模板文件:templates/cmsyou(你用的模板的目录)/member/account_manage_password.html,将邮箱那一栏的input去掉,具体代码请自己尝试修改,这里不给出具体代码。

修改后的会员中心修改密码页面

修改后的会员中心修改密码页面(见CMSYOU.com会员中心)

3、在phpcms/modules/member/index.php中新增account_manage_email方法,用于单独修改email:

public function account_manage_email() {
if(isset($_POST['dosubmit'])) {
$updateinfo = array();
 
//修改会员邮箱
if($this->memberinfo['email'] != $_POST['info']['email'] && is_email($_POST['info']['email'])) {
$email = trim($_POST['info']['email']);
$updateinfo['email'] = $_POST['info']['email'];
}elseif($this->memberinfo['email'] == $_POST['info']['email']) {
showmessage(L('email_same'), HTTP_REFERER);
} else {
showmessage(L('email_format_incorrect'), HTTP_REFERER);
}
$this->db->update($updateinfo, array('userid'=>$this->memberinfo['userid']));
if(pc_base::load_config('system', 'phpsso')) {
//初始化phpsso
$this->_init_phpsso();
$res = $this->client->ps_member_edit($this->memberinfo['username'], $email);
$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 {
$siteid = isset($_REQUEST['siteid']) && trim($_REQUEST['siteid']) ? intval($_REQUEST['siteid']) : 1;
$siteinfo = siteinfo($siteid);
 
//SEO
$SEO = seo($siteid);
if(!$setting['meta_title']) $setting['meta_title'] = '修改邮箱';
$SEO = seo($siteid, '',$setting['meta_title'],$setting['meta_description'],$setting['meta_keywords']);
 
$show_validator = true;
$memberinfo = $this->memberinfo;
 
include template('member', 'account_manage_email');
}
}

4、在会员模板目录templates/cmsyou(你用的模板的目录)/member/新增account_manage_email.html模板文件,模板的写法参考account_manage_password.html模板的写法,在这也不给出具体的代码了,请自行研究。

修改后的会员中心修改邮箱页面

修改后的会员中心修改Email页面(见CMSYOU.com会员中心)

至此,已经成功将修改邮箱/密码分拆,做到邮箱和密码单独修改。

今天的分享就到这里,欢迎大家抱着研究的心态自定义Phpcms,多多分享,如果有好的文章也欢迎投稿,投稿email:info@cmsyou.com。

同时欢迎大家收听CMSYOU官方微博,相互探讨Phpcms!

我要收藏
点个赞吧

相关阅读

本月热门

精选推荐

在线客服

扫一扫,关注我们

扫一扫,关注我们