Formulario de Login

Boa tarde pessoal,

Gostaria de tirar um duvida eu nao sei se ja aconteceu com alguem:

Tenho um formulario de login que te a opçao de lembre-me, so que quando ativa ele nao grava as informaçao no cookies pois toda vez que fecho o navegado e abro o aplicativo novamente ele pede o e-mail e a senha novamente. Nao sei se isso é do navegador ou do meu codigo:

Loginform




class LoginForm extends CFormModel

{

	public $email;

	public $password;

        public $rememberMe = false;

        private $_identity;


	/**

	 * Declares the validation rules.

	 * The rules state that username and password are required,

	 * and password needs to be authenticated.

	 */

public function rules()

{

	return array(

		array('email, password', 'required'),

		array('email', 'email'),

		array('password', 'authenticate'),

	);

}


	/**

	 * Declares attribute labels.

	 */

	public function attributeLabels()

	{

		return array(

			'email'=>'Email Address',

		);

	}


	/**

	 * Authenticates the password.

	 * This is the 'authenticate' validator as declared in rules().

	 */

	public function authenticate($attribute,$params)

	{

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

		{

			$identity=new UserIdentity($this->email,$this->password);

			$identity->authenticate();

			switch($identity->errorCode)

			{

				case UserIdentity::ERROR_NONE:

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

					break;

				case UserIdentity::ERROR_USERNAME_INVALID:

					$this->addError('email','Email address is incorrect.');

					break;

				default: // UserIdentity::ERROR_PASSWORD_INVALID

					$this->addError('password','Password is incorrect.');

					break;

			}

		}

	}

        

        public function login()

	{

		if($this->_identity===null)

		{

			$this->_identity=new UserIdentity($this->email,$this->password);

			$this->_identity->authenticate();

		}

		if($this->_identity->errorCode===UserIdentity::ERROR_NONE)

		{

                        $duration=(Yii::app()->user->allowAutoLogin && $this->rememberMe) ? 3600*24*30 : 0;

                         // log user in and save in session all appended data

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

		//	$duration=$this->rememberMe ? 3600*24*30 : 0; // 30 days

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

			return true;

		}

		else

			return false;

	}

}




UserIdentify




class UserIdentity extends CUserIdentity

{


	 // Need to store the user's ID:

	 private $_id;




	/**

	 * Authenticates a user.

	 * The example implementation makes sure if the username and password

	 * are both 'demo'.

	 * In practical applications, this should be changed to authenticate

	 * against some persistent user identity storage (e.g. database).

	 * @return boolean whether authentication succeeds.

	 */

	public function authenticate()

	{

		$user = Usuario::model()->findByAttributes(array('email'=>$this->username));


		if ($user===null) { // No user found!

			$this->errorCode=self::ERROR_USERNAME_INVALID;

		} else if ($user->password !== md5($this->password) ) { // Invalid password!

			$this->errorCode=self::ERROR_PASSWORD_INVALID;

		} else { // Okay!

		    $this->errorCode=self::ERROR_NONE;

		    // Store the role in a session:

		    $this->setState('role', $user->perfil);

			$this->_id = $user->id;

		}

		return !$this->errorCode;

	}

	

	public function getId()

	{

	 return $this->_id;

	}


	

}

[code]


Login



<div class="form" id="login">

<br />

<?php $form=$this->beginWidget(‘CActiveForm’, array(

'id'=&gt;'login-form',


'enableAjaxValidation'=&gt;true,


    'clientOptions'=&gt;array(


	'validateOnSubmit'=&gt;true,


),

)); ?>

&lt;?php echo &#036;form-&gt;errorSummary(&#036;model); ?&gt;


&lt;div class=&quot;row&quot;&gt;


	&lt;?php echo &#036;form-&gt;labelEx(&#036;model,'E-mail'); ?&gt;


	&lt;?php echo &#036;form-&gt;textField(&#036;model,'email',array('class'=&gt;'text ui-widget-content ui-corner-all','size'=&gt;'30')); ?&gt;


	&lt;?php // echo &#036;form-&gt;error(&#036;model,'username'); ?&gt;


&lt;/div&gt;





&lt;div class=&quot;row&quot;&gt;


	&lt;?php echo &#036;form-&gt;labelEx(&#036;model,'password'); ?&gt;


	&lt;?php echo &#036;form-&gt;passwordField(&#036;model,'password', array('class'=&gt;'text ui-widget-content ui-corner-all', 'size'=&gt;'30')); ?&gt;


	&lt;?php //  echo &#036;form-&gt;error(&#036;model,'password'); ?&gt;


&lt;/div&gt;





&lt;div class=&quot;row rememberMe&quot;&gt;


	&lt;?php echo &#036;form-&gt;checkBox(&#036;model,'rememberMe'); ?&gt;


	&lt;?php echo &#036;form-&gt;label(&#036;model,'rememberMe'); ?&gt;


	&lt;?php //  echo &#036;form-&gt;error(&#036;model,'rememberMe'); ?&gt;


&lt;/div&gt;





&lt;div class=&quot;row submit&quot;&gt;


	&lt;?php echo CHtml::submitButton('Entrar');  ?&gt;


&lt;/div&gt;

<?php $this->endWidget(); ?>

</div><!-- form -->

[/code]

LoginController




class LoginController extends Controller

{

        public $layout='login';

        

	public function actionLogin()

	{

		$model=new LoginForm;

                

		if(isset($_POST['ajax']) && $_POST['ajax']==='login-form')

		{

			echo CActiveForm::validate($model);

			Yii::app()->end();

		}


	

		if(isset($_POST['LoginForm']))

		{

			$model->attributes=$_POST['LoginForm'];

		        if($model->validate() && $model->login())

				$this->redirect('home');

		}else{

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

                            $this->redirect('home');

                    }

                }

                

		               

		$this->render('login',array('model'=>$model));

	}


	

	public function actionLogout()

	{

		Yii::app()->user->logout();

		$this->redirect(Yii::app()->homeUrl);

	}

     




}



Se alguem poder me ajudar agradeço…

Valew

Vê se seu navegador não ta configurado pra limpar os cookies assim que fechar.

valew

Edson, consegui resolver o problema?

Não lembro se usei o "lembra-me" alguma vez, só que dessa vez ele insere a duração na sessão/cookie, mais fecho o browser já era!

Não é problema no browser, por que no próprio fórum do Yii, eu fico logado por dias.