建站幫助

誠信合作, 高質專業!

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:[email protected]

同時歡迎大家收聽CMSYOU官方微博,相互探討Phpcms!

我要收藏
點個贊吧

相關閱讀

本月熱門

精選推薦

在線客服

掃一掃,關注我們

掃一掃,關注我們
百人牛牛经验分享