Discuz x3.2昵称功能修改
思路:
尽可能少的改动文件(模板及其他相关文件)
common_member表中,新加一个字段loginname,用来代替原来的username
common_member表中原username当成昵称使用
改动相关注册和登录逻辑,即可实现,尽最大程序减少模板等相关文件修改
一、SQL修改记录
ALTER TABLE pre_common_member ADD COLUMN loginname char(15) NOT NULL;
UPDATE pre_common_member SET loginname=username;
UPDATE pre_common_member SET username=nickname;
ALTER TABLE `pre_common_member` ADD INDEX loginname(`loginname`);
二、登录逻辑修改
M uc_client/model/user.php : function get_user_by_boyuan(…)
1.修改common_member相关操作中,username变为昵称
2.新增loginname字段,使用原username的值
//原username当成昵称使用,新增loginname字段用来登录
$row = DB::fetch_first("SELECT * FROM ".DB::table('common_member')." WHERE loginname='$username'");
if ( isset($row['uid']) ) return $row;
DB::insert('common_member', array(
'uid' => $uid,
'username' => $response->NickName,
'loginname' => $username,
'password' => md5($password),
'email' => $username,
'adminid' => 0,
'groupid' => 10,
'regdate' => TIMESTAMP,
'credits' => 5,
'timeoffset' => 9999,
'nickname' => $response->NickName,
));
三、注册逻辑修改
M source/class/class_member.php : function on_register()
1.增加nickname
$nickname = isset($_GET['field1']) ? trim($_GET['field1']) : '';
$nickname = addslashes(dhtmlspecialchars($nickname));
2.昵称重复检查
if(C::t('common_member')->fetch_uid_by_nickname($nickname)) {
if($_G['inajax']) {
showmessage('profile_nickname_duplicate');
} else {
showmessage('register_activation_message', 'member.php?mod=logging&action=login', array('username' => $username));
}
}
3.向common_member注册时传入参数,增加nickname
//注册传入nickname参数
$init_arr = array('credits' => explode(',', $this->setting['initcredits']), 'profile'=>$profile, 'emailstatus' => $emailstatus,'nickname'=>$nickname);
M source/class/table/table_common_member.php
1.修改 fetch_uid_by_username(){},变更字段username->loginname
public function fetch_uid_by_username($username, $fetch_archive = 0) {
$uid = 0;
if($username) {
$uid = DB::result_first('SELECT uid FROM %t WHERE loginname=%s', array($this->_table, $username));
if(isset($this->membersplit) && $fetch_archive && empty($uid)) {
$uid = C::t($this->_table.'_archive')->fetch_uid_by_username($username, 0);
}
}
return $uid;
}
2.新增 fetch_uid_by_nickname(){}
public function fetch_uid_by_nickname($nickname, $fetch_archive = 0) {
$uid = 0;
if($nickname) {
$uid = DB::result_first('SELECT uid FROM %t WHERE username=%s', array($this->_table, $nickname));
if(isset($this->membersplit) && $fetch_archive && empty($uid)) {
$uid = C::t($this->_table.'_archive')->fetch_uid_by_username($username, 0);
}
}
return $uid;
}
3.修改insert(){}
$nickname = isset($extdata[‘nickname’]) ? $extdata[‘nickname’] : ‘’;
‘username’ => (string)$nickname,
‘loginname’ => (string)$username,
public function insert($uid, $username, $password, $email, $ip, $groupid, $extdata, $adminid = 0) {
if(($uid = dintval($uid))) {
$nickname = isset($extdata['nickname']) ? $extdata['nickname'] : '';
$credits = isset($extdata['credits']) ? $extdata['credits'] : array();
$profile = isset($extdata['profile']) ? $extdata['profile'] : array();
$profile['uid'] = $uid;
$base = array(
'uid' => $uid,
'username' => (string)$nickname,
'loginname' => (string)$username,
'password' => (string)$password,
'email' => (string)$email,
.....