/**
  * Component startup
  */
 public function startup(Controller $controller)
 {
     $this->settings = array_merge($this->settings, $this->Auth->settings['authenticate'][AuthComponent::ALL]);
     $controller->getEventManager()->attach(array($this, 'beforeLogin'), "Controller.Users.beforeLogin");
     $controller->getEventManager()->attach(array($this, 'afterLogin'), "Controller.Users.afterLogin");
     $controller->getEventManager()->attach(array($this, 'afterLogout'), "Controller.Users.afterLogout");
     /*
     if (!in_array($controller->request->action, array('logout')) && empty($controller->request->data)) {
     	$this->Auth->login();
     }
     */
 }
Example #2
0
 /**
  * Component startup
  */
 public function startup(Controller $controller)
 {
     $this->_Controller = $controller;
     $controller->getEventManager()->attach(array($this, 'onAdminLogoutSuccessful'), 'Controller.Users.adminLogoutSuccessful');
     // skip autologin when mcrypt is not available
     if (!function_exists('mcrypt_decrypt')) {
         return;
     }
     $this->Cookie->type('rijndael');
     $setting = $this->Auth->authenticate['all'];
     list(, $this->_userModel) = pluginSplit($setting['userModel']);
     $this->_fields = $setting['fields'];
     $controller->getEventManager()->attach(array($this, 'onAdminLoginSuccessful'), 'Controller.Users.adminLoginSuccessful');
 }
Example #3
0
 /**
  * Run the shutdown events.
  *
  * Triggers the afterFilter and afterDispatch events.
  *
  * @return void
  */
 protected function _shutdown()
 {
     $afterFilterEvent = new CakeEvent('Controller.shutdown', $this->controller);
     $this->controller->getEventManager()->dispatch($afterFilterEvent);
     $Dispatcher = new Dispatcher();
     $afterDispatchEvent = new CakeEvent('Dispatcher.afterDispatch', $Dispatcher, array('request' => $this->controller->request, 'response' => $this->controller->response));
     $Dispatcher->getEventManager()->dispatch($afterDispatchEvent);
 }
 /**
  * Attaches an event listener function to the controller for Crud Events
  *
  * @param string|array $events Name of the Crud Event you want to attach to controller
  * @param callback $callback callable method or closure to be executed on event
  * @return void
  */
 public function on($events, $callback)
 {
     if (!is_array($events)) {
         $events = array($events);
     }
     foreach ($events as $event) {
         if (!strpos($event, '.')) {
             $event = $this->config('eventPrefix') . '.' . $event;
         }
         $this->_controller->getEventManager()->attach($callback, $event);
     }
 }
 /**
  * Initialize Controller and CakeRequest
  *
  * This method applies Controller attributes.
  * Should be called in Component::initialize() or Controller::beforeFilter()
  *
  * @param Controller $controller
  * @param CakeRequest $request
  * @return boolean
  */
 public function initialize(Controller $controller)
 {
     // attach event listeners
     $controller->getEventManager()->attach(new BackendEventListener());
     // add backend detector
     $controller->request->addDetector('backend', array('callback' => array($this, 'isBackendRequest')));
     $controller->request->addDetector('iframe', array('callback' => array($this, 'isIframeRequest')));
     // is a plugin using backend?
     if ($controller->request->params['plugin']) {
         $this->plugin = $controller->request->params['plugin'];
     }
     if ($controller->request->is('backend')) {
         $this->_isBackendRequest = true;
         // Load plugin specif config
         if ($this->plugin && $this->plugin != "backend") {
             try {
                 Configure::load(Inflector::camelize($this->plugin) . '.backend');
             } catch (Exception $e) {
                 // this plugin has no backend configuration
             }
         }
         // Controller
         $controller->layout = $this->layout;
         $controller->viewClass = 'Backend.Backend';
         // load AuthComponent
         if (Configure::read('Backend.Auth.enabled') === true && !$controller->Components->loaded('Auth')) {
             $controller->Auth = $controller->Components->load('Auth');
             $controller->Auth->initialize($controller);
         }
         // Auth
         if (Configure::read('Backend.Auth.enabled') === true && $controller->Auth) {
             //TODO check if backend auth sessionkey overwrite can be avoided
             AuthComponent::$sessionKey = "Auth.Backend";
             $controller->Auth->authenticate = $this->authenticate;
             $controller->Auth->loginAction = $this->loginAction;
             // enable Access Control List
             if (Configure::read('Backend.Acl.enabled') === true) {
                 //TODO check if acl tables are present
                 $controller->Auth = $this->authorize;
             }
         }
         // Error Handling
         if (is_a($controller, 'CakeErrorController')) {
             // use backend error layout
             $controller->layout = $this->errorLayout;
         }
     }
 }
