PHP教程:修改discuz兼容自己开发的通行证
http://www.itjxue.com 2015-07-17 08:18 来源:未知 点击次数:
修改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() 函数里面直接切入就可以了。