Home >php教程 >php手册 >Discuz & UCenter 修改手记,discuz论坛

Discuz & UCenter 修改手记,discuz论坛

WBOY
WBOYOriginal
2016-06-13 09:18:381082browse

Discuz & UCenter 修改手记,discuz论坛

最近在整JAVA和UCENTER的东西,受限于项目架构需要,无法完全以UCENTER为中心,所以在对接过程中遇到了许多不愉快的事情。经历多番研究,终于解决了其中了两个大问题,现记录下来,以备日后查看。

一、解决email必须填写的问题

项目并不要求用户注册时填写email,但UCENTER API要求必须输入email才可以通过验证,不得已必须得修改UCENTER代码才能绕过。以下是改动的代码:

/uc_server/control/user.php 69行:

<span>1</span> <span>//</span><span> NOTE: 解决email必须填写的问题
</span><span>2</span> <span>//if(($status = $this->_check_email($email)) < 0) {
</span><span>3</span> <span>//    return $status;
</span><span>4</span> <span>//}</span>

 

二、解决用户必须手工登录1次论坛的问题

由于BBS屏蔽了DISCUZ自带的注册、登录、找密等操作,所以必须要实现单点登录。当中遇到了一个非常蛋疼的问题:主站注册的账户同步到UCENTER之后,UCENTER并不会通知其他应用,也就是说默认情况下,其他应用(包括DISCUZ在内)无法在新用户注册之后立即更新用户列表。细细研究之后发现,DISCUZ是在本地注册、登录等事件中才会与UCENTER同步。这导致了,在主站新注册的用户,无法在BBS单点登录成功——因为在BBS中根本不存在这个用户。解决的方法有两个,一是用户手工登录一次BBS,BBS自带的机制会自动将用户信息从UCENTER同步过来;二是修改DISCUZ系统代码,在单点登录请求时自动同步用户数据。在权衡了各方面因素之后,决定采用第二套方案。以下是改动的代码:

/api/uc.php 192行:

<span> 1</span> <span>//</span><span> NOTE 解决用户必须手工登录1次论坛的问题</span>
<span> 2</span> <span>$member</span> = getuserbyuid(<span>$uid</span>, 1<span>);
</span><span> 3</span> 
<span> 4</span> <span>if</span> (!<span>$member</span><span>) {
</span><span> 5</span>     <span>$init_arr</span> = <span>explode</span>(',', <span>$_G</span>['initcredits'<span>]);
</span><span> 6</span>     <span>$groupid</span> = <span>$_G</span>['regverify'] ? 8 : <span>$_G</span>['newusergroupid'<span>];
</span><span> 7</span> 
<span> 8</span>     C::t('common_member')->insert(<span>$uid</span>, <span>$get</span>['username'], <span>md5</span>(random(10)), <span>$get</span>['email'], <span>$_G</span>['clientip'], <span>$groupid</span>, <span>$init_arr</span><span>);
</span><span> 9</span> 
<span>10</span>     <span>$member</span> = getuserbyuid(<span>$uid</span>, 1<span>);
</span><span>11</span> <span>}
</span><span>12</span> 
<span>13</span> <span>if</span>(<span>$member</span><span>) {
</span><span>14</span>     dsetcookie('auth', authcode("<span>$member</span>[password]\t<span>$member</span>[uid]", 'ENCODE'), <span>$cookietime</span><span>);
</span><span>15</span> }

 

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn