/** * Before filter callback. * * @param CakeEvent $event * @return void */ public function beforeFilter(CakeEvent $event) { parent::beforeFilter($event); Event::dispatch('App.Controller.Setup', $this); $this->set('page_title', implode(' ', [$this->request->param('controller'), $this->request->param('action')])); $this->Security->config('unlockedFields', ['action']); }
/** * Upload theme. * * @return \Cake\Network\Response|void * @throws \Exception */ public function upload() { $themeEntity = $this->Themes->newEntity(); if ($this->request->is(['post', 'put'])) { $Installer = new ThemeInstaller($this->request); $isValidate = $Installer->validate()->isValid(); if ($isValidate) { if ($Installer->open() && $Installer->extract()->getResult()) { $result = $Installer->getOutput(); $alias = Plugin::nameToAlias($result['name']); $themeEntity = $this->Themes->patchEntity($themeEntity, ['params' => [], 'name' => $result['name'], 'alias' => $alias, 'client_id' => ThemeExtension::getInstance()->getClientIdByAttr($result['data'])]); if ($this->Themes->save($themeEntity)) { $this->Flash->success($result['message']); } else { Event::dispatch('Controller.Themes.failSave', $this, ['theme' => $themeEntity]); $this->Flash->error(__d('extensions', 'The template was not saved, try again')); } } else { $this->Flash->success(__d('extensions', 'Can not install theme.')); } } else { $Installer->setFlashErrors($this->Flash); } return $this->redirect(['action' => 'index']); } }
/** * Configuration plugin action. * * @param null $plugin */ public function config($plugin = null) { $plugin = UnionPlugin::aliasToName($plugin); $alias = UnionPlugin::nameToAlias($plugin); $pluginName = UnionPlugin::getFullName($plugin); $isLoaded = CakePlugin::loaded($plugin); if ($isLoaded) { $configs = $this->Plugins->find()->where(['alias' => $alias])->first(); if (!$configs) { $configs = $this->Plugins->newEntity(['params' => [], 'alias' => $alias, 'name' => $pluginName]); } if ($this->request->is(['post', 'put'])) { $configs = $this->Plugins->patchEntity($configs, $this->request->data); if ($result = $this->Plugins->save($configs)) { $this->Flash->success(__d('extensions', 'The settings has been saved.')); return $this->Union->setRedirect(['apply' => ['action' => 'config', $result->alias]]); } else { $this->Flash->error(__d('extensions', 'The settings could not be saved. Please, try again.')); } } Event::dispatch($plugin . '.Config.Admin.Controller', $this); $this->set('configs', $configs); $this->viewBuilder()->templatePath('Admin/Plugin'); $this->render($plugin . '.config'); } else { throw new MissingPluginException(['plugin' => $plugin]); } }
/** * Bulk delete method. * * @param $ids * @return bool|mixed */ public function bulkDelete($ids) { $result = false; foreach ($ids as $id) { $theme = $this->get($id); Event::dispatch('Model.Themes.beforeBulkDelete', $this, ['theme' => $theme]); $result = $this->delete($theme); } return $result; }
/** * Before filter callback. * * @param CakeEvent $event * @return void */ public function beforeFilter(CakeEvent $event) { parent::beforeFilter($event); $this->Security->config('blackHoleCallback', 'blackHole'); if ($this->isAdmin()) { Event::dispatch('Core.Controller.setupAdminData', $this); $this->viewBuilder()->layout('admin'); $this->set('page_header', __d('core', 'Page header')); } Event::dispatch('Core.Controller.setupData', $this); $this->set('authorize', new PhpArray($this->Auth->user())); }
/** * Login action. * * @return \Cake\Network\Response|null */ public function login() { if ($this->App->isAdmin()) { $this->viewBuilder()->layout('authorize'); } if ($this->request->is('post')) { Event::dispatch($this->_getEventName('Users', 'BeforeLogin'), $this); if ($user = $this->Auth->identify()) { $this->Auth->setUser($user); Event::dispatch($this->_getEventName('Users', 'SuccessLogin'), $this); return $this->redirect($this->Auth->redirectUrl()); } Event::dispatch($this->_getEventName('Users', 'FailLogin'), $this); $this->Flash->error(__d('community', 'Username or password is incorrect')); } }
/** * Edit action. * * @return \Cake\Network\Response|null */ public function edit() { $id = $this->Auth->user('id'); $user = $this->Users->get($id); if ($this->request->is(['patch', 'post', 'put'])) { $user = $this->Users->patchEntity($user, $this->request->data); Event::dispatch('Controller.Users.Edit.BeforeSave', $this, ['user' => $user]); /** @var \Union\Community\Model\Entity\User $result */ if ($result = $this->Users->save($user)) { Event::dispatch('Controller.Users.Edit.AfterSave', $this, ['user' => $user]); $this->Flash->success(__d('community', '{0}, your profile has been successfully updated.', sprintf('<strong>%s</strong>', $result->username))); return $this->redirect(['action' => 'edit']); } else { $this->Flash->error(__d('community', 'Profile has not been updated. Please, try again.')); } } $this->set(compact('user')); $this->set('page_title', __d('community', 'Edit profile')); }
/** * Chooser action. * * @return void */ public function chooser() { Event::dispatch('Controller.Admin.Link.Chooser', $this); $types = Configure::read('Link.choosers'); $types = Hash::sort($types, '{n}.order', 'desc'); $this->set('types', $types); }
/** * Process action. * * @param Table $table * @param $action * @param array $ids * @param array $options * @return \Cake\Network\Response|void */ public function process(Table $table, $action, array $ids = [], array $options = []) { $idsCount = count($ids); $options = Hash::merge($this->_config, $options); $_options = ['messages' => $this->__setupMessages($idsCount)]; $options = Hash::merge($_options, $options); $redirect = $options['redirect']; $messages = $options['messages']; if (!$action) { $this->Flash->error($messages['noAction']); return $this->_controller->redirect($redirect); } if ($idsCount == 0) { $this->Flash->error($messages['noChose']); return $this->_controller->redirect($redirect); } $behaviors = $table->behaviors(); if (!in_array('BulkProcess', $behaviors->loaded())) { $behaviors->load('Union/Core.BulkProcess'); } $event = Event::dispatch($this->_getEventName($action, 'bulkBefore'), $this->_controller, ['ids' => $ids]); if (is_array($event->result)) { $ids = $event->result; if (count($ids) == 0) { $this->Flash->error($messages['noChose']); return $this->_controller->redirect($redirect); } $messages = $this->__setupMessages(count($ids)); } $process = $table->processAction($action, $ids); if ($process) { if (!empty($messages[$action])) { $message = $messages[$action]; } else { $message = __d('union', '{0} processed', Inflector::humanize($this->_controller->name)); } Event::dispatch($this->_getEventName($action), $this->_controller, ['ids' => $ids]); $this->Flash->success($message); return $this->_controller->redirect($redirect); } $this->Flash->error(__d('union', 'An error occurred')); return $this->_controller->redirect($redirect); }
/** * View action. * * @return mixed */ public function view() { $event = Event::dispatch('Event.Controller.view'); return $event->result; }
/** * Controller success process. * * @param string $action * @param array $messages * @param array $redirect * @param array $ids * @return \Cake\Network\Response|null */ protected function _process($action, array $messages, array $redirect, array $ids) { if (Arr::key($action, $messages)) { $message = $messages[$action]; } else { $message = __d('union', '{0} processed.', Inflector::humanize($this->_controller->name)); } Event::dispatch($this->_getEventName($action, self::EVEN_POS_AFTER), $this->_controller, ['ids' => $ids]); $this->Flash->success($message); return $this->_controller->redirect($redirect); }
/** * Registration action. * * @return void|\Cake\Network\Response */ public function registration() { if ($this->Auth->user('id')) { $this->Flash->error(__d('community', 'It is impossible to register. Exit the system for registration.')); return $this->redirect(['action' => 'edit']); } $user = $this->Users->newEntity(['token' => $this->generateToken()]); if ($this->request->is('post')) { Event::dispatch('Controller.Users.Registration.beforeSave', $this); $user = $this->Users->patchEntity($user, $this->request->data()); if ($result = $this->Users->save($user)) { Event::dispatch('Controller.Users.Registration.afterSave', $this, ['user' => $result]); $this->Flash->success(__d('community', 'To activate, click on the link that we sent you in the mail.')); return $this->redirect(['action' => 'login']); } else { $this->Flash->error(__d('community', 'An error has occurred. Please, try again.')); } } $roles = $this->Users->Roles->find()->toArray(); $this->set(compact('user', 'roles')); $this->set('page_title', __d('community', 'Registration on site')); }
/** * Edit action. * * @param int|string $id * @return \Cake\Network\Response|null */ public function edit($id) { $user = $this->Users->get($id); if ($this->request->is(['patch', 'post', 'put'])) { $user = $this->Users->patchEntity($user, $this->request->data); Event::dispatch('Controller.Users.Edit.BeforeSave.Admin', $this, ['user' => $user]); /** @var \Union\Community\Model\Entity\User $result */ if ($result = $this->Users->save($user)) { Event::dispatch('Controller.Users.Edit.AfterSave.Admin', $this, ['user' => $user]); $this->Flash->success(__d('community', 'The user «{0}» has been updated.', sprintf('<strong>%s</strong>', $result->username))); return $this->App->redirect(['apply' => ['action' => 'edit', $result->id]]); } else { $this->Flash->error(__d('community', 'The user could not be saved. Please, try again.')); } } $roles = $this->Users->Roles->getTreeList(); $this->set(compact('roles', 'user')); $this->set('page_title', __d('community', 'Edit user «{0}»', $user->username)); }
/** * Change password action. * * @param null $id * @return \Cake\Network\Response|void */ public function changePass($id = null) { $user = $this->Users->get($id, ['contain' => []]); if ($this->request->is(['patch', 'post', 'put'])) { Event::dispatch('Controller.Admin.Users.changePass.beforeSave', $this, ['user' => $user]); $user = $this->Users->patchEntity($user, $this->request->data); if ($result = $this->Users->save($user)) { Event::dispatch('Controller.Admin.Users.changePass.afterSave', $this, ['user' => $user]); $this->Flash->success(__d('community', 'Password has been updated.')); return $this->Union->setRedirect(['apply' => ['action' => 'edit', $result->id]]); } else { $this->Flash->error(__d('community', 'Password could not be updated. Please, try again.')); } } $this->set(compact('user')); }