From 4e82174c6ddf24088eb0add14ef1871afed7fa3d Mon Sep 17 00:00:00 2001 From: George Dimakopoulos Date: Wed, 26 Jul 2017 11:12:56 +0300 Subject: [PATCH] Publication point --- README.md | 5 + src/Controller/AppController.php | 98 ++++++++++++++++++++ src/Controller/Component/GlobalComponent.php | 83 +++++++++++++++++ 3 files changed, 186 insertions(+) create mode 100755 src/Controller/AppController.php create mode 100755 src/Controller/Component/GlobalComponent.php diff --git a/README.md b/README.md index 3bdf066..34d4502 100644 --- a/README.md +++ b/README.md @@ -16,3 +16,8 @@ By committing source code, data or other material to the Shopimail project you are assigning all copyright and/ or similar rights to AVERWAY LTD in consideration of its agreement to license the source, code, data or other material under GPL v.3.0. + +## Screenshots +![Screenshot](https://user-images.githubusercontent.com/28845968/27742554-d34ecb3c-5dc1-11e7-9c3c-5e348ab06256.png) +![Screenshot](https://user-images.githubusercontent.com/28845968/27742582-e50c2086-5dc1-11e7-989b-2f03e5d856e8.png) +![Screenshot](https://user-images.githubusercontent.com/28845968/27742593-eeb5feea-5dc1-11e7-8b20-8fa725f001f5.png) diff --git a/src/Controller/AppController.php b/src/Controller/AppController.php new file mode 100755 index 0000000..9dbc0e5 --- /dev/null +++ b/src/Controller/AppController.php @@ -0,0 +1,98 @@ +. + * + * + * @author AVERWAY LTD + * @license GNU/GPLv3 or later; https://www.gnu.org/licenses/gpl.html + * @copyright 2017 AVERWAY LTD + * + * SophiMail is a registered trademark of AVERWAY LTD + * + */ +namespace App\Controller; + +use Cake\Controller\Controller; +use Cake\Event\Event; +use Cake\Core\Configure; + +/** + * Application Controller + * + * Add your application-wide methods in the class below, your controllers + * will inherit them. + * + * @link http://book.cakephp.org/3.0/en/controllers.html#the-app-controller + */ +class AppController extends Controller +{ + + /** + * Initialization hook method. + * + * Use this method to add common initialization code like loading components. + * + * e.g. `$this->loadComponent('Security');` + * + * @return void + */ + public function initialize() + { + parent::initialize(); + + $this->loadComponent('RequestHandler'); + $this->loadComponent('Flash'); + $this->loadComponent('CakeDC/Users.UsersAuth'); + $this->loadComponent('Global'); + + } + + /* + public function beforeFilter(Event $event) + { + $this->Security->config('unlockedActions', ['register']); + } + */ + + /** + * Before render callback. + * + * @param \Cake\Event\Event $event The beforeRender event. + * @return void + */ + public function beforeRender(Event $event) + { + if (!array_key_exists('_serialize', $this->viewVars) && + in_array($this->response->type(), ['application/json', 'application/xml']) + ) { + $this->set('_serialize', true); + } + } + + public function beforeFilter(Event $event){ + if ($this->Global->_UserDomainDatasourceExists()) { + Configure::write('_domain', $this->Global->_getDomain()); + Configure::write('_datasource', $this->Global->_getDatasource()); + } else { + $this->Global->_deleteParams(); + } + } +} diff --git a/src/Controller/Component/GlobalComponent.php b/src/Controller/Component/GlobalComponent.php new file mode 100755 index 0000000..599f50e --- /dev/null +++ b/src/Controller/Component/GlobalComponent.php @@ -0,0 +1,83 @@ +. + * + * + * @author AVERWAY LTD + * @license GNU/GPLv3 or later; https://www.gnu.org/licenses/gpl.html + * @copyright 2017 AVERWAY LTD + * + * SophiMail is a registered trademark of AVERWAY LTD + * + */ +namespace App\Controller\Component; + +use Cake\Controller\Component; +use Cake\ORM\TableRegistry; +use Cake\Core\Configure; + +class GlobalComponent extends Component +{ + + public function _deleteParams() { + $this->request->session()->delete('Auth.User.datasource'); + $this->request->session()->delete('Auth.User.domain'); + Configure::delete('_domain'); + Configure::delete('_datasource'); + } + + + public function _getDomain() { + if ($this->_UserDomainExists()) { + $results = TableRegistry::get('Shards')->get($this->request->session()->read('Auth.User.domain')); + return $results['domain']; + } + + return false; + } + + + public function _getDatasource() { + if ($this->_DomainDatasourceExists()) { + $results = TableRegistry::get('Accounts')->get($this->request->session()->read('Auth.User.datasource')); + return $results['datasource']; + } + + return false; + } + + + public function _UserDomainExists() { + if (($this->request->session()->read('Auth.User.id')) && ($this->request->session()->read('Auth.User.domain'))) + return TableRegistry::get('UsersShards')->exists(['user_id' => $this->request->session()->read('Auth.User.id'), 'shard_id' => $this->request->session()->read('Auth.User.domain')]); + } + + + public function _DomainDatasourceExists() { + if (($this->request->session()->read('Auth.User.datasource')) && ($this->request->session()->read('Auth.User.domain'))) + return TableRegistry::get('ShardsAccounts')->exists(['account_id' => $this->request->session()->read('Auth.User.datasource'), 'shard_id' => $this->request->session()->read('Auth.User.domain')]); + } + + + public function _UserDomainDatasourceExists() { + return (($this->_UserDomainExists()) && ($this->_DomainDatasourceExists())); + } +}