我正在开发一个带蛋糕的简单登录应用程序..总是返回false ..为什么?我的代码
我的AppController代码是...... 的 AppController.php
public $components = array(
'Session', 'RequestHandler', 'Auth', 'Email'
);
public $helpers = array(
'Session','Time','Text','Number'
);
public $titleForLayout = null;
public $currentUser = array();
public function beforeFilter() {
// Configurações específicas para cada prefixo
if ($this->isPrefix('operador')) {
$this->layout = 'admin';
} elseif ($this->isPrefix('user')) {
}
// Configurações de login
$this->_manageAuthConfigs();
$this->currentUser = $this->Auth->user();
$this->set('usuario',$this->Auth->user('nome'));
$this->set('id',$this->Auth->user('id'));
return parent::beforeFilter();
}
public function _forceSecure(){
$this->redirect('https://'.env('SERVER_NAME').env('REQUEST_URI'));
}
// Verifiy that is a prefix
protected function isPrefix($prefix)
{
$params = $this->request->params;
return isset($params['prefix']) && $params['prefix'] === $prefix;
}
private function _manageAuthConfigs() {
// $this->Auth->authError = 'Área restrita, identifique-se primeiro.';
$this->Auth->authorize = array('Controller');
$this->Auth->allow('index', 'info', 'enviar');
AuthComponent::$sessionKey = 'Auth.User';
$this->Auth->loginAction = array('controller' => 'users', 'action' => 'index', 'user' => true);
$this->Auth->loginRedirect = array('controller' => 'Obras', 'action' => 'painel');
$this->Auth->logoutRedirect = array('controller' => 'Home', 'action' => 'index');
$this->Auth->authenticate = array(
'Form' => array(
'userModel' => 'User',
'fields' => array('username' => 'email', 'password'=>'password'),
),
);
if ($this->isPrefix('operador')) {
$this->layout = 'admin';
AuthComponent::$sessionKey = 'Auth.Operador';
$this->Auth->loginAction = array('controller' => 'operadors', 'action' => 'login', 'operador' => true);
$this->Auth->loginRedirect = array('controller' => 'operadors', 'action' => 'Home');
$this->Auth->logoutRedirect = array('controller' => 'operadors', 'action' => 'index');
$this->Auth->deny();
$this->Auth->authenticate = array(
'Form' => array(
'userModel' => 'Operador',
'fields' => array('username' => 'email', 'password'=>'password'),
),
);
//$this->Auth->allow('index', 'login', 'home');
}
}
public function isAuthorized($user = null)
{
return true;
}
我的UsersController代码是...... 的 UsersController.php
public function index(){
if ($this->request->is('post')) {
if ($this->Auth->login()) {
$this->redirect($this->Auth->redirectUrl());
} else {
$this->Session->setFlash('<b>Erro!</b> E-mail ou senha inválidos.', 'default', array('class'=>'alert alert-danger'), 'Operador.CCN');
}
}
}
查看/用户/ index.ctp
<?php echo $this->Session->flash('bad');?>
<?php echo $this->Session->flash('auth'); ?>
<?php echo $this->Form->create('User'); ?>
<div class="row">
<div class="form-group">
<div class="col-md-12">
<label>E-mail</label>
<?php echo $this->Form->input('email', array('class'=>'form-control', 'label'=>false));?>
</div>
</div>
</div>
<div class="row">
<div class="form-group">
<div class="col-md-12">
<a class="pull-right" id="headerRecover" href="#">Esqueci minha senha</a>
<label>Senha</label>
<?php echo $this->Form->input('password', array('class'=>'form-control', 'label'=>false));?>
</div>
</div>
</div>
<div class="row">
<div class="col-md-6">
</div>
<div class="col-md-6">
<?php echo $this->Form->button(__('Login'), array('class'=>'btn btn-primary pull-right push-bottom')); ?>
</div>
</div>
</form>
</div>
</div>