/**
  * perform the login action
  * @param CUserIdentity $identity
  * @param int $duration
  * @see CWebUser::login()
  */
 public function login($identity, $duration = 0)
 {
     $id = $identity->getId();
     $states = $identity->getPersistentStates();
     if ($this->beforeLogin($id, $states, false)) {
         $this->UGChangeIdentity($id, $identity->getName(), $identity->getGroup(), $identity->getGroupName(), $identity->getLevel(), $identity->getAccessRules(), $identity->getHome(), $identity->getRecovery(), $identity->getProfile(), $states);
         $this->profileLoad();
         if ($duration > 0) {
             if ($this->allowAutoLogin) {
                 $this->saveToCookie($duration);
             } else {
                 throw new CException(Yii::t('userGroupsModule.admin', '{class}.allowAutoLogin must be set true in order to use cookie-based authentication.', array('{class}' => get_class($this))));
             }
         }
         $this->afterLogin(false);
     }
 }