Example #6
0
 /**
  * Make sure to update the list of known controller methods before startup is called.
  *
  * The reason for this is that if we don't, the Auth component won't execute any callbacks on the controller
  * like isAuthorized.
  *
  * @param Controller $controller
  * @return void
  */
 public function initialize(Controller $controller)
 {
     $this->_normalizeConfig();
     $this->_controller = $controller;
     $this->_controller->methods = array_keys(array_flip($this->_controller->methods) + array_flip(array_keys($this->settings['actions'])));
     $this->_action = $this->_controller->request->action;
     $this->_request = $this->_controller->request;
     $this->_eventManager = $this->_controller->getEventManager();
     if (!isset($this->_controller->dispatchComponents)) {
         $this->_controller->dispatchComponents = array();
     }
     $name = str_replace('Component', '', get_class($this));
     $this->_controller->dispatchComponents[$name] = true;
     $this->_loadListeners();
     $this->trigger('initialize');
 }
Example #7
0
 /**
  * beforeRender callback
  *
  * @param Controller $controller
  * @return void
  */
 public function beforeRender(Controller $controller)
 {
     $component = $controller->Crud->config();
     if ($controller->Crud->isActionMapped()) {
         $Action = $controller->Crud->action();
         $action = $Action->config();
     }
     $eventManager = $controller->getEventManager();
     $eventLog = $controller->Crud->eventLog();
     $events = array();
     foreach ($eventLog as $event) {
         list($name, $data) = $event;
         $listeners = $eventManager->listeners($name);
         $callbacks = $this->_getCallbacks($listeners);
         $uName = $this->_getUniqueName($name, $events);
         $events[$uName] = array('data' => $data, 'callbacks' => $callbacks);
     }
     $listeners = array();
     foreach ($controller->Crud->config('listeners') as $listener => $value) {
         $listeners[$listener] = $controller->Crud->listener($listener)->config();
     }
     $controller->set('crudDebugKitData', compact('component', 'action', 'events', 'listeners'));
 }
 /**
  * Setup method
  *
  * @param Controller $controller
  * @return void
  */
 protected function setup(Controller $controller)
 {
     // Cache local properties from the controller
     $this->controller = $controller;
     $this->request = $controller->request;
     $this->response = $controller->response;
     // Configure detectors
     $this->configureRequestDetectors();
     // Don't do anything if the request isn't considered API
     if (!$this->request->is('api')) {
         return;
     }
     // Bind Crud Event Api
     $this->controller->getEventManager()->attach(new ApiListener());
     // Copy publicActions from the controller if set and no actions has been defined already
     // @todo: This is legacy, remove it
     if (isset($this->controller->publicActions) && empty($this->publicActions)) {
         $this->publicActions = $this->controller->publicActions;
     }
     // Change Exception.renderer so output isn't forced to HTML
     Configure::write('Exception.renderer', 'Api.ApiExceptionRenderer');
     // Always repond as JSON
     $this->controller->response->type('json');
 }
Example #9
0
 /**
  * Setup Event handlers
  *
  * @return void
  */
 protected function _setupEvents(Controller $controller)
 {
     $callback = array($this, 'getCommentData');
     $eventManager = $controller->getEventManager();
     $eventManager->attach($callback, 'Controller.Nodes.view');
 }