UCenter修改用户名无效的解决方法
function onedit() {
$uid = getgpc('uid');
$status = 0;
if(!$this->user['isfounder']) { //判断是否受保护用户
$isprotected = $this->db->result_first("SELECT COUNT(*) FROM ".UC_DBTABLEPRE."protectedmembers WHERE uid = '$uid'");
if($isprotected) {
$this->message('user_edit_noperm');
}
}
if($this->submitcheck()) { //判断是否提交更新
$username = getgpc('username', 'P');
$newusername = getgpc('newusername', 'P');
$password = getgpc('password', 'P');
$email = getgpc('email', 'P');
$delavatar = getgpc('delavatar', 'P');
$rmrecques = getgpc('rmrecques', 'P');
$sqladd = '';
if($username != $newusername) { //是否更新用户名
if($_ENV['user']->get_user_by_username($newusername)) {
$this->message('admin_user_exists');
}
$sqladd .= "username='$newusername', ";
$this->load('note');
$_ENV['note']->add('renameuser', 'uid='.$uid.'&oldusername='.urlencode($username).'&newusername='.
urlencode($newusername));//保存记录
}
if($password) { //密码是否更新
$salt = substr(uniqid(rand()), 0, 6);
$orgpassword = $password;
$password = md5(md5($password).$salt);
$sqladd .= "password='$password', salt='$salt', ";
$this->load('note');
$_ENV['note']->add('updatepw', 'username='.urlencode($username).'&password=');//保存记录
}
if($rmrecques) { //验证问答
$sqladd .= "secques='', ";
}
if(!empty($delavatar)) { //删除头像
$_ENV['user']->delete_useravatar($uid);
}
$this->db->query("UPDATE ".UC_DBTABLEPRE."members SET $sqladd email='$email' WHERE uid='$uid'");
$status = $this->db->errno() ? -1 : 1;
}
$user = $this->db->fetch_first("SELECT * FROM ".UC_DBTABLEPRE."members WHERE uid='$uid'");
$user['bigavatar'] = '';
$user['bigavatarreal'] = '';
$this->view->assign('uid', $uid);
$this->view->assign('user', $user);
$this->view->assign('status', $status);
$this->view->display('admin_user');
}
这个函数首先判断是该用户受保护,然后就是判断是否提交了修改,当提交后,判断用户名是否修改,密码是否做了修改,验证问题及头像等是否修改,如果做了修改,调用add()方法在notelist表保存更新内容,当修改成功后,二次调用send方法时,会自动向各个UCenter应用发出执行命令,更新对应用户的信息,并保存通知,如果不成功,提示通知失败,并指向链接,手动通知。