[SOLVED] PART II - Definitely Yii isn't friendly with its Authentication feature

(my environment is: Apache/2.2.11 (Win32) DAV/2 mod_ssl/2.2.11 OpenSSL/0.9.8i mod_autoindex_color PHP/5.2.8 Yii Framework/1.0.3)

Second Scenario - I will try to do the Auth to be closely driven by a database.

-----------------------------------------------------------------------------

Step 1: main.php config file has

Quote

    ...

    'user'=>array(

                      'allowAutoLogin'=>FALSE, // disable cookie-based authentication

                        'class'=>'application.components.WebUser',

                    ),

    …

Step 2: LoginForm.php will undervalue the duration of cookie retained User data.

Quote

public function authenticate($attribute,$params)
{





	if(!$this->hasErrors())  // we only want to authenticate when no input errors





	{





		$identity=new UserIdentity($this->txtUsername,$this->txtPassword);





		$identity->authenticate();





		switch($identity->errorCode)





		{





			case UserIdentity::ERROR_NONE:





				$duration=0; // <span style='color: limeGreen'>&lt;&lt;&lt;&lt;=====</span>





				Yii::app()-&gt;user-&gt;login($identity,$duration);

                          …

Step 3: Injecting my User activerecord properties into the WebUser instance at login time

Quote

<?php

class WebUser extends CWebUser

{

public function login($identity,$duration=0) 





{





	parent::login($identity,$duration);





	if( ! empty($identity-&gt;id) ) 





	{





		$user = <span style='color: purple'>Usuario</span>::model()-&gt;findByAttributes( array(&#039;de_nick&#039;=&gt;&quot;{$identity-&gt;username}&quot;, &#039;de_senha&#039;=&gt;&quot;{$identity-&gt;password}&quot;) ); 





		if( ! is_null($user) ) 





		{





			// --------------------------------





			<span style='color: purple'>$propertiesUsuario</span> = array( &#039;id_usuario&#039;, &#039;de_senha&#039;, tp_status&#039;, &#039;de_codigo_ativacao&#039;, &#039;de_observacao&#039;, &#039;de_nick&#039;, &#039;dt_registro&#039;, &#039;dt_cancelamento&#039;, &#039;tp_pessoa&#039;, &#039;id_pessoa_fisica&#039;, &#039;de_config&#039;, &#039;id_perfil&#039;, 	&#039;arr_role&#039;, &#039;de_theme&#039; );				





			foreach( $propertiesUsuario as $k ) 





			{ 





				if( isset( $user-&gt;$k ) ) {





					Yii::App()-&gt;user-&gt;setState( $k, $user[$k] );





				}





			}





			Yii::App()-&gt;user-&gt;setState( &#039;guestName&#039;, $user&#91;&#039;de_nick&#039;] );





			Yii::App()-&gt;user-&gt;saveIdentityStates();





			// --------------------------------





		}





	}





}

}

?>

Step 4: The second great disappointment: Where are the customized properties?

At the end of actionIndex() method of SiteController I put: var_dump(Yii::App()->user);

Quote

(the result of var_dump( Yii::App()->user ) is:)

object(WebUser)#8 { ["allowAutoLogin"]=>  bool(false) ["guestName"]=>  string(5) "Guest" ["loginUrl"]=>  array(1) { [0]=>  string(10) "site/login" } ["_keyPrefix:private"]=>  string(32) "2cd4aca7d9b132f165c210e8cd55c2eb" ["behaviors"]=>  array(0) { } ["_initialized:private"]=>  bool(true) ["_e:private"]=>  NULL ["_m:private"]=>  NULL }

Is my property inject mechanism (1) correct ?

(1)----------------------

Yii::App()->user->setState( 'key', 'value' );

Yii::App()->user->saveIdentityStates();


MN

What is the problem?

Sory, I post the topic inadvertently before completing it.

I explained the problem only after you have asked, by modifying the topic.

MN

BINGO !!!

With My WebUser class slightly different:

Quote

<?php

class WebUser extends CWebUser

{

/* the same Usuario (my User) ActiveRecord (db table) properties	*/





public $id_usuario			= NULL;





public $de_senha			= NULL;





public $tp_status			= NULL;





public $de_codigo_ativacao	= NULL;





public $de_observacao		= NULL;





public $de_nick				= NULL;





public $dt_registro			= NULL;





public $dt_cancelamento		= NULL;





public $tp_pessoa			= NULL;





public $id_pessoa_fisica	= NULL;





public $de_config			= NULL; 





public $id_perfil			= NULL;





public $arr_role			= NULL;





public $de_theme 			= NULL;

// The big tip&trick !!!

public function init()

{





	parent::init();





	$propertiesUsuario = get_class_vars( &#039;WebUser&#039; );





	foreach( $propertiesUsuario as $k=&gt;$v ) 





		if(! is_array($v) ) $this-&gt;$k = $this-&gt;getState($k);





}</span>











public function login($identity,$duration=0) 





{





	parent::login($identity,$duration);











	if( ! empty($identity-&gt;id) ) 





	{





		$user = Usuario::model()-&gt;findByAttributes( array(&#039;de_nick&#039;=&gt;&quot;{$identity-&gt;username}&quot;, &#039;de_senha&#039;=&gt;&quot;{$identity-&gt;password}&quot;) ); 





		if( ! is_null($user) ) 





		{





			// Injects the same name Usuario (AR) properties





			$propertiesUsuario = get_class_vars( &#039;WebUser&#039; );





			foreach( $propertiesUsuario as $k=&gt;$v ) {





				if(! is_array($v) )&nbsp; 





					if( isset( $user-&gt;$k ) ) $this-&gt;setState( $k, $user[$k] );





			}





			$this-&gt;setState( &#039;guestName&#039;, $user&#91;&#039;de_nick&#039;] );





			$this-&gt;saveIdentityStates();





		}





	}





}

}

?>