Olá Brodis,
Estou com um problema na minha autenticação… o caso é que est funcionando tudo certinho o problema é que esta lento para autenticar.
Quando faço login demora em torno de 5 a 10 segundos… estou testando local.
O que pode ser que esta dando este gargalo.
Alguém já teve este problema?
loginform
<?php
/**
* LoginForm class.
* LoginForm is the data structure for keeping
* user login form data. It is used by the 'login' action of 'SiteController'.
*/
class LoginForm extends CFormModel
{
public $email;
public $password;
public $rememberMe;
private $_identity;
/**
* Declares the validation rules.
* The rules state that username and password are required,
* and password needs to be authenticated.
*/
public function rules()
{
return array(
array('email, password', 'required'),
array('email', 'email'),
array('password', 'authenticate'),
array('rememberMe', 'boolean'),
);
}
/**
* Declares attribute labels.
*/
public function attributeLabels()
{
return array(
'email'=>'E-mail',
'password'=>'Senha',
);
}
public function checkEnabled($attribute,$params)
{
if(!$this->$attribute == $params['enabledValue'])
{
$this->addError('username','E-mail bloqueado ou Inválido');
}
}
/**
* Authenticates the password.
* This is the 'authenticate' validator as declared in rules().
*/
public function authenticate($attribute,$params)
{
if(!$this->hasErrors()) // we only want to authenticate when no input errors
{
$identity=new UserIdentity($this->email,$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_USERNAME_INVALID:
$this->addError('email','E-mail Inválido');
break;
case UserIdentity::ERROR_PASSWORD_INVALID:
$this->addError('password','Senha Inválida');
break;
case UserIdentity::ERROR_PASSWORD_STATUS:
$this->addError('password','Usuário Bloquedo pelo Administrador');
break;
default: // UserIdentity::ERROR_PASSWORD_INVALID
$this->addError('password','Senha Inválida');
break;
}
}
}
public function login()
{
if($this->_identity===null)
{
$this->_identity=new UserIdentity($this->email,$this->password);
$this->_identity->authenticate();
}
if($this->_identity->errorCode===UserIdentity::ERROR_NONE)
{
$duration=(Yii::app()->user->allowAutoLogin && $this->rememberMe) ? 3600*24*30 : 0;
// log user in and save in session all appended data
Yii::app()->user->login($this->_identity,$duration);
// $duration=$this->rememberMe ? 3600*24*30 : 0; // 30 days
// Yii::app()->user->login($this->_identity,$duration);
return true;
}
else
return false;
}
}
useridentify
<?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
{
// Need to store the user's ID:
private $_id;
/**
* Authenticates a user.
* The example implementation makes sure if the username and password
* are both 'demo'.
* In practical applications, this should be changed to authenticate
* against some persistent user identity storage (e.g. database).
* @return boolean whether authentication succeeds.
*/
public function authenticate()
{
$user = Usuario::model()->findByAttributes(array('email'=>$this->username));
if ($user===null)
$this->errorCode=self::ERROR_USERNAME_INVALID;
else if ($user->password !== md5($this->password) )
$this->errorCode=self::ERROR_PASSWORD_INVALID;
else if($user->status==0)
$this->errorCode=self::ERROR_PASSWORD_STATUS;
else {
$this->errorCode=self::ERROR_NONE;
// Store the role in a session:
$this->setState('nivel', $user->nivel);
$this->setState('nome', $user->nome);
$this->_id = $user->id;
$_SESSION['logado'] = true;
}
return !$this->errorCode;
}
public function getId()
{
return $this->_id;
}
}
main
<?php
$backend=dirname(dirname(__FILE__));
$frontend=dirname($backend);
Yii::setPathOfAlias('backend', $backend);
$frontendArray=require($frontend.'/config/main.php');
Yii::setPathOfAlias('bootstrap', dirname(__FILE__).'/../extensions/bootstrap');
// This is the main Web application backend configuration. Any writable
// CWebApplication properties can be configured here.
$backendArray=array(
'basePath' => $frontend,
'language'=>'pt_br',
'name'=>'Sistema Administrativo - EProdesq',
'controllerPath' => $backend.'/controllers',
'viewPath' => $backend.'/views',
'runtimePath' => $backend.'/runtime',
'preload'=>array('log','bootstrap'),
// autoloading model and component classes
'import'=>array(
'backend.models.*',
'backend.components.*',
'backend.CA_Framework.*',
'application.models.*',
'application.components.*',
'application.extensions.*',
),
'aliases' => array(
'xupload' => 'backend.extensions.xupload',
),
'modules'=>array(
'gii'=>array(
// 'class'=>'backend.extensions.gii-sisadm.GiiModule',
'password'=>'a12b25',
'generatorPaths'=>array(
'bootstrap.gii'
// 'application.backend.extensions.bootstrap.gii', // since 0.9.1
),
),
),
// main is the default layout
'layout'=>'main',
// alternate layoutPath
'layoutPath'=>dirname(dirname(__FILE__)).DIRECTORY_SEPARATOR.'views'.DIRECTORY_SEPARATOR.'layouts'.DIRECTORY_SEPARATOR,
// application-level parameters that can be accessed
// using Yii::app()->params['paramName'] and MParams class
'params'=>require(dirname(__FILE__).'/parametros.php'),
// application components
'homeUrl'=>array('home/index'),
'components'=>array(
'image'=>array(
'class'=>'application.backend.extensions.image.CImageComponent',
// GD or Imagick
'driver'=>'GD',
),
'clientScript'=>array(
'coreScriptPosition' => CClientScript::POS_HEAD,
'scriptMap' => array(
'jquery.js'=>false, //disable default implementation of jquery
'jquery.min.js'=>false, //desable any others default implementation
'core.css'=>false, //disable
'styles.css'=>false, //disable
'pager.css'=>false, //disable
'default.css'=>false, //disable
'jquery.ba-bbq.js'=>false,
'jquery.yiiactiveform.js'=>false,
)
),
'user'=>array(
'class' => 'WebUser',
'allowAutoLogin'=>true,
'loginUrl'=>array('/sisadm/'),
'stateKeyPrefix' => 'd18e09c74efe6c1b55e135',
),
'bootstrap'=>array(
'class'=>'backend.extensions.bootstrap.components.Bootstrap', // assuming you extracted bootstrap under extensions
'plugins'=>array(
// Optionally you can configure the "global" plugins (button, popover, tooltip and transition)
// To prevent a plugin from being loaded set it to false as demonstrated below
'transition'=>true, // disable CSS transitions
'popover'=>array(
'selector'=>'.dica, img[rel="popover"]',
'options'=>array(
'placement'=>'bottom'
),
),
'tooltip'=>array(
'selector'=>'a[rel="tooltip"],img[rel="tooltip"]', // bind the plugin tooltip to anchor tags with the 'tooltip' class
'options'=>array(
'placement'=>'top', // place the tooltips below instead
),
),
// If you need help with configuring the plugins, please refer to Bootstrap's own documentation:
// http://twitter.github.com/bootstrap/javascript.html
),
),
'urlManager'=>array(
'urlSuffix'=> '',
'showScriptName'=>false,
'caseSensitive'=>false,
'rules'=>require(dirname(__FILE__).'/rotas.php'),
),
'log'=>array(
'class'=>'CLogRouter',
'routes'=>array(
array(
'class'=>'CFileLogRoute',
'levels'=>'trace, info',
'categories'=>'system.*'
),
// array(
// 'class'=>'CEmailLogRoute',
// 'levels'=>'error, warning',
// 'emails'=>'suporte@setequatro.com.br',
// ),
),
),
),
);
if(!function_exists('w3_array_union_recursive'))
{
/**
* This function does similar work to $array1+$array2,
* except that this union is applied recursively.
* @param array $array1 - more important array
* @param array $array2 - values of this array get overwritten
* @return array
*/
function w3_array_union_recursive($array1,$array2)
{
$retval=$array1+$array2;
foreach($array1 as $key=>$value)
{
if(is_array($array1[$key]) && is_array($array2[$key]))
$retval[$key]=w3_array_union_recursive($array1[$key],$array2[$key]);
}
return $retval;
}
}
return w3_array_union_recursive($backendArray,$frontendArray);
?>