Remember me

How to Work Remember me Function in Yii.

My Coding.

In Config/Main.php

‘user’=>array(

    // enable cookie-based authentication


    'allowAutoLogin'=>true,


),

UserIdentity.php

public function authenticate() {

$this->errorCode = self::ERROR_NONE;


$user = User::model()->find("username = :username or email=:username", array(":username" => $this->username));


if ($user === null) {


    $this->errorCode = self::ERROR_INCORRECT_CREDENTIAL;


} else {


    if($user->is_active != 1){


            if($user->activation_token_used == 0){


                $this->errorCode = self::ERROR_NOT_ACTIVATED;


            }


            else{


                $this->errorCode = self::ERROR_ACCOUNT_INACTIVE;


            }


    }


    else{


        $isCorrectPwd = ($user->password !== Yii::app()->mclass->encryptPwd($this->password)) ? false : true;


        if ($isCorrectPwd) {


            if($user->is_deleted == 1){


                $this->errorCode = self::ERROR_ACCOUNT_DELETED;


            }


            elseif($user->is_active != 1){


                if($user->activation_token_used == 0){


                    $this->errorCode = self::ERROR_NOT_ACTIVATED;


                }


                else{


                    $this->errorCode = self::ERROR_ACCOUNT_INACTIVE;


                }


            }


        } else {


            $this->errorCode = self::ERROR_INCORRECT_CREDENTIAL;


        }


    }


}


if ($this->errorCode == self::ERROR_NONE) {            


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


    $this->_isAdmin = ($user->user_type == Yii::app()->const->ADMIN_USER_TYPE) ? true : false;        


    $this->setState('user_type', $user->user_type);


    $this->setState('username', $user->username);


}


return !$this->errorCode;

}

Model Class

public function login() {

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


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


    $this->_identity->authenticate();


}


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


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


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


    return true;


}


else


    return false;

}

Whats Wrong in my code,Why Remember me not working.

And Also what is the difference between browser remember me and in that site remember me in yii.once i remember me checked and then login and also logout site.Again i run the login url mean both username and password are placed i am right?