(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)
First Scenario - Following the instructions founded at Definitive Guide (http://www.yiiframework.com/doc/guide/topics.auth) and Yii CookBook (http://www.yiiframework.com/doc/cookbook/6/)
--------------------------------------------------------------------------
Step 1: main.php config file has
Quote
'user'=>array(
'allowAutoLogin'=>TRUE, // enable cookie-based authentication
),
…
Step 2: extending the CUserIdentity Yii class
Quote
class UserIdentity extends CUserIdentity
{
public $_id = NULL;
public function authenticate()
{
$senha = md5($this->password);
$user = Usuario::model()->findByAttributes( array('de_nick'=>"{$this->username}", 'de_senha'=>"{$senha}") );
if( $user===null ) {
$this->errorCode=self::ERROR_UNKNOWN_IDENTITY;
} else {
$this->_id = $user->id_usuario;
$this->password = $senha;
// customizing USER object !!!
$this->setState( 'tp_pessoa', $user['tp_pessoa'] );
$this->setState( 'guestName', $user['de_nick'] );
$this->errorCode=self::ERROR_NONE;
}
return !$this->errorCode;
}
public function getId()
{
return $this->_id;
}
}
?>
Step 3: Evaluating the Yii::App()->user has changed as expected, at SiteControler program (assuming the input of a valid login data).
Quote
{
// renders the view file 'protected/views/site: /index.php or /login.php'
// using the default layout 'protected/views/layouts: /mainLayout.php or /loginLayout.php'
if( Yii::App()->user->isGuest ) {
$this->layout = 'loginLayout';
$form = new LoginForm;
// collect user input data
if(isset($_POST['LoginForm']))
{
$form->attributes=$_POST['LoginForm'];
// validate user input and redirect to previous page if valid
if($form->validate())
$this->redirect(Yii::app()->user->returnUrl);
}
// display the login form
$this->render( 'login', array('form'=>$form) );
} else {
var_dump(Yii::App()->user); // (***)
die();
// display the main program
$this->layout = 'mainLayout';
$this->render('index');
}
}</div></div>
Step 4: The great disappointment: Where is the customization?
Quote
object(CWebUser)#8 { [“allowAutoLogin”]=> bool(true) [“guestName”]=> string(5) “Guest” [“loginUrl”]=> array(1) { [0]=> string(10) “site/login” } ["_keyPrefix:private"]=> string(32) “7f3668ab9970a2aec82f5148750368e0” [“behaviors”]=> array(0) { } ["_initialized:private"]=> bool(true) ["_e:private"]=> NULL ["_m:private"]=> NULL }
At next post I will expose the second scenario of desapointment.
TIA
MN