本帖最后由 viqecel 于 2013-7-23 17:59 编辑
一,功能简介.本认证库由tank_auth修改精简.他不一定是你需要的,但里面的整合思路,可以一起探讨. 1,user用户表分离出三个表,目的是减轻user表的重量.登录日志等频繁写入的内容放在admin_log表中,普通会员不再保存登录日志. user_activation为邮箱激活验证表,手机认证等也可以放在里面,user_count为会员统计表,本表频繁写入,所以要才考虑单独存放.比如文章数.帖子数.粉丝数,积分,勋章数,喜欢次数等. 2,session可以选择入库或直接用HEX发布的php原生认证库.默认用的是这个.http://codeigniter.org.cn/forums/thread-4007-1-1.html,但是,如果会员从uc其它应用同步登录或注册到ci应用时,即在api/uc.php中,用session入库的方式,好像不好实现.等待热心网友的完善.(因为ci的session入库是自动写入的.而在api.uc.php中,好像不方便调用session类.) 3,密码加密库Phpass升级到了0.3最新版. 4,原来的user表中有一个activated字段,表示该会员是否被激活,现在把他合并到usergroup中了,即如果会员没激活,就把用户组设置为9,即未激活用户组. 5,普通会员与管理员共享user表,管理组的varname中必须包含admin关键字.用于区分.普通会员默认包含7个会员组,包含新手上路,初级会员等. 6,实现ci与uc1.6的完美整合,双向注册与登录,比如从ci注册会员后,uc整合的其它论坛用户自动同步登录,不必再去bbs上填上用户名去手工激活.论坛上登录的会员,可以同步注册到ci并登录.(论坛上注册,无法同步注册到ci,因为没这个接口) 7,这里提供一个api/uc.php调试方法.http://www.feihuayuan.com/index.php/191 8,注意,config.php中的.$config['log_threshold'] = 1; 这里设置为1,可以记录错误日志到logs/目录中.方便调试. 9,tank有自动登录功能.即根据cookie,自动到数据库的自动登录表(user_autologin)中,验证用户id,登录ip等,但因为自动登录时.客户并没有手工输入原始密码.所以没法进uc验证密码是否正确.所以没法同步uc. 10,如果论坛与ci的编码不同,可能要转码. 11,ci注册会员后,默认情况下.要去bbs上登录一次.才能激活,同步成功.如果你想自动激活.要修改uc_client\model\user.php文件.把add_user函数修改为下面的,dz3为数据库名,
PHP复制代码 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’” );
//开始激活
$this->db->query(“INSERT INTO `dz3` .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 `dz3` .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 `dz3` .pre_common_member_profile SET uid =’ $uid’” );
$this->db->query(“INSERT INTO `dz3` .pre_common_member_field_forum SET uid =’ $uid’” );
$this->db->query(“INSERT INTO `dz3` .pre_common_member_field_home SET uid =’ $uid’” );
$this->db->query(“INSERT INTO `dz3` .pre_common_member_count SET uid =’ $uid’ , extcredits1 =’ 0′ , extcredits2 =’ 0′ , extcredits3 =’ 0′ , extcredits4 =’ 0′ , extcredits5 =’ 0′ , extcredits6 =’ 0′ , extcredits7 =’ 0′ , extcredits8 =’ 0′” );
return $uid;
} 复制代码
11,如果要实现从uc.php向ci中同步注册,需要修改一个地方.
PHP复制代码 \uc_server\control\user .php要修改本文件的onsynlogin (),里面增加email参数 .这时 ,就可以在api /uc .php中get 到email了 ,如果不修改 .那不方便同步注册
‘ &email =’ .$this->user['email']
即修改后
// -1 未开启
function onsynlogin () {
$this->init_input();
$uid = $this->input(‘uid’ );
if($this->app['synlogin']) {
if($this->user = $_ENV['user']->get_user_by_uid($uid)) {
$synstr = ” ;
foreach($this->cache['apps'] as $appid => $app) {
if($app['synlogin']) {
$synstr .= ‘ <script type =”text /javascript” src =”‘ .$app['url'].’ /api /’ .$app['apifilename'].’? time=’ .$this->time.’ &code =’ .urlencode($this->authcode(‘action =synlogin &username =’ .$this->user['username'].’ &uid =’ .$this->user['uid'].’ &email =’ .$this->user['email'].’ &password =’ .$this->user['password'].” &time=” .$this->time,
‘ENCODE’ ,
$app['authkey'])).’” reload =” 1″ ></script>’ ;
if(is_array($app['extra']['extraurl'])) foreach($app['extra']['extraurl'] as $extraurl) {
$synstr .= ‘ <script type =”text /javascript” src =”‘ .$extraurl.’ /api /’ .$app['apifilename'].’? time=’ .$this->time.’ &code =’ .urlencode($this->authcode(‘action =synlogin &username =’ .$this->user['username'].’ &uid =’ .$this->user['uid'].’ &email =’ .$this->user['email'].’ &password =’ .$this->user['password'].” &time=” .$this->time, ‘ENCODE’ , $app['authkey'])).’” reload =” 1″ ></script>’ ;
}
}
}
return $synstr;
}
}
return ” ;
} 复制代码
=================== 二,但里面有些疑问,期待解答 1,注册成功后,如果需要发送激活邮箱,如果邮箱不正确,可能会等待几十秒时间,才成功跳转,其实早已注册成功.这里不知怎么优化.比如能不能先跳转成功.再发送邮箱.或延迟一段再发送激活信. 2,从ci登录成功并跳转时,如果用redirect(”);即header()跳转时.好像没法成功登录uc下的其它论坛.用js跳转才行.不知原因为何.难道是header()之前有输出?好像用ob_start();也什么变化. 三,安装说明 1,先登录ucenter管理中心.增加应用.然后最下面得到配置内容.复制下来.放到application\config\uc.php中.注意UC_DBTABLEPRE这个参数值前面最好加上数据库名. 2,还要按上面10到11条说明.修改下文件. 3,api/目录中,还整合了这个数据库连接类.方法在uc.php中可以操作ci的数据库.具体可以了解下.http://codeigniter.org.cn/forums/thread-10447-1-1.html 4,schema.sql这个在根目录中.sql文件.注意进数据库.运行下.建表. 如果能用uc原生的数据库连接当然好.但好像不方便吧? 5,注意配置application/config目录中的auth.php,config.php,database.php 因为本整合没用到session数据库保存方式.所以config.php中$config['sess_use_database'] = FALSE;这里设置为false 点击下载,下载包中包含uc相关文件.及一个user控制器.user_model和一个libraries/auth类. 你需要安装一个discuz3.0及ci 2.1.3新版. 安装即可
tank_auth_ucenter.rar
(265.13 KB, 下载次数: 80)
|