Duplicated(?) code in LoginForm.php (Gii generated)

Hi all

Why do we create two same (?) UserIdentity’s and call their authenticate() method twice in LoginForm.php with

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


Visit: http://code.google.com/p/yii/source/browse/trunk/demos/blog/protected/models/LoginForm.php?r=1919 (lines 49/50 and 72/73)

For me it looks like I could remove lines 70-74 in login()… what am I missing?

Best regards


I still don’t get it… :(

In SiteController.php you have

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

which validates first with the authenticate() method from LoginForm.php and then calles login().

But I can’t see a way to get to lines 72/73. Not even with provoking validation errors like “Field must not be empty” etc.

public function login()


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



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


I am taking a guess here, but I suspect that part would be reached when automatically logging in (when a cookie is set and you are opening a new session). After all, when automatically logging in, you don’t have a login form to validate.

Hi jodev. Thank you for the insight, this must be it!