修改discuz,uchome,ucenter兼容自己開發的通行證
最近稍有接觸,修改其中的部分代碼,就貢獻其中的關鍵部分吧。
目前discuz的會員注冊是在discuz自己的體系中完成,然後post(或者MySQL直接操作,此處以post代稱)到ucenter的數據庫,其中會員密碼是md5(md5(真實密碼)+首次隨機字符sult),memberid由ucenter產生。然後得到改值,保存在discuz。
如果是自己已有通行證系統,產生id,保存密碼這部分就在自己的系統完成,然後送回來到ucenter,然後保存到dizcuz。
在uc_center/clIEnt.PHP中加入代碼
//cjjer
function uc_user_registerCjjer($uid,$username, $passWord, $email, $questionid = '', $answer = '') {
return call_user_func(UC_API_FUNC, 'user', 'register', array('uid'=>$uid,'username'=>$username, 'password'=>$passWord, 'email'=>$email, 'questionid'=>$questionid, 'answer'=>$answer));
}
function uc_user_updateCjjer($uid,$username, $passWord, $email, $questionid = '', $answer = '') {
return call_user_func(UC_API_FUNC, 'user', 'myupdate', array('uid'=>$uid,'username'=>$username, 'password'=>$passWord, 'email'=>$email, 'questionid'=>$questionid, 'answer'=>$answer));
}
注冊的時候就用uc_user_registerCjjer。
在contol/user.PHP加入代碼:
// rewrite by cjjer
function onregister() {
$this->init_input();
$username = $this->input('username');
$myuserid = intval($this->input('uid'));
$password = $this->input('passWord');
$email = $this->input('email');
$questionid = $this->input('questionid');
$answer = $this->input('answer');
if( (($status = $this->_check_username($username)) < 0) ||
(($status = $this->_check_email($email)) < 0)||
($status = $_ENV['user']->get_user_by_uid($myuserid))
) {
//開始更新會員資料
$_ENV['user']->update_user($myuserid,$username, $passWord, $email, $myuserid, $questionid, $answer);
return $myuserid;
}else{
$uid = $_ENV['user']->add_user($username, $passWord, $email, $myuserid, $questionid, $answer);
}
return $uid;
}
function onmyupdate() {
$this->init_input();
$username = $this->input('username');
$myuserid = intval($this->input('uid'));
$password = $this->input('passWord');
$email = $this->input('email');
$questionid = $this->input('questionid');
$answer = $this->input('answer');
$status = $_ENV['user']->get_user_by_uid($myuserid);
if(!$status) {
return -1;
}
$uid = $_ENV['user']->update_user($myuserid,$username, $passWord, $email, $myuserid, $questionid, $answer);
return $uid;
}
然後在model/user.PHP加入
function update_user($user_id,$username, $passWord, $email, $uid = 0, $questionid = '', $answer = '') {
$salt = substr(uniqid(rand()), -6);
$password = md5(md5($passWord).$salt);
if(! $uid)return 0;
$sqladd = $uid ? "uid='".intval($uid)."'," : '';
$sqladd .= $questionid > 0 ? " secques='".$this->quescrypt($questionid, $answer)."'," : " secques='',";
//不更新密碼,,salt='$salt'
$this->db->query("update ".UC_DBTABLEPRE."members SET username='$username', email='$email' where uid='$uid'");
return $user_id;
}
修改其中的add_user方法為:
function add_user($username, $passWord, $email, $uid = 0, $questionid = '', $answer = '') {
$salt = substr(uniqid(rand()), -6);
$password = md5(md5($passWord).$salt);
$sqladd = $uid ? "uid='".intval($uid)."'," : '';
$sqladd .= $questionid > 0 ? " secques='".$this->quescrypt($questionid, $answer)."'," : " secques='',";
$this->db->query("INSERT INTO ".UC_DBTABLEPRE."members SET $sqladd username='$username', password='$passWord', email='$email', regip='".$this->base->onlineip."', regdate='".$this->base->time."', salt='$salt'");
$uid = $this->db->insert_id();
$this->db->query("INSERT INTO ".UC_DBTABLEPRE."memberfIElds SET uid='$uid'");
return $uid;
}
這樣,在uchome注冊的用戶就能自動映射到discuz,不需要激活。直接更新。
其中discuz系統的關鍵部分在include/common.inc.PHP裡面的140行左右的驗證用戶登錄的。這裡切入即可。就是在產生$sid=$discuz_pw= $discuz_secques= $discuz_uid這幾個變量的時候。包含自己的通行證,直接可以打通。
uchome在source/function_common.PHP這個function checkauth() 函數裡面直接切入就可以了。