Yii::app()->user->login($this->_identity, $duration) failed

hi,

im creating a login form and i check if im logged in using


if (Yii::app()->user->isGuest) {

    echo "is NOT login";

}

i’ve set Yii::app()->user->login($this->_identity, $duration) but still im not login.

i did this and it keeps return false;


if (Yii::app()->user->login($this->_identity, $duration)) {

				echo "SET SUCCESS";

			} else {

				echo "SET FAILED";

			}

any idea?

CWebUser->login() does not return anything at all and this




Yii::app()->user->login($this->_identity, $duration)



will allways return null. Can you show your $_SESSION array or Yii::app()->user?

hi below is the content of Yii::app()->user and $_SESSION:


Yii::app()->user

CWebUser Object

(

    [allowAutoLogin] => 1

    [guestName] => Guest

    [loginUrl] => Array

        (

            [0] => /site/login

        )


    [identityCookie] => 

    [autoRenewCookie] => 

    [_keyPrefix:CWebUser:private] => c7942a53a43de02add1de71b9ccff745

    [_access:CWebUser:private] => Array

        (

        )


    [behaviors] => Array

        (

        )


    [_initialized:CApplicationComponent:private] => 1

    [_e:CComponent:private] => 

    [_m:CComponent:private] => 

)


session

Array

(

    [c7942a53a43de02add1de71b9ccff745__name] => admin@email.com

    [c7942a53a43de02add1de71b9ccff745__states] => Array

        (

            [title] => 1

            [role] => 1

        )


    [c7942a53a43de02add1de71b9ccff745title] => Admin

    [c7942a53a43de02add1de71b9ccff745role] => user

)

but why is isGuest always true??

I added the accessRule and filter:




public function filters() {

		return array(

			'accessControl', // perform access control for CRUD operations

		);

	}

return array(

			array('deny',  // deny all unknown users

						'actions'=>array('home', 'index'),

						'users'=>array('?'),

			),

		);

after login in, i cannot access actionHome. so that means there is a problem with my login right?

OK, what you have in $this->_identity? And what return $this->_identity->getId()?

after login, $this->_identity has the following:


UserIdentity Object ( [_id:UserIdentity:private] => [username] => admin@email.com [password] => password123 [errorCode] => 100 [errorMessage] => [_state:CBaseUserIdentity:private] => Array ( ) [_e:CComponent:private] => [_m:CComponent:private] => )

for $this->_identity->getId(), i get the error when i echo $this->_identity->getId(). the error is Property "SiteController._identity" is not defined.

Property UserIdentity::__id must be not empty. You can specify this property in UserIdentity class before logging in.

hey silnov, tks now it works. i owe u one =)

well the problem was that i’ve set $this->_id = $record->id in UserIdentity;

But $record->id was protected so that’s why it was assigned to $this->_id;

well i’ve created a public function to return ID.

btw, i’ve added the following filters and accessRule for login users to access Home page but it didnt work.


public function filters() {

		return array(

			'accessControl', // perform access control for CRUD operations

		);

	}


public function accessRules()

	{

		return array(

		array('allow',

				'actions'=>array('home'),

				'users'=>array('@'),

		),

		);

	}

did i go wrong somewhere?