allowAutoLogin

Hi guys,

i transformed the blog login to my own login using the UserIdentity, but when the user succesfully logged in and he will return a little later to the site he will see the login page again instead of automatticly redirect to the correct page.

below the neccecary scripts:

config:




'user'=>array(

	'allowAutoLogin'=>true,

	'loginUrl'=>array('login/login'),

        'returnUrl'=>array('daytrip/list'),

),



model:




    public function authenticate($attribute, $params)

    {

        if(!$this->hasErrors())

        {

            $identity = new UserIdentity($this->Username, $this->Password);

            $identity->authenticate();

            switch($identity->errorCode)

            {

                case UserIdentity::ERROR_NONE:

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

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

                    break;

                case UserIdentity::ERROR_UNKNOWN_IDENTITY:

                    $this->addError('Account', 'Account disabled.');

                    break;

                case UserIdentity::ERROR_USERNAME_INVALID:

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

                    break;

                default: // UserIdentity::ERROR_PASSWORD_INVALID

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

                    break;

            }

        }

    }



controller:




    public function actionLogin()

    {

        $login = new Login;

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

        {

            $login->attributes = $_POST['Login'];

            if($login->validate())

                $this->redirect(array('daytrip/list'));

        }

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

    }



It’s a bug in the example code and yiic generated code too.

In models/loginForm.php, you need to add this to the array in the relations() function:


array('rememberMe','boolean'),

Yii 1.1 will refuse any variable that are not in the relations and which are given through something like this (see siteController.php):


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

Or, also if you don’t want to use the rememberMe checkbox, you can just modify the following line:


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

by


Yii::app()->user->login($identity, 3600*24*30);

.

Please report it using official project tracker: http://code.google.com/p/yii/issues/list

It is now submitted, see bug 724