Can't login with CUserIdentify

Hi

I tried make an authentification just with the User ID:


<?php


class UserIdentity extends CUserIdentity

{

	public $id;

	public $name;

	public $user;


	public function __construct ( $user_id )

	{

		

		$this->id = $user_id;


	}


	public function authenticate ( )

	{

		$user=User::model()->find('user_id=?',array( $this->id ));


		if($user===null)

		{

			$this->errorCode=self::ERROR_USERNAME_INVALID;

			$this->id = null;

		}


		else

		{


			$this->user = $user->user_nickname;

			$this->name = $user->user_real_name;


			$this->errorCode=self::ERROR_NONE;


		}


		return $this->errorCode==self::ERROR_NONE;

	}




}

This is my authentification:


			$identity = new UserIdentity ( $user_id ) ;


			if($identity->authenticate())

			{

				Yii::app()->user->login($identity);

				return true;

			}

			else

				return false;



It seems to work - there is no exception thrown and the result was true.

Now, when i check if the user is logged in ([font="Courier New"]Yii::app()->user->isGuest[/font]) - the result is true. And my variables (like [font="Courier New"]Yii::app()->user->user[/font]) are not set.

Can someone please help me?

Thank you very much.

Try replacing


$user=User::model()->find('user_id = ?',array($this->id));

with


$user=User::model()->find('user_id =:userid ',array(':userid'=>$this->id));

This isn’t the fault. The authenticate() hasn’t an error, it has to be something other… :confused:

I found, that $this->_identity is empty:


public function actionIndex()

	{

		var_dump( $this->_identity );

		// renders the view file 'protected/views/site/index.php'

		// using the default layout 'protected/views/layouts/main.php'

		$this->render('index');

	}

result: Property "SiteController._identity" is not defined.

But I create put the identity in the login-method :-/