php 模拟 cas,PHP discuz3.2 cas

0818b9ca8b590ca3270a3433284dd417.png

先将CAS PHP版支持包引入,然后进入下面环节。下载地址http://developer.jasig.org/cas-clients/php/1.3.4/CAS-1.3.4.tgz 1.去除登录输入

upload\template\default\member\login-simple.html

删除8-29行代码,删除31-32行代码

2.去除弹框登录

upload/admin.php-=》界面-》去掉浮动窗口(登录)

3.在CAS文件夹中创建CasClientConfig.php

define ( 'CAS_SERVER_HOSTNAME', '192.168.32.7' );

define ( 'CAS_SERVER_PORT', 8080 );

define ( 'CAS_SERVER_APP_NAME', "cas_server" );

?>

4.在CAS文件中创建CasClient.php

require_once DISCUZ_ROOT.'./CAS/CasClientConfig.php'; // 注意

require_once DISCUZ_ROOT.'./CAS.php'; // 注意

// 初始化

//phpCAS::setDebug ();

// initialize phpCAS

phpCAS::client ( CAS_VERSION_2_0, CAS_SERVER_HOSTNAME, CAS_SERVER_PORT, CAS_SERVER_APP_NAME );

// no SSL validation for the CAS server

phpCAS::setNoCasServerValidation ();

?>

5.source/class/class_core.php第16行加入

require_once DISCUZ_ROOT."Cas/CasClient.php";

6.uc_client/control/user.php

134行注释

//elseif($user['password'] != md5($passwordmd5.$user['salt'])) {

//$status = -2;

//} elseif($checkques && $user['secques'] != $_ENV['user']->quescrypt($questionid, $answer)) {

//$status = -3;

//}

注释 onsynlogin、onsynlogout、onregister方法

7.source/function/member.php加入

// 新加的方法,用以支持CAS 登录

function userloginCas($username, $ip = '') {

$return = array ();

if(!function_exists('uc_user_login')) {

loaducenter();

}

$return['ucresult'] = uc_user_login(addslashes($username), '', 0, 0,'', '', $ip);

$tmp = array ();

$duplicate = '';

list ( $tmp ['uid'], $tmp ['username'], $tmp ['password'], $tmp ['email'], $duplicate ) = $return ['ucresult'];

$return ['ucresult'] = $tmp;

if ($duplicate && $return ['ucresult'] ['uid'] > 0 || $return ['ucresult'] ['uid'] <= 0) {

$return ['status'] = 0;

return $return;

}

$member = getuserbyuid ( $return ['ucresult'] ['uid'], 1 );

if (! $member || empty ( $member ['uid'] )) {

$return ['status'] = - 1;

return $return;

}

$return ['member'] = $member;

$return ['status'] = 1;

if ($member ['_inarchive']) {

C::t ( 'common_member_archive' )->move_to_master ( $member ['uid'] );

}

if ($member ['email'] != $return ['ucresult'] ['email']) {

C::t ( 'common_member' )->update ( $return ['ucresult'] ['uid'], array (

'email' => $return ['ucresult'] ['email']

) );

}

return $return;

}

8.source/class/class_member.php

51行注释并改为

//if(!submitcheck('loginsubmit', 1, $seccodestatus)) {

if (1 == 2) {

92行 $_G['username'] = $_G['member']['username'] = $_G['member']['password'] = '';后加入

phpCAS::setNoClearTicketsFromUrl ();

//这里会检测服务器端的退出的通知,就能实现php和其他语言平台间同步登出了

phpCAS::handleLogoutRequests();

$username='';

if(phpCAS::isAuthenticated()){

$username = phpCAS::getUser ();

} else {

phpCAS::forceAuthentication ();

}

//if(!$_GET['password'] || $_GET['password'] != addslashes($_GET['password'])) {

//showmessage('profile_passwd_illegal');

//}

//$result = userlogin($_GET['username'], $_GET['password'], $_GET['questionid'], $_GET['answer'], $this->setting['autoidselect'] ? 'auto' : $_GET['loginfield'], $_G['clientip']);

$result = userloginCas($username, $_G['clientip']);

347行 on_logout方法

if(defined('IN_MOBILE')) {

showmessage('location_logout_succeed_mobile', dreferer(), array('formhash' => FORMHASH, 'referer' => rawurlencode(dreferer())));

} else {

$service =  dreferer ()  ;

phpCAS::logoutWithRedirectService ( $service );

//showmessage('logout_succeed', dreferer(), array('formhash' => FORMHASH, 'ucsynlogout' => $ucsynlogout, 'referer' => rawurlencode(dreferer())));

}

386行 on_register方法中

if(strpos($url_forward, $this->setting['regname']) !== false) {

$url_forward = 'forum.php';

}

修改掉防止当登录成功时无限跳转

$url_forward = 'forum.php';

去除https CAS\Client.php

$this->_server['base_url'] = 'https://' . $this->_getServerHostname();

改为

$this->_server['base_url'] = 'http://' . $this->_getServerHostname();

关闭gateway CAS\Client.php

$this->redirectToCas(true/* gateway */);

改为

$this->redirectToCas(false/* gateway */);

待续(缺少PHP监听CAS cookie中的账号phpCAS:checkAuthentication() 不存在就清理session完毕)

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值