嗯,我在我的應用程序中實現CAS登錄.. 問題是,在CasLogin()
函數..登錄獲取成功,所有會話變量設置.. 和Yii::app()->user->isGuest
,返回false。即正確登錄。 和Yii::app()->user->id
,返回登錄ID
。Yii :: app() - > user-> isGuest在重定向後返回true。
尚未...當我從這裏重定向到我的索引操作時,Yii::app()->user->isGuest
返回true。和Yii::app()->user->id
,返回NULL。
其實我做過一個實驗$ _session包含CasLogin()所有的值,但重定向後,它重定向
casUserIdentity
延伸CUserIdentity
,它的構造我是在具有NULL因此會議被摧毀...調用CasLoginForm()
的登錄函數;
順便說一句,LocalLoginIdentity
作品就好了... ...這些值不復位有.. 雖然我發送,用戶名和密碼LocalUserIdentity
構造..
下面是代碼按順序.. 公共職能的actionIndex () { echo「hello at index」;
if (! Yii::app()->user->isGuest) {
//#CASE 1: User is already logged in
$this->redirect(array("site/upload"));
}
else{
//#CASE 2: User is not Logged in
echo '<br>Always show up, and id NULL <br>';
var_dump(Yii::app()->user->id);
exit;
$this->redirect(array("site/login"));
}
}
這裏是CasLoginFunction()
的代碼:
public function actionCasLogin($CID=NULL)
{
//code to be imported from GMS here
PhpCasControl::setPhpCasContext($CID);
phpCAS::setPostAuthenticateCallback(array($this,'_saveServiceTkt'));
$loginForm = new CasLoginForm;
// validate user input and redirect to the previous page if valid
if ($loginForm->login($CID)) {
if (Yii::app()->user->isGuest){
echo 'this always show up, if at this controller only';
var_dump(Yii::app()->user->id);}
else{
echo 'it never showed up';
var_dump(Yii::app()->user->id);}
$this->redirect(array('index'));
}
else {
throw new Exception("You don't have sufficient permissions to access this service. Please contact Administrator !");
}
}
以下是其中i調用CasUserIdentity代碼() 類CasLoginForm延伸CFormModel {
private $_identity; //User identity
/**
* Logs in the user using the cas forceAuthentication method
* @return boolean whether login is successful
*/
public function login($cname=NULL) {
if ($this->_identity === null) {
$this->_identity = new CasUserIdentity('', NULL);
$this->_identity->authenticate($cname);
var_dump($this->_identity);
}
if ($this->_identity->errorCode === UserIdentity::ERROR_NONE) {
$duration = 0; // 0 days
Yii::app()->user->login($this->_identity, $duration);
//get service tkt from session
$serviceTkt = Yii::app()->user->getState('service_tkt');
$this->rename_session($serviceTkt);
//echo "<br> current_session <br><br>".$serviceTkt."<br>";
//var_dump($_SESSION);
return true;
}
else
//echo "hies";
return false;
}
此函數返回真..所以不用擔心,關於CAS
的其他詳情
什麼是你的用戶類的屬性的allowAutoLogin的價值? –
@AndreyMischenko:它完全設置爲TRUE – Himanshu97