我正在尝试在 cakephp 中进行简单的“用户身份验证”。我编写了食谱中给出的代码,但我的登录功能无法正常工作。它不进行任何身份验证,并允许任何用户访问或编辑数据,即使提供空白用户名和密码,也允许我登录。我在 Appcontroller.php 中编写了以下代码
<?php
class AppController extends Controller {
public $components = array(
'Session',
'Auth' => array(
'loginRedirect' => array('controller' => 'users','action' => 'index'),
'logoutRedirect' => array('controller' => 'users','action' => 'login')
)
);
public function beforeFilter() {
$this->layout = 'admin_layout';
$this->Auth->allow('index','view');
}
用户控制器.php
<?php
App::uses('AppController', 'Controller');
App::uses('AuthComponent', 'Controller/Component');
class UsersController extends AppController {
public function login()
{
if($this->request->is('post')) {
if ($this->Auth->login()) {
if($this->Auth->login());
$this->redirect($this->Auth->redirect());
} else {
$this->Session->setFlash(__('Invalid username or password, try again'));
}
}}
public function logout() {
$this->redirect($this->Auth->logout());
}
Login.ctp is as follows
<?php echo $this->Html->css('login');?>
<div class="logincontainer">
<div class="loginform">
<div class="img">
</div>
<?php echo $this->Form->create('User'); ?>
<div id="input">
<div id="username">
<?php // echo $this->Form->input('username');?>
<?php echo $this->Form->input('username',array('class'=>'name','placeholder'=>'username','label'=>false));?>
</div>
<div id="space">
</div>
<div id="password">
<?php // echo $this->Form->input('password');?>
<?php echo $this->Form->input('password',array('class'=>'name','placeholder'=>'password','label'=>false));?>
</div>
<div id="space1"></div>
<?php echo $this->Form->end('Login'); ?>
<div id="forgot">Forgot Password
</div>
</div>
<?php // echo $this->Session->flash();?>
</div>
</div>
有人可以指导我错在哪里..