4我有一个应用程序,用于注册用户在页面上编辑和写入。我的问题是,一旦第一个用户登录所有其他用户似乎不需要有效密码。简而言之,它只会验证第一个用户。 添加操作用于注册新用户,博客操作是编辑和发布页面。感谢任何帮助,谢谢。
以下是我的代码;
<?php
class UsersController extends AppController {
public $helpers = array('Html', 'Form');
public $name='Users';
public function beforeFilter() {
parent::beforeFilter();
$this->Auth->allow('add','logout'); // Letting users register themselves
}
public function isAuthorized($user){
if (in_array($this->action, array('edit'))){
if($user['id'] != $this->request->params['pass'][0]){
return false;
}
}
return true;
}
public function login() {
if ($this->request->is('post')) {
debug($this->Auth->login());
if ($this->Auth->login()) {
return $this->redirect($this->Auth->redirectUrl());
} else{
$this->Session->setFlash(__('Invalid username or password'),'default', array(), 'auth');
}
}
}
public function logout() {
return $this->redirect($this->Auth->logout());
}
public function users() {
}
public function index() {
$this->set('users', $this->User->find('all'));
}
public function view($id = NULL) {
$this->set('users', $this->User->read(NULL, $id));
}
public function edit() {
}
public function blog() {
if ($this->request->is('post')) {
$this->User->create();
if ($this->User->save($this->request->data)) {
return $this->redirect(array('action' => 'index'));
}
}
$this->Session->setFlash(__('really'));
}
public function add() {
if ($this->request->is('post')) {
$this->User->create();
if ($this->User->save($this->request->data)) {
$this->request->data['User']['password'] ==$this->request->data['User'][ 'password_Confirmation'];
$this->Session->setFlash(__('The user has been saved'));
return $this->redirect(array('action' => 'index'));
}
$this->Session->setFlash(__('The user could not be saved. Please, try again.'));
}
}
}