dqx36753 2014-06-26 04:13
浏览 34

isAuthorized Error ... cakefolder /两次

I am having an issue, when I add 'authorize' => array('Controller'), in my app controller everytime I press edit or add or login it goes to the following address:

localhost/cakefolder/cakefolder

and I get this error:

Error: cakefolderController could not be found.

But when I remove 'authorize' => array('Controller'), from the appController everything goes normal

.

AppController.php

         <?php

      class AppController extends Controller {


public $helpers = array('Html', 'Session', 'Form' );
public $components = array(
'DebugKit.Toolbar',
'Session', 
'Auth' => array(
'authorize' => array('Controller'),
'authenticate' => array(
'Form' => array(
'passwordHasher' => 'Blowfish',
'loginRedirect'=>array('Controller'=>'user', 'action'=>'index'),
'logoutRedirect'=>array('Controller'=>'user', 'action'=>'index'),
'authError'=>"you are not allowed to access that page",

    )
)
)
); 


public function beforeFilter() {

    $this->Auth->allow('index', 'add');
    $this->set('logged_in', $this->Auth->loggedIn());
    $this->set('current_user', $this->Auth->user());



}

 }

UserController.php

     <?php
       App::uses('AppController', 'Controller');



     class UsersController extends AppController {



public function beforeFilter() {
    parent::beforeFilter();
    $this->Auth->allow('add');
}



// This is to let user edit and delete only their own information
  public function isAuthorized($user) {
if (in_array($this->action, array('edit','delete'))) {
    if ($user['id'] != $this->request->params['pass'][0]) {
        return false;
    }   
    return true;

}
       }   


    public function login() {
if ($this->request->is('post')) {
    if ($this->Auth->login()) {
        return $this->redirect($this->Auth->redirect());
    }
    $this->Session->setFlash(__('Invalid username or password, try again'));
  }
  }


public function logout() {
    $this->Auth->logout();
    $this->redirect('index');
}


public $components = array('Paginator', 'Session');


public function index() {
    $this->User->recursive = 0;
    $this->set('users', $this->Paginator->paginate());
}


public function view($id = null) {
    if (!$this->User->exists($id)) {
        throw new NotFoundException(__('Invalid user'));
    }
    $options = array('conditions' => array('User.' . $this->User->primaryKey =>    $id));
    $this->set('user', $this->User->find('first', $options));
}


public function add() {
    if ($this->request->is('post')) {
    //  $this->User->create();

        if ($this->User->save($this->request->data)) {
            $this->Session->setFlash(__('The user has been saved.'));
            return $this->redirect(array('action' => 'index'));
        } else {
            $this->Session->setFlash(__('The user could not be saved. Please, try again.'));
        }
    }
}



public function edit($id = null) {
    if (!$this->User->exists($id)) {
        throw new NotFoundException(__('Invalid user'));
    }
    if ($this->request->is(array('post', 'put'))) {
        if ($this->User->save($this->request->data)) {
            $this->Session->setFlash(__('The user has been saved.'));
            return $this->redirect(array('action' => 'index'));
        } else {
            $this->Session->setFlash(__('The user could not be saved. Please, try again.'));
        }
    } else {
        $options = array('conditions' => array('User.' . $this->User->primaryKey => $id));
        $this->request->data = $this->User->find('first', $options);
    }
}


public function delete($id = null) {
    $this->User->id = $id;
    if (!$this->User->exists()) {
        throw new NotFoundException(__('Invalid user'));
    }
    $this->request->allowMethod('post', 'delete');
    if ($this->User->delete()) {
        $this->Session->setFlash(__('The user has been deleted.'));
    } else {
        $this->Session->setFlash(__('The user could not be deleted. Please, try again.'));
    }
    return $this->redirect(array('action' => 'index'));
}


public function full_index() {
    $this->User->recursive = 0;
    $this->set('users', $this->Paginator->paginate());
}




public function full_view($id = null) {
    if (!$this->User->exists($id)) {
        throw new NotFoundException(__('Invalid user'));
    }
    $options = array('conditions' => array('User.' . $this->User->primaryKey =>   $id));
    $this->set('user', $this->User->find('first', $options));




}


public function full_add() {
    if ($this->request->is('post')) {
        $this->User->create();
        if ($this->User->save($this->request->data)) {
            $this->Session->setFlash(__('The user has been saved.'));
            return $this->redirect(array('action' => 'index'));
        } else {
            $this->Session->setFlash(__('The user could not be saved. Please, try again.'));
        }
    }
}


public function full_edit($id = null) {
    if (!$this->User->exists($id)) {
        throw new NotFoundException(__('Invalid user'));
    }
    if ($this->request->is(array('post', 'put'))) {
        if ($this->User->save($this->request->data)) {
            $this->Session->setFlash(__('The user has been saved.'));
            return $this->redirect(array('action' => 'index'));
        } else {
            $this->Session->setFlash(__('The user could not be saved.     Please, try again.'));
        }
    } else {
        $options = array('conditions' => array('User.' . $this->User- >primaryKey => $id));
        $this->request->data = $this->User->find('first', $options);
    }
}


public function full_delete($id = null) {
    $this->User->id = $id;
    if (!$this->User->exists()) {
        throw new NotFoundException(__('Invalid user'));
    }
    $this->request->allowMethod('post', 'delete');
    if ($this->User->delete()) {
        $this->Session->setFlash(__('The user has been deleted.'));
    } else {
        $this->Session->setFlash(__('The user could not be deleted. Please,      try again.'));
    }
    return $this->redirect(array('action' => 'index'));
}
             }

