Sat*_*ati 5 authentication cakephp-2.0
当我尝试登录应用程序时,我正试图将我的代码从本地移动到服务器
Here is my AppController
class AppController extends Controller{
/* Determines what logged-in users access to */
var $components = array('Auth','Session');
public function isAuthorized($user){
return true;
}
public function beforeFilter(){
$userdetails = array();
$this->Auth->autoRedirect = false;
$this->Auth->loginAction = array('controller' => 'users', 'action' => 'login');
$this->Auth->loginRedirect = array('controller' => 'matches', 'action' => 'index');
$this->Auth->authorize = 'controller';
$this->Auth->authError= 'You need permissions to access this page';
$this->Auth->allow('users');
$this->set('Auth',$this->Auth);
$userdetails = $this->Auth->user();
$this->set('myUser', $userdetails['username']);
$this->set('myRole', $userdetails['user_role_id']);
$this->set('pStatus', $userdetails['password_status']);
}
}
Here is my Login Action in UsersController
public function login(){
$this->Auth->autoRedirect = false;
$id = $this->Auth->user('id');
if(empty($id)){
if($this->request->is('post')){
if($this->Auth->login()){
$this->redirect($this->Auth->redirect());
}else{
$this->Session->setFlash('Invalid Username or password');
}
}
}else{
$this->redirect(array('action'=>'index'));
}
}
Run Code Online (Sandbox Code Playgroud)
谢谢您的帮助
men*_*sch 14
您在其中授权控制器的部分beforeFilter
应正确大写:
所以:
$this->Auth->authorize = 'Controller';
代替:
$this->Auth->authorize = 'controller';
那个特定的声明试图寻找controllerAuthorize.php
并且应该寻找ControllerAuthorize.php
.这不会在Windows上造成问题,但在Unix系统上会出现问题.