php - isAuthorized Error... cakefolder/ two times -


i having issue, when add 'authorize' => array('controller'), in app controller everytime press edit or add or login goes following address:

localhost/cakefolder/cakefolder

and error:

error: cakefoldercontroller not found.

but when remove 'authorize' => array('controller'), appcontroller 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 not allowed access 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'); }    // let user edit , delete 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 not 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 not 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 not 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 not 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 not 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 not 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            public function beforesave($options = array()) {     // if id not set, we're inserting new user opposed 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 title.'         )              ),      'username' => array(         'required' => array(             'rule' => array( 'isunique' ),             'message' => 'username exist. please try again',             //'allowempty' => false,             //'required' => true,             //'last' => true, // stop validation after rule             //'on' => 'create', // limit validation 'create' or 'update' operations         ),          ),              //email address validation  'email_address' => array(         'required' => array(             'rule' => array('minlength', 1),             'allowempty' => false,             'message' => 'please add email'         )              ),      'email_address' => array(         'required' => array(             'rule' => array( 'isunique' ),             'message' => 'email exist in our database. please try again',             //'allowempty' => false,             //'required' => true,             //'last' => true, // stop validation after rule             //'on' => 'create', // limit validation 'create' or    'update' operations         ),          ),  /*'email_address' => array(         'required' => array(             'rule' => array( 'email' ),             'message' => 'please add correct email',             //'allowempty' => false,             //'required' => true,             //'last' => true, // stop validation after rule             //'on' => 'create', // limit validation 'create' or 'update' operations         ),          ),  */            //password validation  /*  'password' => array(                 'minlength' => array(         'rule' => array('minlength', 6),         'message' => 'your password must @ least 6 characters long.'     ),     'notempty' => array(         'rule' => 'notempty',         'message' => 'please fill in required field.'     ) ), 'password_confirmation' => array(     'identical' => array(         'rule' => array('matchpasswords'),         'message' => 'password confirmation not match password.'     ), */     'password'=>array(  'not empty' => array(  'rule'=>'notempty',  'message'=>'password empty'  ),   'match passwords'=> array(   'rule'=>'matchpasswords',   'message'=>'password 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 rule             //'on' => 'create', // limit validation '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 not match');     return false; }           }   

try using lower case c in controller in loginredirect , logoutredirect settings. whenever url built via array, convention use lower case in keys.

secondly, there may issue base url set up. auth component recognizing need authenticate, trying redirect users/index, may happen default router /. however, instead of going http://localhost/cakefolder or http://localhost/cakefolder/users/index, it's going http://localhost/cakefolder/cakefolder.

can confirm url document root? , check settings value of baseurl.


Comments

Popular posts from this blog

google api - Incomplete response from Gmail API threads.list -

Installing Android SQLite Asset Helper -

Qt Creator - Searching files with Locator including folder -