Yii Framework Forum: allowAutoLogin - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

allowAutoLogin not redirecting automaticlay Rate Topic: ****- 1 Votes

#1 User is offline   bas_vdl 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 215
  • Joined: 01-April 09

Posted 02 December 2009 - 05:14 AM

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));
    }

0

#2 User is offline   Weboide 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 4
  • Joined: 11-December 09

Posted 11 December 2009 - 10:42 PM

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);

0

#3 User is offline   Weboide 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 4
  • Joined: 11-December 09

Posted 11 December 2009 - 10:48 PM

.
0

#4 User is online   samdark 

  • Having fun
  • Yii
  • Group: Yii Dev Team
  • Posts: 3,786
  • Joined: 17-January 09
  • Location:Russia

Posted 12 December 2009 - 04:30 AM

Please report it using official project tracker: http://code.google.c...yii/issues/list
Yii 1.1 Application Development Cookbook

Enjoying Yii? Star us at github: 1.1 and 2.0.
0

#5 User is offline   Weboide 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 4
  • Joined: 11-December 09

Posted 12 December 2009 - 09:13 AM

It is now submitted, see bug 724
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users