Yii Framework Forum: Slowing Near Session And Auth Manager - Yii Framework Forum

Jump to content

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

Slowing Near Session And Auth Manager Rate Topic: -----

#1 User is offline   Actimele 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 3
  • Joined: 18-March 13

Posted 09 September 2013 - 08:18 PM

Hello, i have a trouble with slow loading page, problem between sessions and authManager step (look at trace).


WebUser.php
<?php
class WebUser extends CWebUser {
    private $_model = null;

    function getRole() {
        if($user = $this->getModel()){
            // в таблице User есть поле role
            return $user->role;
        }
    }

    private function getModel(){
        if (!$this->isGuest && $this->_model === null){
            $c = new CDbCriteria();
            $c->compare('id', $this->id);
            $model = User::model();
           // $model->detachBehaviors();
            $this->_model = $model->find($c);
        }
        return $this->_model;
    }
}

UserIdentity.php
<?php

/**
 * UserIdentity represents the data needed to identity a user.
 * It contains the authentication method that checks if the provided
 * data can identity the user.
 */
class UserIdentity extends CUserIdentity
{
    protected $_id;
	public function authenticate(){
        $user = User::model()->find('LOWER(login)=? AND verifyID is null', array(strtolower($this->username)));
        if(($user===null) || (crypt($this->password, $user->password)!==$user->password)) {
            $this->errorCode = self::ERROR_USERNAME_INVALID;
        } else {
            $this->_id = $user->id;
            $this->username = $user->login;
            $this->setState('last_login', $user->last_login);
            $this->errorCode = self::ERROR_NONE;
            $user->last_login = date('Y-m-d H:i:s');
            $user->save(false);
        }
        return !$this->errorCode;
    }

    public function getId(){
        return $this->_id;
    }
}

PhpAuthManager.php
<?php
class PhpAuthManager extends CPhpAuthManager{
    public function init(){
        if($this->authFile===null){
            $this->authFile=Yii::getPathOfAlias('application.config.auth').'.php';
        }

        parent::init();
        if(!Yii::app()->user->isGuest){
            try {
                $this->assign(Yii::app()->user->role, Yii::app()->user->id);
            } catch (CException $e){
                Yii::app()->user->logout();
            }
        }
    }
}

Primary controller class for all controllers, access part
public function filters()
    {
        return array(
            'accessControl',
        );
    }

    public function accessRules()
    {
        return array(
            array('allow',
                'controllers'=>array('site'),
                'roles'=>array('guest')
            ),
            array('allow',
                // 'controllers'=>array('site','user', 'order', 'package'),
                'roles'=>array('customer')

            ),
            array('deny',
                'message'=>'Access Denied.'
            ),
        );
    }

and last part, config.php
'authManager' => array(
            'class' => 'PhpAuthManager',
            'defaultRoles' => array('guest'),
            'showErrors' => YII_DEBUG
        ),


Total report (Time: 6.27636с, Memory: 3,904Кб)
Процедура 	Номер 	Всего (с) 	Средн. (с) 	Мин. (с) 	Макс. (с)
system.db.CDbCommand.query(SHOW FULL COLUMNS FROM `users`) 	1 	0.02400 	0.02400 	0.02400 	0.02400
system.db.CDbCommand.query(SELECT id, login, userFName, userLName FROM `users` `t`) 	1 	0.00100 	0.00100 	0.00100 	0.00100
system.db.CDbCommand.query(SHOW CREATE TABLE `users`) 	1 	0.00100 	0.00100 	0.00100 	0.00100
system.db.CDbCommand.query(SELECT * FROM `users` `t` WHERE id=:ycp0 LIMIT 1. Bound with :ycp0='15') 	1 	0.00100 	0.00100 	0.00100 	0.00100


03:08:06.270709 	trace 	system.CModule 	

Loading "session" application component
in C:\xampp\htdocs\protected\components\WebApplicationEndBehavior.php (32)
in C:\xampp\htdocs\admin.php (13)
in C:\xampp\htdocs\admin.php (13)

03:08:12.277051 	trace 	system.CModule 	

Loading "authManager" application component
in C:\xampp\htdocs\protected\components\WebApplicationEndBehavior.php (32)
in C:\xampp\htdocs\admin.php (13)
in C:\xampp\htdocs\admin.php (13)

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