/**
  * Handles the optional setting of view vars within the component.
  *
  * @param boolean|string $viewVar
  * @param \Cake\Datesource\EntityInterface
  * @return void
  */
 protected function _setViewVar($viewVar, $entity)
 {
     if ($viewVar === false) {
         return;
     }
     $this->_controller->set($viewVar, $entity);
 }
Пример #2
0
 public function startup(Event $event)
 {
     if ($this->config('use_session_salt')) {
         if (!$this->controller->request->session()->check('Alaxos.SpamFilterComponent.salt')) {
             $this->controller->request->session()->write('Alaxos.SpamFilterComponent.salt', String::uuid());
         }
     } elseif ($this->controller->request->session()->check('Alaxos.SpamFilterComponent.salt')) {
         $this->controller->request->session()->delete('Alaxos.SpamFilterComponent.salt');
     }
     $salt = $this->get_session_salt();
     $this->controller->components()->load('Security')->config('unlockedFields', [SecurityTool::get_today_fieldname($salt)]);
     $this->controller->components()->load('Security')->config('unlockedFields', [SecurityTool::get_yesterday_fieldname($salt)]);
     /*
      * Pass Session salt to view in order to be available in AlaxosFormHelper
      */
     $this->controller->set('_alaxos_spam_filter_salt', $salt);
 }
Пример #3
0
 /**
  * Prepare Entity used to display search filters in the view
  * @param array $options
  * @return void
  */
 public function prepareSearchEntity(array $options = array())
 {
     $options['modelClass'] = isset($options['modelClass']) ? $options['modelClass'] : $this->controller->modelClass;
     $search_entity = $this->controller->{$options['modelClass']}->newEntity();
     $search_entity->accessible('*', true);
     $this->controller->{$options['modelClass']}->patchEntity($search_entity, $this->request->data);
     $this->controller->set(compact('search_entity'));
 }
 /**
  * Let the logged in user change his password.
  *
  * @param array $options
  * @return void
  */
 public function changePassword($options = [])
 {
     $options = Hash::merge($this->_defaultConfig['changePassword'], $options);
     $entity = $this->UserTable->newEntity();
     $entity->accessible(['id', 'old_password', 'new_password', 'confirm_password'], true);
     if ($this->request->is(['post', 'put'])) {
         $entity = $this->UserTable->patchEntity($entity, $this->request->data);
         $entity->id = $this->_controller->Auth->user('id');
         $entity->isNew(false);
         if ($this->UserTable->changePassword($entity)) {
             $this->request->data = [];
             $entity = $this->UserTable->newEntity();
             $entity->id = $this->_controller->Auth->user('id');
             $entity->isNew(false);
             $this->handleFlashAndRedirect('success', $options);
         } else {
             $this->handleFlashAndRedirect('error', $options);
         }
     }
     $this->_controller->set('entity', $entity);
 }