User.php

   <?php
     App::uses('AppModel', 'Model', 'Security', 'Utility');
App::uses('BlowfishPasswordHasher', 'Controller/Component/Auth');



    class User extends AppModel {




            // hash password before saving It  


       public function beforeSave($options = array()) {
    // if ID is not set, we're inserting a new user as opposed to updating
    if (!$this->id) {
        $passwordHasher = new BlowfishPasswordHasher();
      $this->data[$this->alias]['password'] = $passwordHasher->hash($this->data[$this- >alias]['password']);
    }
       return true;
  }







public $primaryKey = 'user_id';

public $displayField = 'username';



public $validate = array(




//USERNAME VALIDATION

'username' => array(
        'required' => array(
            'rule' => array('minLength', 1),
            'allowEmpty' => false,
            'message' => 'Please enter a title.'
        )          
   ),

    'username' => array(
        'required' => array(
            'rule' => array( 'isUnique' ),
            'message' => 'Username already exist. Please try again',
            //'allowEmpty' => false,
            //'required' => TRUE,
            //'last' => TRUE, // Stop validation after this rule
            //'on' => 'create', // Limit validation to 'create' or 'update' operations
        ),

        ),





        //EMAIL ADDRESS VALIDATION

'email_address' => array(
        'required' => array(
            'rule' => array('minLength', 1),
            'allowEmpty' => false,
            'message' => 'Please add an email'
        )          
   ),

    'email_address' => array(
        'required' => array(
            'rule' => array( 'isUnique' ),
            'message' => 'Email already exist in our database. Please try again',
            //'allowEmpty' => false,
            //'required' => TRUE,
            //'last' => TRUE, // Stop validation after this rule
            //'on' => 'create', // Limit validation to 'create' or    'update' operations
        ),

        ),

/*'email_address' => array(
        'required' => array(
            'rule' => array( 'email' ),
            'message' => 'Please add a correct email',
            //'allowEmpty' => false,
            //'required' => TRUE,
            //'last' => TRUE, // Stop validation after this rule
            //'on' => 'create', // Limit validation to 'create' or 'update' operations
        ),

        ),  */



        //PASSWORD VALIDATION

/*  'password' => array(            
    'minLength' => array(
        'rule' => array('minLength', 6),
        'message' => 'Your password must be at least 6 characters long.'
    ),
    'notempty' => array(
        'rule' => 'notEmpty',
        'message' => 'Please fill in the required field.'
    )
),
'password_confirmation' => array(
    'identical' => array(
        'rule' => array('matchPasswords'),
        'message' => 'Password confirmation does not match password.'
    ), */



 'password'=>array(
 'not empty' => array(
 'rule'=>'notEmpty',
 'Message'=>'Password is empty'
 ),

 'Match Passwords'=> array(
  'rule'=>'matchPasswords',
  'message'=>'Password do not match'
 )
 ),            

  'password_confirmation'=>array(
   'not empty' => array(
 'rule'=>'notEmpty',
 'Message'=>'verify password'
 )
  )





/*  'user_id' => array(
        'alphaNumeric' => array(
            'rule' => array('alphaNumeric'),
            //'message' => 'Your custom message here',
            //'allowEmpty' => false,
            //'required' => false,
            //'last' => false, // Stop validation after this rule
            //'on' => 'create', // Limit validation to 'create' or 'update' operations
        ), */



    );


// PASSWORD CONFIRMATION VALIDATION FUNCTION 
 public function matchPasswords($data){

    if ($data['password'] == $this->data['User']['password_confirmation']) {
        return True;
    }

    $this->invalidate('password_confirmation', 'Your password do not match');
    return FALSE;
} 





    }  
  • 写回答

1条回答 默认 最新

  • dongyongju9560 2014-06-26 05:23
    关注

    Try using a lower case c in controller in the loginRedirect and logoutRedirect settings. Whenever a URL is built via an array, it is convention to use lower case in the keys.

    Secondly, there may be an issue with your base url set up. The Auth component is recognizing you need to authenticate, so it is trying to redirect you to users/index, which may also happen to be the default router for /. However, instead of going to http://localhost/cakefolder or http://localhost/cakefolder/users/index, it's going to http://localhost/cakefolder/cakefolder.

    Can you confirm the URL for your document root? And check your settings for the value of baseUrl.

    评论

报告相同问题?

悬赏问题

  • ¥15 2024-五一综合模拟赛
  • ¥15 下图接收小电路,谁知道原理
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测
  • ¥15 ETLCloud 处理json多层级问题
  • ¥15 matlab中使用gurobi时报错
  • ¥15 这个主板怎么能扩出一两个sata口
  • ¥15 不是,这到底错哪儿了😭