专注ECSHOP第九年
始自2007,服务二千多商户,不断为您增光溢彩

DZ,ecshp整合UCenter首次注册同步登录激活

多程序整合 UCenter,在新用户首次注册后是没有同步登录到其它程序的,非得登陆以后才能同步登录,还有就是用户不是在 Discuz 程序注册的话,在 Discuz 登录时得手动激活,这些都导致用户体验很不好,解决方法很简单~
修改各个程序目录下的 ./uc_client/model/user.php 文件,大概在 129 行处的 function add_user 函数里添加代码
如 Discuz X 的:

$this->db->query("INSERT INTO `dbname`.pre_common_member SET uid='$uid', username='$username', password='$password', email='$email', adminid='0', groupid='10', regdate='".$this->base->time."', credits='0', timeoffset='9999'");
$this->db->query("INSERT INTO `dbname`.pre_common_member_status SET uid='$uid', regip='$regip', lastip='$regip', lastvisit='".$this->base->time."', lastactivity='".$this->base->time."', lastpost='0', lastsendmail='0'");
$this->db->query("INSERT INTO `dbname`.pre_common_member_profile SET uid='$uid'");
$this->db->query("INSERT INTO `dbname`.pre_common_member_field_forum SET uid='$uid'");
$this->db->query("INSERT INTO `dbname`.pre_common_member_field_home SET uid='$uid'");
$this->db->query("INSERT INTO `dbname`.pre_common_member_count SET uid='$uid', extcredits1='0', extcredits2='0', extcredits3='0', extcredits4='0', extcredits5='0', extcredits6='0', extcredits7='0', extcredits8='0'");

Discuz 的参数比较多(`dbname` 是数据库名,.pre_ 是表前缀)按自己的情况修改,注意需要在 MySQL 设置相应的权限。

这些代码的原理就是,在某应用注册用户时,同时添加其它应用的数据库字段,因为 UCenter 在首次注册时并没有这一步骤所以才没能同步登录与激活。

修改后完整的 function add_user 函数是这样的:

function add_user($username, $password, $email, $uid = 0, $questionid = '', $answer = '', $regip = '') {
	$regip = empty($regip) ? $this->base->onlineip : $regip;
	$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='$regip', regdate='".$this->base->time."', salt='$salt'");
	$uid = $this->db->insert_id();
	$this->db->query("INSERT INTO ".UC_DBTABLEPRE."memberfields SET uid='$uid'");
	// BEGIN
	$this->db->query("INSERT INTO `dbname`.pre_common_member SET uid='$uid', username='$username', password='$password', email='$email', adminid='0', groupid='10', regdate='".$this->base->time."', credits='0', timeoffset='9999'");
	$this->db->query("INSERT INTO `dbname`.pre_common_member_status SET uid='$uid', regip='$regip', lastip='$regip', lastvisit='".$this->base->time."', lastactivity='".$this->base->time."', lastpost='0', lastsendmail='0'");
	$this->db->query("INSERT INTO `dbname`.pre_common_member_profile SET uid='$uid'");
	$this->db->query("INSERT INTO `dbname`.pre_common_member_field_forum SET uid='$uid'");
	$this->db->query("INSERT INTO `dbname`.pre_common_member_field_home SET uid='$uid'");
	$this->db->query("INSERT INTO `dbname`.pre_common_member_count SET uid='$uid', extcredits1='0', extcredits2='0', extcredits3='0', extcredits4='0', extcredits5='0', extcredits6='0', extcredits7='0', extcredits8='0'");
	// END
	return $uid;
}

知道工作原理,其它的程序就比较简单了,下面提供几个参考:

// ecmall
$this->db->query("INSERT INTO `ecmall`.ecm_member SET user_id='$uid', user_name='$username', email='$email', password='$password', gender='0', reg_time='".$this->base->time."', last_login='".$this->base->time."', last_ip='$regip', logins='1', ugrade='0', outer_id='0'");

// ecshop
$this->db->query("INSERT INTO `ecshop`.ecs_users SET user_id='$uid', email='$email', user_name='$username', password='$password', reg_time='".$this->base->time."', last_login='".$this->base->time."', last_ip='$regip'");

// thinksns
$this->db->query("INSERT INTO `thinksns`.ts_ucenter_user_link SET uid='$uid', uc_uid='$uid', uc_username='$username'");
$this->db->query("INSERT INTO `thinksns`.ts_user SET uid='$uid', email='$email', password='$password', uname='$username', is_active='1', is_init='1'");
$this->db->query("INSERT INTO `thinksns`.ts_user_online SET uid='$uid', ctime='".$this->base->time."'");

BTW.(需要说明的是部分程序的登录机制不同使得此方法的首次注册同步登录无法实现)

赞(0) 打赏
未经允许不得转载:阿牛ECSHOP » DZ,ecshp整合UCenter首次注册同步登录激活
分享到: 更多 (0)
1

评论 抢沙发

阿牛ECSHOP 更专业 更方便

关于我们联系我们

觉得文章有用就打赏一下文章作者

支付宝扫一扫打赏

微信扫一扫打赏