Как заблокировать действия в Cake PHP 2.8 API REST - PullRequest
0 голосов
/ 18 октября 2019

Я хочу сделать свое действие "индексным" в моей блокировке DaysController по учетным данным (имя пользователя и пароль, которые я уже сохранил в своей модели User). Но я не нахожу правильный способ сделать это, мой REST API с Cake PHP 2.8.0

Я получаю доступ к моему RestAPI через ReactJS Client.

Не могли бы вы помочь мне и сказать, что яЯ делаю неправильно?

AppController.php

<?php

App::uses('Controller', 'Controller');

/**
 * Application Controller
 *
 * Add your application-wide methods in the class below, your controllers
 * will inherit them.
 *
 * @package       app.Controller
 * @link http://book.cakephp.org/2.0/en/controllers.html#the-app-controller
 */
class AppController extends Controller {

  public $components = array(
    'Session',
    'Auth',
    'Security'
  );


  public function beforeFilter(){

    parent::beforeFilter();
      $this->response->header('Access-Control-Allow-Origin','*');
    $this->response->header('Access-Control-Allow-Methods','*');
    $this->response->header('Access-Control-Allow-Headers','X-Requested-With');
    $this->response->header('Access-Control-Allow-Headers','Content-Type, x-xsrf-token');
    $this->response->header('Access-Control-Max-Age','172800');

    if(in_array($this->params['controller'],array('days'))){        
        $this->Auth->allow();             
        $this->Security->unlockedActions = array('add','view','edit','delete');         
    }else{        
        $this->Auth->allow();         
    }
  }

}

DaysController.php

<?php
class DaysController extends AppController {


    public $components = array(       
        'RequestHandler'
    );



    public function index() {
        $days = $this->Day->find('all');
        $this->set(array(
            'days' => $days,
            '_serialize' => array('days')
        ));
    }


    public function view($id) {
        $day = $this->Day->findById($id);
        $this->set(array(
            'day' => $day,
            '_serialize' => array('day')
        ));
    }


    public function add() {
        $this->Day->create();
        if ($this->Day->save($this->request->data)) {
            $message = 'Saved';
        } else {
            $message = 'Error';
        }
        $this->set(array(
            'message' => $message,
            '_serialize' => array('message')
        ));
    }


    public function edit($id) {
        $this->Day->id = $id;
        if ($this->Day->save($this->request->data)) {
            $message = 'Saved';
        } else {
            $message = 'Error';
        }
        $this->set(array(
            'message' => $message,
            '_serialize' => array('message')
        ));
    }


    public function delete($id) {
        if ($this->Day->delete($id)) {
            $message = 'Deleted';
        } else {
            $message = 'Error';
        }
        $this->set(array(
            'message' => $message,
            '_serialize' => array('message')
        ));
    }
}
?>

Большое спасибо за вашу помощь: -)

...