@@ -1,20 +1,20 @@ |
||
| 1 | 1 | <?php |
| 2 | 2 | |
| 3 | - /** |
|
| 4 | - * Add any string here that may be dynamicaly created and not verbatim in the source. |
|
| 5 | - * |
|
| 6 | - * In source |
|
| 7 | - * $a = bar; |
|
| 8 | - * $a = baz; |
|
| 9 | - * … |
|
| 10 | - * __('foo-'.$a); |
|
| 11 | - * |
|
| 12 | - * becomes |
|
| 13 | - * |
|
| 14 | - * __('foo-bar'); |
|
| 15 | - * __('foo_baz'); |
|
| 16 | - * |
|
| 17 | - * here. |
|
| 18 | - */ |
|
| 3 | + /** |
|
| 4 | + * Add any string here that may be dynamicaly created and not verbatim in the source. |
|
| 5 | + * |
|
| 6 | + * In source |
|
| 7 | + * $a = bar; |
|
| 8 | + * $a = baz; |
|
| 9 | + * … |
|
| 10 | + * __('foo-'.$a); |
|
| 11 | + * |
|
| 12 | + * becomes |
|
| 13 | + * |
|
| 14 | + * __('foo-bar'); |
|
| 15 | + * __('foo_baz'); |
|
| 16 | + * |
|
| 17 | + * here. |
|
| 18 | + */ |
|
| 19 | 19 | |
| 20 | 20 | ?> |
| 21 | 21 | \ No newline at end of file |
@@ -1,6 +1,6 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | 2 | |
| 3 | - App::uses('AppController', 'Controller'); |
|
| 3 | + App::uses('AppController', 'Controller'); |
|
| 4 | 4 | |
| 5 | 5 | /** |
| 6 | 6 | * Bookmarks Controller |
@@ -9,127 +9,127 @@ discard block |
||
| 9 | 9 | */ |
| 10 | 10 | class BookmarksController extends AppController { |
| 11 | 11 | |
| 12 | - public $helpers = ['EntryH']; |
|
| 12 | + public $helpers = ['EntryH']; |
|
| 13 | 13 | |
| 14 | 14 | /** |
| 15 | 15 | * @throws MethodNotAllowedException |
| 16 | 16 | */ |
| 17 | - public function index() { |
|
| 18 | - if (!$this->CurrentUser->isLoggedIn()) { |
|
| 19 | - throw new MethodNotAllowedException; |
|
| 20 | - } |
|
| 21 | - $bookmarks = $this->Bookmark->find('all', [ |
|
| 22 | - 'contain' => ['Entry' => ['Category', 'User']], |
|
| 23 | - 'conditions' => ['Bookmark.user_id' => $this->CurrentUser->getId()], |
|
| 24 | - 'order' => 'Bookmark.id DESC', |
|
| 25 | - ]); |
|
| 26 | - $this->set('bookmarks', $bookmarks); |
|
| 27 | - } |
|
| 17 | + public function index() { |
|
| 18 | + if (!$this->CurrentUser->isLoggedIn()) { |
|
| 19 | + throw new MethodNotAllowedException; |
|
| 20 | + } |
|
| 21 | + $bookmarks = $this->Bookmark->find('all', [ |
|
| 22 | + 'contain' => ['Entry' => ['Category', 'User']], |
|
| 23 | + 'conditions' => ['Bookmark.user_id' => $this->CurrentUser->getId()], |
|
| 24 | + 'order' => 'Bookmark.id DESC', |
|
| 25 | + ]); |
|
| 26 | + $this->set('bookmarks', $bookmarks); |
|
| 27 | + } |
|
| 28 | 28 | |
| 29 | 29 | /** |
| 30 | 30 | * @return bool |
| 31 | 31 | * @throws MethodNotAllowedException |
| 32 | 32 | * @throws BadRequestException |
| 33 | 33 | */ |
| 34 | - public function add() { |
|
| 35 | - if (!$this->request->is('ajax')) { |
|
| 36 | - throw new BadRequestException; |
|
| 37 | - } |
|
| 38 | - if (!$this->CurrentUser->isLoggedIn()) { |
|
| 39 | - throw new MethodNotAllowedException; |
|
| 40 | - } |
|
| 41 | - $this->autoRender = false; |
|
| 42 | - if (!$this->request->is('post')) { |
|
| 43 | - return false; |
|
| 44 | - } |
|
| 45 | - |
|
| 46 | - $data = [ |
|
| 47 | - 'user_id' => $this->CurrentUser->getId(), |
|
| 48 | - 'entry_id' => $this->request->data['id'], |
|
| 49 | - ]; |
|
| 50 | - $this->Bookmark->create(); |
|
| 51 | - return (bool)$this->Bookmark->save($data); |
|
| 52 | - } |
|
| 53 | - |
|
| 54 | - /** |
|
| 55 | - * @param null $id |
|
| 56 | - * @throws NotFoundException |
|
| 57 | - * @throws MethodNotAllowedException |
|
| 58 | - */ |
|
| 59 | - public function edit($id = null) { |
|
| 60 | - $bookmark = $this->_getBookmark($id); |
|
| 61 | - |
|
| 62 | - if (!$this->request->is('post') && !$this->request->is('put')) { |
|
| 63 | - $posting = array( |
|
| 64 | - 'Entry' => $bookmark['Entry'], |
|
| 65 | - 'Category' => $bookmark['Entry']['Category'], |
|
| 66 | - 'User' => $bookmark['Entry']['User'], |
|
| 67 | - ); |
|
| 68 | - $this->set('entry', $this->dic->newInstance('\Saito\Posting\Posting', |
|
| 69 | - ['rawData' => $posting])); |
|
| 70 | - $this->request->data = $bookmark; |
|
| 71 | - return; |
|
| 72 | - } |
|
| 73 | - |
|
| 74 | - $data['Bookmark'] = [ |
|
| 75 | - 'id' => $id, |
|
| 76 | - 'comment' => $this->request->data['Bookmark']['comment'] |
|
| 77 | - ]; |
|
| 78 | - $success = $this->Bookmark->save($data); |
|
| 79 | - if (!$success) { |
|
| 80 | - $this->Session->setFlash( |
|
| 81 | - __('The bookmark could not be saved. Please, try again.')); |
|
| 82 | - return; |
|
| 83 | - } |
|
| 84 | - $this->redirect(['action' => 'index', |
|
| 85 | - '#' => $bookmark['Bookmark']['entry_id']]); |
|
| 86 | - } |
|
| 34 | + public function add() { |
|
| 35 | + if (!$this->request->is('ajax')) { |
|
| 36 | + throw new BadRequestException; |
|
| 37 | + } |
|
| 38 | + if (!$this->CurrentUser->isLoggedIn()) { |
|
| 39 | + throw new MethodNotAllowedException; |
|
| 40 | + } |
|
| 41 | + $this->autoRender = false; |
|
| 42 | + if (!$this->request->is('post')) { |
|
| 43 | + return false; |
|
| 44 | + } |
|
| 45 | + |
|
| 46 | + $data = [ |
|
| 47 | + 'user_id' => $this->CurrentUser->getId(), |
|
| 48 | + 'entry_id' => $this->request->data['id'], |
|
| 49 | + ]; |
|
| 50 | + $this->Bookmark->create(); |
|
| 51 | + return (bool)$this->Bookmark->save($data); |
|
| 52 | + } |
|
| 53 | + |
|
| 54 | + /** |
|
| 55 | + * @param null $id |
|
| 56 | + * @throws NotFoundException |
|
| 57 | + * @throws MethodNotAllowedException |
|
| 58 | + */ |
|
| 59 | + public function edit($id = null) { |
|
| 60 | + $bookmark = $this->_getBookmark($id); |
|
| 61 | + |
|
| 62 | + if (!$this->request->is('post') && !$this->request->is('put')) { |
|
| 63 | + $posting = array( |
|
| 64 | + 'Entry' => $bookmark['Entry'], |
|
| 65 | + 'Category' => $bookmark['Entry']['Category'], |
|
| 66 | + 'User' => $bookmark['Entry']['User'], |
|
| 67 | + ); |
|
| 68 | + $this->set('entry', $this->dic->newInstance('\Saito\Posting\Posting', |
|
| 69 | + ['rawData' => $posting])); |
|
| 70 | + $this->request->data = $bookmark; |
|
| 71 | + return; |
|
| 72 | + } |
|
| 73 | + |
|
| 74 | + $data['Bookmark'] = [ |
|
| 75 | + 'id' => $id, |
|
| 76 | + 'comment' => $this->request->data['Bookmark']['comment'] |
|
| 77 | + ]; |
|
| 78 | + $success = $this->Bookmark->save($data); |
|
| 79 | + if (!$success) { |
|
| 80 | + $this->Session->setFlash( |
|
| 81 | + __('The bookmark could not be saved. Please, try again.')); |
|
| 82 | + return; |
|
| 83 | + } |
|
| 84 | + $this->redirect(['action' => 'index', |
|
| 85 | + '#' => $bookmark['Bookmark']['entry_id']]); |
|
| 86 | + } |
|
| 87 | 87 | |
| 88 | 88 | /** |
| 89 | 89 | * @param null $id |
| 90 | 90 | * @return bool |
| 91 | 91 | * @throws BadRequestException |
| 92 | 92 | */ |
| 93 | - public function delete($id = null) { |
|
| 94 | - if (!$this->request->is('ajax')) { |
|
| 95 | - throw new BadRequestException; |
|
| 96 | - } |
|
| 97 | - |
|
| 98 | - $this->_getBookmark($id, $this->CurrentUser->getId()); |
|
| 99 | - $this->autoRender = false; |
|
| 100 | - $this->Bookmark->id = $id; |
|
| 101 | - return (bool)$this->Bookmark->delete(); |
|
| 102 | - } |
|
| 103 | - |
|
| 104 | - public function beforeFilter() { |
|
| 105 | - parent::beforeFilter(); |
|
| 106 | - |
|
| 107 | - $this->Security->unlockedActions = ['add']; |
|
| 108 | - } |
|
| 109 | - |
|
| 110 | - /** |
|
| 111 | - * @param $id |
|
| 112 | - * @throws NotFoundException |
|
| 113 | - * @throws MethodNotAllowedException |
|
| 114 | - * @throws Saito\Exception\SaitoForbiddenException |
|
| 115 | - * @return mixed |
|
| 116 | - */ |
|
| 117 | - protected function _getBookmark($id) { |
|
| 118 | - if (!$this->CurrentUser->isLoggedIn()) { |
|
| 119 | - throw new MethodNotAllowedException; |
|
| 120 | - } |
|
| 121 | - |
|
| 122 | - if (!$this->Bookmark->exists($id)) { |
|
| 123 | - throw new NotFoundException(__('Invalid bookmark.')); |
|
| 124 | - } |
|
| 125 | - |
|
| 126 | - $this->Bookmark->contain(['Entry' => ['Category', 'User']]); |
|
| 127 | - $bookmark = $this->Bookmark->findById($id); |
|
| 128 | - |
|
| 129 | - if ($bookmark['Bookmark']['user_id'] != $this->CurrentUser->getId()) { |
|
| 130 | - throw new Saito\Exception\SaitoForbiddenException("Attempt to edit bookmark $id."); |
|
| 131 | - } |
|
| 132 | - return $bookmark; |
|
| 133 | - } |
|
| 93 | + public function delete($id = null) { |
|
| 94 | + if (!$this->request->is('ajax')) { |
|
| 95 | + throw new BadRequestException; |
|
| 96 | + } |
|
| 97 | + |
|
| 98 | + $this->_getBookmark($id, $this->CurrentUser->getId()); |
|
| 99 | + $this->autoRender = false; |
|
| 100 | + $this->Bookmark->id = $id; |
|
| 101 | + return (bool)$this->Bookmark->delete(); |
|
| 102 | + } |
|
| 103 | + |
|
| 104 | + public function beforeFilter() { |
|
| 105 | + parent::beforeFilter(); |
|
| 106 | + |
|
| 107 | + $this->Security->unlockedActions = ['add']; |
|
| 108 | + } |
|
| 109 | + |
|
| 110 | + /** |
|
| 111 | + * @param $id |
|
| 112 | + * @throws NotFoundException |
|
| 113 | + * @throws MethodNotAllowedException |
|
| 114 | + * @throws Saito\Exception\SaitoForbiddenException |
|
| 115 | + * @return mixed |
|
| 116 | + */ |
|
| 117 | + protected function _getBookmark($id) { |
|
| 118 | + if (!$this->CurrentUser->isLoggedIn()) { |
|
| 119 | + throw new MethodNotAllowedException; |
|
| 120 | + } |
|
| 121 | + |
|
| 122 | + if (!$this->Bookmark->exists($id)) { |
|
| 123 | + throw new NotFoundException(__('Invalid bookmark.')); |
|
| 124 | + } |
|
| 125 | + |
|
| 126 | + $this->Bookmark->contain(['Entry' => ['Category', 'User']]); |
|
| 127 | + $bookmark = $this->Bookmark->findById($id); |
|
| 128 | + |
|
| 129 | + if ($bookmark['Bookmark']['user_id'] != $this->CurrentUser->getId()) { |
|
| 130 | + throw new Saito\Exception\SaitoForbiddenException("Attempt to edit bookmark $id."); |
|
| 131 | + } |
|
| 132 | + return $bookmark; |
|
| 133 | + } |
|
| 134 | 134 | |
| 135 | 135 | } |
| 136 | 136 | \ No newline at end of file |
@@ -36,23 +36,23 @@ discard block |
||
| 36 | 36 | * |
| 37 | 37 | * @var string |
| 38 | 38 | */ |
| 39 | - public $name = 'Pages'; |
|
| 39 | + public $name = 'Pages'; |
|
| 40 | 40 | |
| 41 | 41 | /** |
| 42 | 42 | * Default helper |
| 43 | 43 | * |
| 44 | 44 | * @var array |
| 45 | 45 | */ |
| 46 | - public $helpers = array('Html', 'Session'); |
|
| 46 | + public $helpers = array('Html', 'Session'); |
|
| 47 | 47 | |
| 48 | 48 | /** |
| 49 | 49 | * This controller does not use a model |
| 50 | 50 | * |
| 51 | 51 | * @var array |
| 52 | 52 | */ |
| 53 | - public $uses = array(); |
|
| 53 | + public $uses = array(); |
|
| 54 | 54 | |
| 55 | - public $showDisclaimer = true; |
|
| 55 | + public $showDisclaimer = true; |
|
| 56 | 56 | |
| 57 | 57 | /** |
| 58 | 58 | * Displays a view |
@@ -60,25 +60,25 @@ discard block |
||
| 60 | 60 | * @param mixed What page to display |
| 61 | 61 | * @return void |
| 62 | 62 | */ |
| 63 | - public function display() { |
|
| 64 | - $path = func_get_args(); |
|
| 63 | + public function display() { |
|
| 64 | + $path = func_get_args(); |
|
| 65 | 65 | |
| 66 | - $count = count($path); |
|
| 67 | - if (!$count) { |
|
| 68 | - $this->redirect('/'); |
|
| 69 | - } |
|
| 70 | - $page = $subpage = $title_for_layout = null; |
|
| 66 | + $count = count($path); |
|
| 67 | + if (!$count) { |
|
| 68 | + $this->redirect('/'); |
|
| 69 | + } |
|
| 70 | + $page = $subpage = $title_for_layout = null; |
|
| 71 | 71 | |
| 72 | - if (!empty($path[0])) { |
|
| 73 | - $page = $path[0]; |
|
| 74 | - } |
|
| 75 | - if (!empty($path[1])) { |
|
| 76 | - $subpage = $path[1]; |
|
| 77 | - } |
|
| 78 | - if (!empty($path[$count - 1])) { |
|
| 79 | - $title_for_layout = Inflector::humanize($path[$count - 1]); |
|
| 80 | - } |
|
| 81 | - $this->set(compact('page', 'subpage', 'title_for_layout')); |
|
| 82 | - $this->render(implode('/', $path)); |
|
| 83 | - } |
|
| 72 | + if (!empty($path[0])) { |
|
| 73 | + $page = $path[0]; |
|
| 74 | + } |
|
| 75 | + if (!empty($path[1])) { |
|
| 76 | + $subpage = $path[1]; |
|
| 77 | + } |
|
| 78 | + if (!empty($path[$count - 1])) { |
|
| 79 | + $title_for_layout = Inflector::humanize($path[$count - 1]); |
|
| 80 | + } |
|
| 81 | + $this->set(compact('page', 'subpage', 'title_for_layout')); |
|
| 82 | + $this->render(implode('/', $path)); |
|
| 83 | + } |
|
| 84 | 84 | } |
@@ -1,52 +1,52 @@ |
||
| 1 | 1 | <?php |
| 2 | 2 | |
| 3 | - App::uses('AppController', 'Controller'); |
|
| 3 | + App::uses('AppController', 'Controller'); |
|
| 4 | 4 | |
| 5 | 5 | /** |
| 6 | 6 | * Tools Controller |
| 7 | 7 | * |
| 8 | 8 | * @property Tool $Tool |
| 9 | 9 | */ |
| 10 | - class ToolsController extends AppController { |
|
| 11 | - |
|
| 12 | - /** |
|
| 13 | - * Empty out all caches |
|
| 14 | - */ |
|
| 15 | - public function admin_emptyCaches() { |
|
| 16 | - $this->CacheSupport->clear(); |
|
| 17 | - $this->Session->setFlash(__('Caches cleared.'), 'flash/success'); |
|
| 18 | - return $this->redirect($this->referer()); |
|
| 19 | - } |
|
| 20 | - |
|
| 21 | - public function testJs() { |
|
| 22 | - if (Configure::read('debug') === 0) { |
|
| 23 | - echo 'Please activate debug mode.'; |
|
| 24 | - exit; |
|
| 25 | - } |
|
| 26 | - |
|
| 27 | - $this->autoLayout = false; |
|
| 28 | - } |
|
| 10 | + class ToolsController extends AppController { |
|
| 11 | + |
|
| 12 | + /** |
|
| 13 | + * Empty out all caches |
|
| 14 | + */ |
|
| 15 | + public function admin_emptyCaches() { |
|
| 16 | + $this->CacheSupport->clear(); |
|
| 17 | + $this->Session->setFlash(__('Caches cleared.'), 'flash/success'); |
|
| 18 | + return $this->redirect($this->referer()); |
|
| 19 | + } |
|
| 20 | + |
|
| 21 | + public function testJs() { |
|
| 22 | + if (Configure::read('debug') === 0) { |
|
| 23 | + echo 'Please activate debug mode.'; |
|
| 24 | + exit; |
|
| 25 | + } |
|
| 26 | + |
|
| 27 | + $this->autoLayout = false; |
|
| 28 | + } |
|
| 29 | 29 | |
| 30 | 30 | /** |
| 31 | 31 | * Gives a deploy script a mean to empty PHP's APC-cache |
| 32 | 32 | * |
| 33 | 33 | * @link https://github.com/jadb/capcake/wiki/Capcake-and-PHP-APC> |
| 34 | 34 | */ |
| 35 | - public function clearCache() { |
|
| 36 | - if (in_array(@$_SERVER['REMOTE_ADDR'], array('127.0.0.1', '::1'))) { |
|
| 37 | - $this->CacheSupport->clear(['Apc', 'OpCache']); |
|
| 38 | - echo json_encode(['Opcode Clear Cache' => true]); |
|
| 39 | - } |
|
| 40 | - exit; |
|
| 41 | - } |
|
| 42 | - |
|
| 43 | - public function beforeFilter() { |
|
| 44 | - parent::beforeFilter(); |
|
| 45 | - $this->Auth->allow( |
|
| 46 | - 'clearCache', |
|
| 47 | - 'testJs', |
|
| 48 | - 'langJs' |
|
| 49 | - ); |
|
| 50 | - } |
|
| 51 | - |
|
| 52 | - } |
|
| 53 | 35 | \ No newline at end of file |
| 36 | + public function clearCache() { |
|
| 37 | + if (in_array(@$_SERVER['REMOTE_ADDR'], array('127.0.0.1', '::1'))) { |
|
| 38 | + $this->CacheSupport->clear(['Apc', 'OpCache']); |
|
| 39 | + echo json_encode(['Opcode Clear Cache' => true]); |
|
| 40 | + } |
|
| 41 | + exit; |
|
| 42 | + } |
|
| 43 | + |
|
| 44 | + public function beforeFilter() { |
|
| 45 | + parent::beforeFilter(); |
|
| 46 | + $this->Auth->allow( |
|
| 47 | + 'clearCache', |
|
| 48 | + 'testJs', |
|
| 49 | + 'langJs' |
|
| 50 | + ); |
|
| 51 | + } |
|
| 52 | + |
|
| 53 | + } |
|
| 54 | 54 | \ No newline at end of file |
@@ -1,24 +1,24 @@ |
||
| 1 | 1 | <?php |
| 2 | 2 | |
| 3 | - use Saito\JsData; |
|
| 3 | + use Saito\JsData; |
|
| 4 | 4 | |
| 5 | - App::uses('Component', 'Controller'); |
|
| 5 | + App::uses('Component', 'Controller'); |
|
| 6 | 6 | |
| 7 | - class JsDataComponent extends Component { |
|
| 7 | + class JsDataComponent extends Component { |
|
| 8 | 8 | |
| 9 | - protected $_JsData; |
|
| 9 | + protected $_JsData; |
|
| 10 | 10 | |
| 11 | - public function startup(Controller $Controller) { |
|
| 12 | - $this->_JsData = JsData::getInstance(); |
|
| 13 | - } |
|
| 11 | + public function startup(Controller $Controller) { |
|
| 12 | + $this->_JsData = JsData::getInstance(); |
|
| 13 | + } |
|
| 14 | 14 | |
| 15 | - public function __call($method, $params) { |
|
| 16 | - $proxy = array($this->_JsData, $method); |
|
| 17 | - if (is_callable($proxy)) { |
|
| 18 | - return call_user_func_array($proxy, $params); |
|
| 19 | - } else { |
|
| 20 | - return parent::__call($method, $params); |
|
| 21 | - } |
|
| 22 | - } |
|
| 15 | + public function __call($method, $params) { |
|
| 16 | + $proxy = array($this->_JsData, $method); |
|
| 17 | + if (is_callable($proxy)) { |
|
| 18 | + return call_user_func_array($proxy, $params); |
|
| 19 | + } else { |
|
| 20 | + return parent::__call($method, $params); |
|
| 21 | + } |
|
| 22 | + } |
|
| 23 | 23 | |
| 24 | - } |
|
| 24 | + } |
|
@@ -1,79 +1,79 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | 2 | |
| 3 | - App::uses('Component', 'Controller'); |
|
| 4 | - App::uses('CakeEmail', 'Network/Email'); |
|
| 3 | + App::uses('Component', 'Controller'); |
|
| 4 | + App::uses('CakeEmail', 'Network/Email'); |
|
| 5 | 5 | |
| 6 | - class SaitoEmailComponent extends Component { |
|
| 6 | + class SaitoEmailComponent extends Component { |
|
| 7 | 7 | |
| 8 | - protected $_emailConfigExists = null; |
|
| 8 | + protected $_emailConfigExists = null; |
|
| 9 | 9 | |
| 10 | - protected $_User = null; |
|
| 10 | + protected $_User = null; |
|
| 11 | 11 | |
| 12 | - protected $_config = array(); |
|
| 12 | + protected $_config = array(); |
|
| 13 | 13 | |
| 14 | - protected $_viewVars = array(); |
|
| 14 | + protected $_viewVars = array(); |
|
| 15 | 15 | |
| 16 | - /** |
|
| 17 | - * @var array ['User' => ['username' => , 'user_email' =>] |
|
| 18 | - */ |
|
| 19 | - protected $_recipient = null; |
|
| 16 | + /** |
|
| 17 | + * @var array ['User' => ['username' => , 'user_email' =>] |
|
| 18 | + */ |
|
| 19 | + protected $_recipient = null; |
|
| 20 | 20 | |
| 21 | - /** |
|
| 22 | - * @var array ['User' => ['username' => , 'user_email' =>] |
|
| 23 | - */ |
|
| 24 | - protected $_sender = null; |
|
| 21 | + /** |
|
| 22 | + * @var array ['User' => ['username' => , 'user_email' =>] |
|
| 23 | + */ |
|
| 24 | + protected $_sender = null; |
|
| 25 | 25 | |
| 26 | - /** |
|
| 27 | - * @var CakeEmail |
|
| 28 | - */ |
|
| 29 | - protected $_CakeEmail; |
|
| 26 | + /** |
|
| 27 | + * @var CakeEmail |
|
| 28 | + */ |
|
| 29 | + protected $_CakeEmail; |
|
| 30 | 30 | |
| 31 | - protected $_webroot; |
|
| 31 | + protected $_webroot; |
|
| 32 | 32 | |
| 33 | - protected $_appAddress; |
|
| 33 | + protected $_appAddress; |
|
| 34 | 34 | |
| 35 | - protected $_addresses; |
|
| 35 | + protected $_addresses; |
|
| 36 | 36 | |
| 37 | - protected $_forumName; |
|
| 37 | + protected $_forumName; |
|
| 38 | 38 | |
| 39 | - protected $_headerSent; |
|
| 39 | + protected $_headerSent; |
|
| 40 | 40 | |
| 41 | - protected $_predefined = ['contact', 'main', 'register', 'system']; |
|
| 41 | + protected $_predefined = ['contact', 'main', 'register', 'system']; |
|
| 42 | 42 | |
| 43 | - public function startup(Controller $Controller) { |
|
| 44 | - $this->_webroot = $Controller->request->webroot; |
|
| 45 | - $this->_User = $Controller->User; |
|
| 46 | - } |
|
| 43 | + public function startup(Controller $Controller) { |
|
| 44 | + $this->_webroot = $Controller->request->webroot; |
|
| 45 | + $this->_User = $Controller->User; |
|
| 46 | + } |
|
| 47 | 47 | |
| 48 | - /** |
|
| 49 | - * init only if mail is actually send during request |
|
| 50 | - * |
|
| 51 | - * @throws InvalidArgumentException |
|
| 52 | - */ |
|
| 53 | - protected function _init() { |
|
| 54 | - if ($this->_addresses !== null) { |
|
| 55 | - return; |
|
| 56 | - } |
|
| 48 | + /** |
|
| 49 | + * init only if mail is actually send during request |
|
| 50 | + * |
|
| 51 | + * @throws InvalidArgumentException |
|
| 52 | + */ |
|
| 53 | + protected function _init() { |
|
| 54 | + if ($this->_addresses !== null) { |
|
| 55 | + return; |
|
| 56 | + } |
|
| 57 | 57 | |
| 58 | - $this->_addresses = [ |
|
| 59 | - 'main' => Configure::read('Saito.Settings.forum_email'), |
|
| 60 | - 'contact' => Configure::read('Saito.Settings.email_contact'), |
|
| 61 | - 'register' => Configure::read('Saito.Settings.email_register'), |
|
| 62 | - 'system' => Configure::read('Saito.Settings.email_system') |
|
| 63 | - ]; |
|
| 58 | + $this->_addresses = [ |
|
| 59 | + 'main' => Configure::read('Saito.Settings.forum_email'), |
|
| 60 | + 'contact' => Configure::read('Saito.Settings.email_contact'), |
|
| 61 | + 'register' => Configure::read('Saito.Settings.email_register'), |
|
| 62 | + 'system' => Configure::read('Saito.Settings.email_system') |
|
| 63 | + ]; |
|
| 64 | 64 | |
| 65 | - foreach ($this->_addresses as $title => $address) { |
|
| 66 | - if (empty($address)) { |
|
| 67 | - throw new InvalidArgumentException("Email address not set: $title"); |
|
| 68 | - } |
|
| 69 | - } |
|
| 65 | + foreach ($this->_addresses as $title => $address) { |
|
| 66 | + if (empty($address)) { |
|
| 67 | + throw new InvalidArgumentException("Email address not set: $title"); |
|
| 68 | + } |
|
| 69 | + } |
|
| 70 | 70 | |
| 71 | - $this->_emailConfigExists = file_exists(APP . 'Config' . DS . 'email' . '.php'); |
|
| 71 | + $this->_emailConfigExists = file_exists(APP . 'Config' . DS . 'email' . '.php'); |
|
| 72 | 72 | |
| 73 | - $this->_forumName = Configure::read('Saito.Settings.forum_name'); |
|
| 73 | + $this->_forumName = Configure::read('Saito.Settings.forum_name'); |
|
| 74 | 74 | |
| 75 | - $this->_CakeEmail = new CakeEmail(); |
|
| 76 | - } |
|
| 75 | + $this->_CakeEmail = new CakeEmail(); |
|
| 76 | + } |
|
| 77 | 77 | |
| 78 | 78 | /** |
| 79 | 79 | * |
@@ -89,172 +89,172 @@ discard block |
||
| 89 | 89 | * @param array $options |
| 90 | 90 | * @return array |
| 91 | 91 | */ |
| 92 | - public function email($options = array()) { |
|
| 93 | - $this->_init(); |
|
| 94 | - $this->_resetConfig(); |
|
| 95 | - $this->_config($options); |
|
| 96 | - $result = $this->_send($this->_config, $this->_viewVars); |
|
| 97 | - |
|
| 98 | - if (isset($options['ccsender']) && $options['ccsender'] === true) { |
|
| 99 | - $result = $this->_sendCopyToOriginalSender($this->_config, |
|
| 100 | - $this->_viewVars); |
|
| 101 | - } |
|
| 102 | - |
|
| 103 | - return $result; |
|
| 104 | - } |
|
| 105 | - |
|
| 106 | - protected function _resetConfig() { |
|
| 107 | - $this->_config = []; |
|
| 108 | - $this->_viewVars = []; |
|
| 109 | - $this->_CakeEmail->reset(); |
|
| 110 | - } |
|
| 111 | - |
|
| 112 | - protected function _config($params = []) { |
|
| 113 | - $defaults = [ |
|
| 114 | - 'viewVars' => [ |
|
| 115 | - 'webroot' => Router::fullBaseUrl() . $this->_webroot, |
|
| 116 | - ], |
|
| 117 | - ]; |
|
| 118 | - $params = array_merge_recursive($defaults, $params); |
|
| 119 | - |
|
| 120 | - $this->_initConfigFromFile(); |
|
| 121 | - |
|
| 122 | - $this->_sender = $this->_getSender($params['sender']); |
|
| 123 | - $this->_recipient = $this->_getRecipient($params['recipient']); |
|
| 124 | - |
|
| 125 | - $this->_config = [ |
|
| 126 | - 'from' => $this->_pA($this->_sender, |
|
| 127 | - $this->_sender['User']['username']), |
|
| 128 | - 'to' => $this->_recipient['User']['user_email'], |
|
| 129 | - 'subject' => $params['subject'], |
|
| 130 | - 'emailFormat' => 'text', |
|
| 131 | - ]; |
|
| 132 | - |
|
| 133 | - //# set 'sender' header |
|
| 134 | - $headerSender = $this->_getHeaderSender(); |
|
| 135 | - if ($headerSender) { |
|
| 136 | - $this->_config['sender'] = $headerSender; |
|
| 137 | - } |
|
| 138 | - |
|
| 139 | - if (isset($params['template'])) { |
|
| 140 | - $this->_config['template'] = $params['template']; |
|
| 141 | - } |
|
| 142 | - |
|
| 143 | - if (isset($params['message'])) { |
|
| 144 | - $this->_viewVars['message'] = $params['message']; |
|
| 145 | - } |
|
| 146 | - $this->_viewVars += $params['viewVars']; |
|
| 147 | - |
|
| 148 | - $this->_configTransport(); |
|
| 149 | - } |
|
| 150 | - |
|
| 151 | - protected function _configTransport() { |
|
| 152 | - if (Configure::read('debug') > 2 || Configure::read('Saito.Debug.email')) { |
|
| 153 | - $this->_config['transport'] = 'Debug'; |
|
| 154 | - }; |
|
| 155 | - if (Configure::read('debug') > 2) { |
|
| 156 | - $this->_config['log'] = true; |
|
| 157 | - }; |
|
| 158 | - } |
|
| 159 | - |
|
| 160 | - protected function _getHeaderSender() { |
|
| 161 | - if ($this->_emailConfigExists && $this->_CakeEmail->from()) { |
|
| 162 | - // set the forum app address from email.php |
|
| 163 | - $hs = $this->_CakeEmail->from(); |
|
| 164 | - |
|
| 165 | - // set app address name to forum's name if it's not set in email.php |
|
| 166 | - if ((is_array($hs) && key($hs) === current($hs))) { |
|
| 167 | - $hs = $this->_pA(key($hs)); |
|
| 168 | - } |
|
| 169 | - } elseif ($this->_headerSent) { |
|
| 170 | - $type = $this->_headerSent; |
|
| 171 | - $hs = $this->_pA($this->_addresses[$type]); |
|
| 172 | - } else { |
|
| 173 | - $hs = false; |
|
| 174 | - } |
|
| 175 | - return $hs; |
|
| 176 | - } |
|
| 177 | - |
|
| 178 | - /** |
|
| 179 | - * returns participant array (Cake mail array) |
|
| 180 | - * |
|
| 181 | - * @param $address string with address or ['User']-sender/recipient |
|
| 182 | - * @param $name |
|
| 183 | - * @return array [<address> => <name>] |
|
| 184 | - */ |
|
| 185 | - protected function _pA($address, $name = null) { |
|
| 186 | - if (is_array($address) && isset($address['User'])) { |
|
| 187 | - $name = $address['User']['username']; |
|
| 188 | - $address = $address['User']['user_email']; |
|
| 189 | - } |
|
| 190 | - if ($name === null) { |
|
| 191 | - $name = $this->_forumName; |
|
| 192 | - } |
|
| 193 | - return [$address => $name]; |
|
| 194 | - } |
|
| 195 | - |
|
| 196 | - /** |
|
| 197 | - * set base config from app/config/email.php |
|
| 198 | - */ |
|
| 199 | - protected function _initConfigFromFile() { |
|
| 200 | - if (!$this->_emailConfigExists) { |
|
| 201 | - return; |
|
| 202 | - } |
|
| 203 | - $this->_CakeEmail->config('saito'); |
|
| 204 | - } |
|
| 205 | - |
|
| 206 | - public function getPredefinedSender($type) { |
|
| 207 | - $this->_init(); |
|
| 208 | - return ['User' => [ |
|
| 209 | - 'username' => $this->_forumName, |
|
| 210 | - 'user_email' => $this->_addresses[$type] |
|
| 211 | - ]]; |
|
| 212 | - } |
|
| 213 | - |
|
| 214 | - protected function _getRecipient($recipient) { |
|
| 215 | - return $this->_getParticipant($recipient); |
|
| 216 | - } |
|
| 217 | - |
|
| 218 | - protected function _getSender($sender) { |
|
| 219 | - if (!is_string($sender) || |
|
| 220 | - !in_array($sender, $this->_predefined) |
|
| 221 | - ) { |
|
| 222 | - // sender-address does not belong to system: is external address |
|
| 223 | - // and should be send 'in behalf off' |
|
| 224 | - $this->_headerSent = 'system'; |
|
| 225 | - } |
|
| 226 | - return $this->_getParticipant($sender); |
|
| 227 | - } |
|
| 228 | - |
|
| 229 | - /** |
|
| 230 | - * @param $value |
|
| 231 | - * @return array |
|
| 232 | - * @throws Exception |
|
| 233 | - */ |
|
| 234 | - protected function _getParticipant($value) { |
|
| 235 | - //# participant-address is valid address |
|
| 236 | - if (is_array($value)) { |
|
| 237 | - return $value; |
|
| 238 | - } |
|
| 239 | - |
|
| 240 | - //# participant-address belongs to system |
|
| 241 | - if (is_string($value) && |
|
| 242 | - in_array($value, $this->_predefined) |
|
| 243 | - ) { |
|
| 244 | - return $this->getPredefinedSender($value); |
|
| 245 | - } |
|
| 246 | - |
|
| 247 | - //# participant-address belongs to external user |
|
| 248 | - $this->_User->id = $value; |
|
| 249 | - $this->_User->contain(); |
|
| 250 | - $participant = $this->_User->read(); |
|
| 251 | - |
|
| 252 | - if (empty($participant)) { |
|
| 253 | - throw new Exception("Can't find participant for email."); |
|
| 254 | - } |
|
| 255 | - |
|
| 256 | - return $participant; |
|
| 257 | - } |
|
| 92 | + public function email($options = array()) { |
|
| 93 | + $this->_init(); |
|
| 94 | + $this->_resetConfig(); |
|
| 95 | + $this->_config($options); |
|
| 96 | + $result = $this->_send($this->_config, $this->_viewVars); |
|
| 97 | + |
|
| 98 | + if (isset($options['ccsender']) && $options['ccsender'] === true) { |
|
| 99 | + $result = $this->_sendCopyToOriginalSender($this->_config, |
|
| 100 | + $this->_viewVars); |
|
| 101 | + } |
|
| 102 | + |
|
| 103 | + return $result; |
|
| 104 | + } |
|
| 105 | + |
|
| 106 | + protected function _resetConfig() { |
|
| 107 | + $this->_config = []; |
|
| 108 | + $this->_viewVars = []; |
|
| 109 | + $this->_CakeEmail->reset(); |
|
| 110 | + } |
|
| 111 | + |
|
| 112 | + protected function _config($params = []) { |
|
| 113 | + $defaults = [ |
|
| 114 | + 'viewVars' => [ |
|
| 115 | + 'webroot' => Router::fullBaseUrl() . $this->_webroot, |
|
| 116 | + ], |
|
| 117 | + ]; |
|
| 118 | + $params = array_merge_recursive($defaults, $params); |
|
| 119 | + |
|
| 120 | + $this->_initConfigFromFile(); |
|
| 121 | + |
|
| 122 | + $this->_sender = $this->_getSender($params['sender']); |
|
| 123 | + $this->_recipient = $this->_getRecipient($params['recipient']); |
|
| 124 | + |
|
| 125 | + $this->_config = [ |
|
| 126 | + 'from' => $this->_pA($this->_sender, |
|
| 127 | + $this->_sender['User']['username']), |
|
| 128 | + 'to' => $this->_recipient['User']['user_email'], |
|
| 129 | + 'subject' => $params['subject'], |
|
| 130 | + 'emailFormat' => 'text', |
|
| 131 | + ]; |
|
| 132 | + |
|
| 133 | + //# set 'sender' header |
|
| 134 | + $headerSender = $this->_getHeaderSender(); |
|
| 135 | + if ($headerSender) { |
|
| 136 | + $this->_config['sender'] = $headerSender; |
|
| 137 | + } |
|
| 138 | + |
|
| 139 | + if (isset($params['template'])) { |
|
| 140 | + $this->_config['template'] = $params['template']; |
|
| 141 | + } |
|
| 142 | + |
|
| 143 | + if (isset($params['message'])) { |
|
| 144 | + $this->_viewVars['message'] = $params['message']; |
|
| 145 | + } |
|
| 146 | + $this->_viewVars += $params['viewVars']; |
|
| 147 | + |
|
| 148 | + $this->_configTransport(); |
|
| 149 | + } |
|
| 150 | + |
|
| 151 | + protected function _configTransport() { |
|
| 152 | + if (Configure::read('debug') > 2 || Configure::read('Saito.Debug.email')) { |
|
| 153 | + $this->_config['transport'] = 'Debug'; |
|
| 154 | + }; |
|
| 155 | + if (Configure::read('debug') > 2) { |
|
| 156 | + $this->_config['log'] = true; |
|
| 157 | + }; |
|
| 158 | + } |
|
| 159 | + |
|
| 160 | + protected function _getHeaderSender() { |
|
| 161 | + if ($this->_emailConfigExists && $this->_CakeEmail->from()) { |
|
| 162 | + // set the forum app address from email.php |
|
| 163 | + $hs = $this->_CakeEmail->from(); |
|
| 164 | + |
|
| 165 | + // set app address name to forum's name if it's not set in email.php |
|
| 166 | + if ((is_array($hs) && key($hs) === current($hs))) { |
|
| 167 | + $hs = $this->_pA(key($hs)); |
|
| 168 | + } |
|
| 169 | + } elseif ($this->_headerSent) { |
|
| 170 | + $type = $this->_headerSent; |
|
| 171 | + $hs = $this->_pA($this->_addresses[$type]); |
|
| 172 | + } else { |
|
| 173 | + $hs = false; |
|
| 174 | + } |
|
| 175 | + return $hs; |
|
| 176 | + } |
|
| 177 | + |
|
| 178 | + /** |
|
| 179 | + * returns participant array (Cake mail array) |
|
| 180 | + * |
|
| 181 | + * @param $address string with address or ['User']-sender/recipient |
|
| 182 | + * @param $name |
|
| 183 | + * @return array [<address> => <name>] |
|
| 184 | + */ |
|
| 185 | + protected function _pA($address, $name = null) { |
|
| 186 | + if (is_array($address) && isset($address['User'])) { |
|
| 187 | + $name = $address['User']['username']; |
|
| 188 | + $address = $address['User']['user_email']; |
|
| 189 | + } |
|
| 190 | + if ($name === null) { |
|
| 191 | + $name = $this->_forumName; |
|
| 192 | + } |
|
| 193 | + return [$address => $name]; |
|
| 194 | + } |
|
| 195 | + |
|
| 196 | + /** |
|
| 197 | + * set base config from app/config/email.php |
|
| 198 | + */ |
|
| 199 | + protected function _initConfigFromFile() { |
|
| 200 | + if (!$this->_emailConfigExists) { |
|
| 201 | + return; |
|
| 202 | + } |
|
| 203 | + $this->_CakeEmail->config('saito'); |
|
| 204 | + } |
|
| 205 | + |
|
| 206 | + public function getPredefinedSender($type) { |
|
| 207 | + $this->_init(); |
|
| 208 | + return ['User' => [ |
|
| 209 | + 'username' => $this->_forumName, |
|
| 210 | + 'user_email' => $this->_addresses[$type] |
|
| 211 | + ]]; |
|
| 212 | + } |
|
| 213 | + |
|
| 214 | + protected function _getRecipient($recipient) { |
|
| 215 | + return $this->_getParticipant($recipient); |
|
| 216 | + } |
|
| 217 | + |
|
| 218 | + protected function _getSender($sender) { |
|
| 219 | + if (!is_string($sender) || |
|
| 220 | + !in_array($sender, $this->_predefined) |
|
| 221 | + ) { |
|
| 222 | + // sender-address does not belong to system: is external address |
|
| 223 | + // and should be send 'in behalf off' |
|
| 224 | + $this->_headerSent = 'system'; |
|
| 225 | + } |
|
| 226 | + return $this->_getParticipant($sender); |
|
| 227 | + } |
|
| 228 | + |
|
| 229 | + /** |
|
| 230 | + * @param $value |
|
| 231 | + * @return array |
|
| 232 | + * @throws Exception |
|
| 233 | + */ |
|
| 234 | + protected function _getParticipant($value) { |
|
| 235 | + //# participant-address is valid address |
|
| 236 | + if (is_array($value)) { |
|
| 237 | + return $value; |
|
| 238 | + } |
|
| 239 | + |
|
| 240 | + //# participant-address belongs to system |
|
| 241 | + if (is_string($value) && |
|
| 242 | + in_array($value, $this->_predefined) |
|
| 243 | + ) { |
|
| 244 | + return $this->getPredefinedSender($value); |
|
| 245 | + } |
|
| 246 | + |
|
| 247 | + //# participant-address belongs to external user |
|
| 248 | + $this->_User->id = $value; |
|
| 249 | + $this->_User->contain(); |
|
| 250 | + $participant = $this->_User->read(); |
|
| 251 | + |
|
| 252 | + if (empty($participant)) { |
|
| 253 | + throw new Exception("Can't find participant for email."); |
|
| 254 | + } |
|
| 255 | + |
|
| 256 | + return $participant; |
|
| 257 | + } |
|
| 258 | 258 | |
| 259 | 259 | /** |
| 260 | 260 | * Sends a copy of a completely configured email to the author |
@@ -262,33 +262,33 @@ discard block |
||
| 262 | 262 | * @param $config |
| 263 | 263 | * @param $viewVars |
| 264 | 264 | */ |
| 265 | - protected function _sendCopyToOriginalSender($config, $viewVars) { |
|
| 266 | - // use name for recipient if available |
|
| 267 | - if (!empty($this->_recipient['User']['username'])) { |
|
| 268 | - $emailConfig['to'] = $this->_pA($this->_recipient['User']['user_email'], |
|
| 269 | - $this->_recipient['User']['username']); |
|
| 270 | - } |
|
| 271 | - |
|
| 272 | - // set new subject |
|
| 273 | - $data = array('subject' => $config['subject']); |
|
| 274 | - if (is_array($config['to'])) { |
|
| 275 | - $data['recipient-name'] = current($config['to']); |
|
| 276 | - $str = __('Copy of your message: ":subject" to ":recipient-name"'); |
|
| 277 | - } else { |
|
| 278 | - $str = __('Copy of your message: ":subject"'); |
|
| 279 | - } |
|
| 280 | - $config['subject'] = CakeText::insert($str, $data); |
|
| 281 | - |
|
| 282 | - // set new addresses |
|
| 283 | - $config['to'] = $config['from']; |
|
| 284 | - // @todo should be system message |
|
| 285 | - $config['from'] = $this->_pA($this->getPredefinedSender('system')); |
|
| 286 | - |
|
| 287 | - // CC is always send by system |
|
| 288 | - unset($config['sender']); |
|
| 289 | - |
|
| 290 | - return $this->_send($config, $viewVars); |
|
| 291 | - } |
|
| 265 | + protected function _sendCopyToOriginalSender($config, $viewVars) { |
|
| 266 | + // use name for recipient if available |
|
| 267 | + if (!empty($this->_recipient['User']['username'])) { |
|
| 268 | + $emailConfig['to'] = $this->_pA($this->_recipient['User']['user_email'], |
|
| 269 | + $this->_recipient['User']['username']); |
|
| 270 | + } |
|
| 271 | + |
|
| 272 | + // set new subject |
|
| 273 | + $data = array('subject' => $config['subject']); |
|
| 274 | + if (is_array($config['to'])) { |
|
| 275 | + $data['recipient-name'] = current($config['to']); |
|
| 276 | + $str = __('Copy of your message: ":subject" to ":recipient-name"'); |
|
| 277 | + } else { |
|
| 278 | + $str = __('Copy of your message: ":subject"'); |
|
| 279 | + } |
|
| 280 | + $config['subject'] = CakeText::insert($str, $data); |
|
| 281 | + |
|
| 282 | + // set new addresses |
|
| 283 | + $config['to'] = $config['from']; |
|
| 284 | + // @todo should be system message |
|
| 285 | + $config['from'] = $this->_pA($this->getPredefinedSender('system')); |
|
| 286 | + |
|
| 287 | + // CC is always send by system |
|
| 288 | + unset($config['sender']); |
|
| 289 | + |
|
| 290 | + return $this->_send($config, $viewVars); |
|
| 291 | + } |
|
| 292 | 292 | |
| 293 | 293 | /** |
| 294 | 294 | * Sends the completely configured email |
@@ -296,12 +296,12 @@ discard block |
||
| 296 | 296 | * @param $config |
| 297 | 297 | * @param $viewVars |
| 298 | 298 | */ |
| 299 | - protected function _send($config, $viewVars) { |
|
| 300 | - $email = $this->_CakeEmail; |
|
| 301 | - // workaround for http://cakephp.lighthouseapp.com/projects/42648/tickets/2855-cakeemail-transports-have-ambiguous-config-behaviors |
|
| 302 | - $email->config(array_merge($this->_CakeEmail->config(), $config)); |
|
| 303 | - $email->viewVars($viewVars); |
|
| 304 | - return $email->send(); |
|
| 305 | - } |
|
| 306 | - |
|
| 307 | - } |
|
| 308 | 299 | \ No newline at end of file |
| 300 | + protected function _send($config, $viewVars) { |
|
| 301 | + $email = $this->_CakeEmail; |
|
| 302 | + // workaround for http://cakephp.lighthouseapp.com/projects/42648/tickets/2855-cakeemail-transports-have-ambiguous-config-behaviors |
|
| 303 | + $email->config(array_merge($this->_CakeEmail->config(), $config)); |
|
| 304 | + $email->viewVars($viewVars); |
|
| 305 | + return $email->send(); |
|
| 306 | + } |
|
| 307 | + |
|
| 308 | + } |
|
| 309 | 309 | \ No newline at end of file |
@@ -1,318 +1,318 @@ |
||
| 1 | 1 | <?php |
| 2 | 2 | |
| 3 | - use Saito\User\Auth\CategoryAuthorization; |
|
| 4 | - use Saito\User\Bookmarks; |
|
| 5 | - use Saito\User\ForumsUserInterface; |
|
| 6 | - use Saito\User\LastRefresh; |
|
| 7 | - use Saito\User\ReadPostings; |
|
| 8 | - use Saito\User\SaitoUserTrait; |
|
| 3 | + use Saito\User\Auth\CategoryAuthorization; |
|
| 4 | + use Saito\User\Bookmarks; |
|
| 5 | + use Saito\User\ForumsUserInterface; |
|
| 6 | + use Saito\User\LastRefresh; |
|
| 7 | + use Saito\User\ReadPostings; |
|
| 8 | + use Saito\User\SaitoUserTrait; |
|
| 9 | 9 | |
| 10 | - App::uses('Component', 'Controller'); |
|
| 10 | + App::uses('Component', 'Controller'); |
|
| 11 | 11 | |
| 12 | - class CurrentUserComponent extends Component implements |
|
| 13 | - ArrayAccess, |
|
| 14 | - ForumsUserInterface { |
|
| 12 | + class CurrentUserComponent extends Component implements |
|
| 13 | + ArrayAccess, |
|
| 14 | + ForumsUserInterface { |
|
| 15 | 15 | |
| 16 | - use SaitoUserTrait; |
|
| 16 | + use SaitoUserTrait; |
|
| 17 | 17 | |
| 18 | - /** |
|
| 19 | - * @var Saito\User\Auth\CategoryAuthorization |
|
| 20 | - */ |
|
| 21 | - public $Categories; |
|
| 18 | + /** |
|
| 19 | + * @var Saito\User\Auth\CategoryAuthorization |
|
| 20 | + */ |
|
| 21 | + public $Categories; |
|
| 22 | 22 | |
| 23 | 23 | /** |
| 24 | 24 | * Component name |
| 25 | 25 | * |
| 26 | 26 | * @var string |
| 27 | 27 | */ |
| 28 | - public $name = 'CurrentUser'; |
|
| 28 | + public $name = 'CurrentUser'; |
|
| 29 | 29 | |
| 30 | 30 | /** |
| 31 | 31 | * Component's components |
| 32 | 32 | * |
| 33 | 33 | * @var array |
| 34 | 34 | */ |
| 35 | - public $components = ['Cookie', 'Cron.Cron']; |
|
| 35 | + public $components = ['Cookie', 'Cron.Cron']; |
|
| 36 | 36 | |
| 37 | 37 | /** |
| 38 | 38 | * Manages the persistent login cookie |
| 39 | 39 | * |
| 40 | 40 | * @var \Saito\User\Cookie\CurrentUserCookie |
| 41 | 41 | */ |
| 42 | - public $PersistentCookie = null; |
|
| 42 | + public $PersistentCookie = null; |
|
| 43 | 43 | |
| 44 | 44 | /** |
| 45 | 45 | * Manages the last refresh/mark entries as read for the current user |
| 46 | 46 | * |
| 47 | 47 | * @var \Saito\User\LastRefresh\LastRefreshAbstract |
| 48 | 48 | */ |
| 49 | - public $LastRefresh = null; |
|
| 49 | + public $LastRefresh = null; |
|
| 50 | 50 | |
| 51 | - /** |
|
| 52 | - * @var ReadPostings |
|
| 53 | - */ |
|
| 54 | - public $ReadEntries; |
|
| 51 | + /** |
|
| 52 | + * @var ReadPostings |
|
| 53 | + */ |
|
| 54 | + public $ReadEntries; |
|
| 55 | 55 | |
| 56 | - /** |
|
| 57 | - * @var Bookmarks bookmarks of the current user |
|
| 58 | - */ |
|
| 59 | - protected $_Bookmarks; |
|
| 56 | + /** |
|
| 57 | + * @var Bookmarks bookmarks of the current user |
|
| 58 | + */ |
|
| 59 | + protected $_Bookmarks; |
|
| 60 | 60 | |
| 61 | 61 | /** |
| 62 | 62 | * Model User instance exclusive to the CurrentUserComponent |
| 63 | 63 | * |
| 64 | 64 | * @var User |
| 65 | 65 | */ |
| 66 | - protected $_User = null; |
|
| 66 | + protected $_User = null; |
|
| 67 | 67 | |
| 68 | 68 | /** |
| 69 | 69 | * Reference to the controller |
| 70 | 70 | * |
| 71 | 71 | * @var Controller |
| 72 | 72 | */ |
| 73 | - protected $_Controller = null; |
|
| 73 | + protected $_Controller = null; |
|
| 74 | 74 | |
| 75 | - public function initialize(Controller $Controller) { |
|
| 76 | - if ($Controller->name === 'CakeError') { |
|
| 77 | - return; |
|
| 78 | - } |
|
| 75 | + public function initialize(Controller $Controller) { |
|
| 76 | + if ($Controller->name === 'CakeError') { |
|
| 77 | + return; |
|
| 78 | + } |
|
| 79 | 79 | |
| 80 | - $this->_Controller = $Controller; |
|
| 81 | - if ($this->_Controller->modelClass) { |
|
| 82 | - $this->_Controller->{$this->_Controller->modelClass}->SharedObjects['CurrentUser'] = $this; |
|
| 83 | - } |
|
| 84 | - $this->Categories = new CategoryAuthorization($this); |
|
| 80 | + $this->_Controller = $Controller; |
|
| 81 | + if ($this->_Controller->modelClass) { |
|
| 82 | + $this->_Controller->{$this->_Controller->modelClass}->SharedObjects['CurrentUser'] = $this; |
|
| 83 | + } |
|
| 84 | + $this->Categories = new CategoryAuthorization($this); |
|
| 85 | 85 | |
| 86 | - $this->_Controller->dic->set('CU', $this); |
|
| 86 | + $this->_Controller->dic->set('CU', $this); |
|
| 87 | 87 | |
| 88 | - /* |
|
| 88 | + /* |
|
| 89 | 89 | * We create a new User Model instance. Otherwise we would overwrite $this->request->data |
| 90 | 90 | * when reading in refresh(), causing error e.g. saving the user prefs. |
| 91 | 91 | */ |
| 92 | - $this->_User = ClassRegistry::init( |
|
| 93 | - ['class' => 'User', 'alias' => 'currentUser'] |
|
| 94 | - ); |
|
| 95 | - |
|
| 96 | - $this->PersistentCookie = new \Saito\User\Cookie\CurrentUserCookie($this->Cookie, 'AU'); |
|
| 97 | - |
|
| 98 | - $this->_configureAuth(); |
|
| 99 | - |
|
| 100 | - // prevents session auto re-login from form's request->data: login is |
|
| 101 | - // called explicitly by controller on /users/login |
|
| 102 | - if ($this->_Controller->action !== 'login') { |
|
| 103 | - if (!$this->_reLoginSession()) { |
|
| 104 | - // don't auto-login on login related pages |
|
| 105 | - if ($this->_Controller->params['action'] !== 'login' && |
|
| 106 | - $this->_Controller->params['action'] !== 'register' && |
|
| 107 | - $this->_Controller->referer() !== '/users/login' |
|
| 108 | - ) { |
|
| 109 | - $this->_reLoginCookie(); |
|
| 110 | - } |
|
| 111 | - } |
|
| 112 | - } |
|
| 113 | - |
|
| 114 | - if ($this->isLoggedIn()) { |
|
| 115 | - $this->ReadEntries = new ReadPostings\ReadPostingsDatabase($this); |
|
| 116 | - } elseif ($this->isBot()) { |
|
| 117 | - $this->ReadEntries = new ReadPostings\ReadPostingsDummy($this); |
|
| 118 | - } else { |
|
| 119 | - $this->ReadEntries = new ReadPostings\ReadPostingsCookie($this); |
|
| 120 | - } |
|
| 121 | - |
|
| 122 | - $this->_Bookmarks = new Bookmarks($this); |
|
| 123 | - |
|
| 124 | - $this->_markOnline(); |
|
| 125 | - } |
|
| 126 | - |
|
| 127 | - public function startup(Controller $controller) { |
|
| 128 | - parent::startup($controller); |
|
| 129 | - |
|
| 130 | - if ($controller->action !== 'logout' && $this->isLoggedIn()) : |
|
| 131 | - if ($this->isForbidden()) : |
|
| 132 | - $this->_Controller->redirect( |
|
| 133 | - ['controller' => 'users', 'action' => 'logout'] |
|
| 134 | - ); |
|
| 135 | - endif; |
|
| 136 | - endif; |
|
| 137 | - } |
|
| 92 | + $this->_User = ClassRegistry::init( |
|
| 93 | + ['class' => 'User', 'alias' => 'currentUser'] |
|
| 94 | + ); |
|
| 95 | + |
|
| 96 | + $this->PersistentCookie = new \Saito\User\Cookie\CurrentUserCookie($this->Cookie, 'AU'); |
|
| 97 | + |
|
| 98 | + $this->_configureAuth(); |
|
| 99 | + |
|
| 100 | + // prevents session auto re-login from form's request->data: login is |
|
| 101 | + // called explicitly by controller on /users/login |
|
| 102 | + if ($this->_Controller->action !== 'login') { |
|
| 103 | + if (!$this->_reLoginSession()) { |
|
| 104 | + // don't auto-login on login related pages |
|
| 105 | + if ($this->_Controller->params['action'] !== 'login' && |
|
| 106 | + $this->_Controller->params['action'] !== 'register' && |
|
| 107 | + $this->_Controller->referer() !== '/users/login' |
|
| 108 | + ) { |
|
| 109 | + $this->_reLoginCookie(); |
|
| 110 | + } |
|
| 111 | + } |
|
| 112 | + } |
|
| 113 | + |
|
| 114 | + if ($this->isLoggedIn()) { |
|
| 115 | + $this->ReadEntries = new ReadPostings\ReadPostingsDatabase($this); |
|
| 116 | + } elseif ($this->isBot()) { |
|
| 117 | + $this->ReadEntries = new ReadPostings\ReadPostingsDummy($this); |
|
| 118 | + } else { |
|
| 119 | + $this->ReadEntries = new ReadPostings\ReadPostingsCookie($this); |
|
| 120 | + } |
|
| 121 | + |
|
| 122 | + $this->_Bookmarks = new Bookmarks($this); |
|
| 123 | + |
|
| 124 | + $this->_markOnline(); |
|
| 125 | + } |
|
| 126 | + |
|
| 127 | + public function startup(Controller $controller) { |
|
| 128 | + parent::startup($controller); |
|
| 129 | + |
|
| 130 | + if ($controller->action !== 'logout' && $this->isLoggedIn()) : |
|
| 131 | + if ($this->isForbidden()) : |
|
| 132 | + $this->_Controller->redirect( |
|
| 133 | + ['controller' => 'users', 'action' => 'logout'] |
|
| 134 | + ); |
|
| 135 | + endif; |
|
| 136 | + endif; |
|
| 137 | + } |
|
| 138 | 138 | |
| 139 | 139 | /** |
| 140 | 140 | * Marks users as online |
| 141 | 141 | */ |
| 142 | - protected function _markOnline() { |
|
| 143 | - Stopwatch::start('CurrentUser->_markOnline()'); |
|
| 144 | - $_isLoggedIn = $this->isLoggedIn(); |
|
| 145 | - if ($_isLoggedIn) { |
|
| 146 | - $_id = $this->getId(); |
|
| 147 | - } else { |
|
| 148 | - // don't count search bots as guests |
|
| 149 | - if ($this->isBot()) { |
|
| 150 | - return; |
|
| 151 | - } |
|
| 152 | - $_id = $this->_Controller->Session->id(); |
|
| 153 | - } |
|
| 154 | - $this->_User->UserOnline->setOnline($_id, $_isLoggedIn); |
|
| 155 | - Stopwatch::stop('CurrentUser->_markOnline()'); |
|
| 156 | - } |
|
| 157 | - |
|
| 158 | - /** |
|
| 159 | - * Detects if the current user is a bot |
|
| 160 | - * |
|
| 161 | - * @return boolean |
|
| 162 | - */ |
|
| 163 | - public function isBot() { |
|
| 164 | - return $this->_Controller->request->is('bot'); |
|
| 165 | - } |
|
| 166 | - |
|
| 167 | - /** |
|
| 168 | - * Logs-in registered users |
|
| 169 | - * |
|
| 170 | - * @param null|array $user user-data, if null request-data is used |
|
| 171 | - * @return bool true if user is logged in false otherwise |
|
| 172 | - */ |
|
| 173 | - protected function _login($user = null) { |
|
| 174 | - $this->_Controller->Auth->login($user); |
|
| 175 | - $this->refresh(); |
|
| 176 | - return $this->isLoggedIn(); |
|
| 177 | - } |
|
| 178 | - |
|
| 179 | - protected function _reLoginSession() { |
|
| 180 | - return $this->_login(); |
|
| 181 | - } |
|
| 182 | - |
|
| 183 | - protected function _reLoginCookie() { |
|
| 184 | - $cookie = $this->PersistentCookie->read(); |
|
| 185 | - if ($cookie) { |
|
| 186 | - $this->_login($cookie); |
|
| 187 | - return $this->isLoggedIn(); |
|
| 188 | - } |
|
| 189 | - return false; |
|
| 190 | - } |
|
| 191 | - |
|
| 192 | - public function login() { |
|
| 193 | - // non-logged in session-id is lost after successful login |
|
| 194 | - $sessionId = session_id(); |
|
| 195 | - |
|
| 196 | - if (!$this->_login()) { |
|
| 197 | - return false; |
|
| 198 | - } |
|
| 199 | - |
|
| 200 | - $this->_User->incrementLogins($this->getId()); |
|
| 201 | - $this->_User->UserOnline->setOffline($sessionId); |
|
| 202 | - //password update |
|
| 203 | - if (empty($this->_Controller->request->data['User']['password']) === false) { |
|
| 204 | - $this->_User->autoUpdatePassword( |
|
| 205 | - $this->getId(), |
|
| 206 | - $this->_Controller->request->data['User']['password'] |
|
| 207 | - ); |
|
| 208 | - } |
|
| 209 | - |
|
| 210 | - // set cookie |
|
| 211 | - if (empty($this->_Controller->request->data['User']['remember_me']) === false) { |
|
| 212 | - $this->PersistentCookie->write($this); |
|
| 213 | - }; |
|
| 214 | - |
|
| 215 | - return true; |
|
| 216 | - } |
|
| 217 | - |
|
| 218 | - /** |
|
| 219 | - * Sets user-data |
|
| 220 | - */ |
|
| 221 | - public function refresh() { |
|
| 222 | - // preliminary set user-data from Cake's Auth handler |
|
| 223 | - $this->setSettings($this->_Controller->Auth->user()); |
|
| 224 | - // set user-data from current DB data: ensures that *all sessions* |
|
| 225 | - // use the same set of data (user got locked, user-type was demoted …) |
|
| 226 | - if ($this->isLoggedIn()) { |
|
| 227 | - $this->_User->id = $this->getId(); |
|
| 228 | - $this->setSettings($this->_User->getProfile($this->getId())); |
|
| 229 | - $this->LastRefresh = new LastRefresh\LastRefreshDatabase($this); |
|
| 230 | - } elseif ($this->isBot()) { |
|
| 231 | - $this->LastRefresh = new LastRefresh\LastRefreshDummy($this); |
|
| 232 | - } else { |
|
| 233 | - $this->LastRefresh = new LastRefresh\LastRefreshCookie($this); |
|
| 234 | - } |
|
| 235 | - } |
|
| 236 | - |
|
| 237 | - public function logout() { |
|
| 238 | - if (!$this->isLoggedIn()) { |
|
| 239 | - return; |
|
| 240 | - } |
|
| 241 | - $this->PersistentCookie->delete(); |
|
| 242 | - $this->_User->id = $this->getId(); |
|
| 243 | - $this->_User->UserOnline->setOffline($this->getId()); |
|
| 244 | - $this->setSettings(null); |
|
| 245 | - $this->_Controller->Auth->logout(); |
|
| 246 | - } |
|
| 247 | - |
|
| 248 | - public function shutdown(Controller $Controller) { |
|
| 249 | - $this->_writeSession($Controller); |
|
| 250 | - } |
|
| 251 | - |
|
| 252 | - public function beforeRedirect(Controller $Controller, $url, $status = null, $exit = true) { |
|
| 253 | - $this->_writeSession($Controller); |
|
| 254 | - } |
|
| 255 | - |
|
| 256 | - public function beforeRender(Controller $Controller) { |
|
| 257 | - // write out the current user for access in the views |
|
| 258 | - $Controller->set('CurrentUser', $this); |
|
| 259 | - } |
|
| 260 | - |
|
| 261 | - public function getModel() { |
|
| 262 | - return $this->_User; |
|
| 263 | - } |
|
| 264 | - |
|
| 265 | - public function hasBookmarked($entryId) { |
|
| 266 | - return $this->_Bookmarks->isBookmarked($entryId); |
|
| 267 | - } |
|
| 142 | + protected function _markOnline() { |
|
| 143 | + Stopwatch::start('CurrentUser->_markOnline()'); |
|
| 144 | + $_isLoggedIn = $this->isLoggedIn(); |
|
| 145 | + if ($_isLoggedIn) { |
|
| 146 | + $_id = $this->getId(); |
|
| 147 | + } else { |
|
| 148 | + // don't count search bots as guests |
|
| 149 | + if ($this->isBot()) { |
|
| 150 | + return; |
|
| 151 | + } |
|
| 152 | + $_id = $this->_Controller->Session->id(); |
|
| 153 | + } |
|
| 154 | + $this->_User->UserOnline->setOnline($_id, $_isLoggedIn); |
|
| 155 | + Stopwatch::stop('CurrentUser->_markOnline()'); |
|
| 156 | + } |
|
| 157 | + |
|
| 158 | + /** |
|
| 159 | + * Detects if the current user is a bot |
|
| 160 | + * |
|
| 161 | + * @return boolean |
|
| 162 | + */ |
|
| 163 | + public function isBot() { |
|
| 164 | + return $this->_Controller->request->is('bot'); |
|
| 165 | + } |
|
| 166 | + |
|
| 167 | + /** |
|
| 168 | + * Logs-in registered users |
|
| 169 | + * |
|
| 170 | + * @param null|array $user user-data, if null request-data is used |
|
| 171 | + * @return bool true if user is logged in false otherwise |
|
| 172 | + */ |
|
| 173 | + protected function _login($user = null) { |
|
| 174 | + $this->_Controller->Auth->login($user); |
|
| 175 | + $this->refresh(); |
|
| 176 | + return $this->isLoggedIn(); |
|
| 177 | + } |
|
| 178 | + |
|
| 179 | + protected function _reLoginSession() { |
|
| 180 | + return $this->_login(); |
|
| 181 | + } |
|
| 182 | + |
|
| 183 | + protected function _reLoginCookie() { |
|
| 184 | + $cookie = $this->PersistentCookie->read(); |
|
| 185 | + if ($cookie) { |
|
| 186 | + $this->_login($cookie); |
|
| 187 | + return $this->isLoggedIn(); |
|
| 188 | + } |
|
| 189 | + return false; |
|
| 190 | + } |
|
| 191 | + |
|
| 192 | + public function login() { |
|
| 193 | + // non-logged in session-id is lost after successful login |
|
| 194 | + $sessionId = session_id(); |
|
| 195 | + |
|
| 196 | + if (!$this->_login()) { |
|
| 197 | + return false; |
|
| 198 | + } |
|
| 199 | + |
|
| 200 | + $this->_User->incrementLogins($this->getId()); |
|
| 201 | + $this->_User->UserOnline->setOffline($sessionId); |
|
| 202 | + //password update |
|
| 203 | + if (empty($this->_Controller->request->data['User']['password']) === false) { |
|
| 204 | + $this->_User->autoUpdatePassword( |
|
| 205 | + $this->getId(), |
|
| 206 | + $this->_Controller->request->data['User']['password'] |
|
| 207 | + ); |
|
| 208 | + } |
|
| 209 | + |
|
| 210 | + // set cookie |
|
| 211 | + if (empty($this->_Controller->request->data['User']['remember_me']) === false) { |
|
| 212 | + $this->PersistentCookie->write($this); |
|
| 213 | + }; |
|
| 214 | + |
|
| 215 | + return true; |
|
| 216 | + } |
|
| 217 | + |
|
| 218 | + /** |
|
| 219 | + * Sets user-data |
|
| 220 | + */ |
|
| 221 | + public function refresh() { |
|
| 222 | + // preliminary set user-data from Cake's Auth handler |
|
| 223 | + $this->setSettings($this->_Controller->Auth->user()); |
|
| 224 | + // set user-data from current DB data: ensures that *all sessions* |
|
| 225 | + // use the same set of data (user got locked, user-type was demoted …) |
|
| 226 | + if ($this->isLoggedIn()) { |
|
| 227 | + $this->_User->id = $this->getId(); |
|
| 228 | + $this->setSettings($this->_User->getProfile($this->getId())); |
|
| 229 | + $this->LastRefresh = new LastRefresh\LastRefreshDatabase($this); |
|
| 230 | + } elseif ($this->isBot()) { |
|
| 231 | + $this->LastRefresh = new LastRefresh\LastRefreshDummy($this); |
|
| 232 | + } else { |
|
| 233 | + $this->LastRefresh = new LastRefresh\LastRefreshCookie($this); |
|
| 234 | + } |
|
| 235 | + } |
|
| 236 | + |
|
| 237 | + public function logout() { |
|
| 238 | + if (!$this->isLoggedIn()) { |
|
| 239 | + return; |
|
| 240 | + } |
|
| 241 | + $this->PersistentCookie->delete(); |
|
| 242 | + $this->_User->id = $this->getId(); |
|
| 243 | + $this->_User->UserOnline->setOffline($this->getId()); |
|
| 244 | + $this->setSettings(null); |
|
| 245 | + $this->_Controller->Auth->logout(); |
|
| 246 | + } |
|
| 247 | + |
|
| 248 | + public function shutdown(Controller $Controller) { |
|
| 249 | + $this->_writeSession($Controller); |
|
| 250 | + } |
|
| 251 | + |
|
| 252 | + public function beforeRedirect(Controller $Controller, $url, $status = null, $exit = true) { |
|
| 253 | + $this->_writeSession($Controller); |
|
| 254 | + } |
|
| 255 | + |
|
| 256 | + public function beforeRender(Controller $Controller) { |
|
| 257 | + // write out the current user for access in the views |
|
| 258 | + $Controller->set('CurrentUser', $this); |
|
| 259 | + } |
|
| 260 | + |
|
| 261 | + public function getModel() { |
|
| 262 | + return $this->_User; |
|
| 263 | + } |
|
| 264 | + |
|
| 265 | + public function hasBookmarked($entryId) { |
|
| 266 | + return $this->_Bookmarks->isBookmarked($entryId); |
|
| 267 | + } |
|
| 268 | 268 | |
| 269 | 269 | /** |
| 270 | 270 | * write the settings to the session, so that they are available on next request |
| 271 | 271 | */ |
| 272 | - protected function _writeSession(&$controller) { |
|
| 273 | - if ($controller->action !== 'logout' && $controller->Auth->user()): |
|
| 274 | - $controller->Session->write( |
|
| 275 | - 'Auth.User', |
|
| 276 | - $this->getSettings() |
|
| 277 | - ); |
|
| 278 | - endif; |
|
| 279 | - } |
|
| 272 | + protected function _writeSession(&$controller) { |
|
| 273 | + if ($controller->action !== 'logout' && $controller->Auth->user()): |
|
| 274 | + $controller->Session->write( |
|
| 275 | + 'Auth.User', |
|
| 276 | + $this->getSettings() |
|
| 277 | + ); |
|
| 278 | + endif; |
|
| 279 | + } |
|
| 280 | 280 | |
| 281 | 281 | /** |
| 282 | 282 | * Configures the auth component |
| 283 | 283 | */ |
| 284 | - protected function _configureAuth() { |
|
| 285 | - // delegate authenticate method |
|
| 286 | - // $this->_Controller->Auth->authenticate = $this->_User; |
|
| 287 | - |
|
| 288 | - $this->_Controller->Auth->authenticate = [ |
|
| 289 | - AuthComponent::ALL => [ |
|
| 290 | - 'useModel' => 'User', |
|
| 291 | - 'contain' => false, |
|
| 292 | - 'scope' => [ |
|
| 293 | - // user has activated his account (e.g. email confirmation) |
|
| 294 | - 'User.activate_code' => 0, |
|
| 295 | - // user is not banned by admin or mod |
|
| 296 | - 'User.user_lock' => 0 |
|
| 297 | - ] |
|
| 298 | - ], |
|
| 299 | - // 'Mlf' and 'Mlf2' could be 'Form' with different passwordHasher, but |
|
| 300 | - // see: https://cakephp.lighthouseapp.com/projects/42648/tickets/3907-allow-multiple-passwordhasher-with-same-authenticate-class-in-auth-config#ticket-3907-1 |
|
| 301 | - 'Mlf', // mylittleforum 1 auth |
|
| 302 | - 'Mlf2', // mylittleforum 2 auth |
|
| 303 | - 'Form' => ['passwordHasher' => 'Blowfish'] // blowfish saito standard |
|
| 304 | - ]; |
|
| 305 | - |
|
| 306 | - if ($this->isLoggedIn()): |
|
| 307 | - $this->_Controller->Auth->allow(); |
|
| 308 | - else: |
|
| 309 | - $this->_Controller->Auth->deny(); |
|
| 310 | - endif; |
|
| 311 | - |
|
| 312 | - $this->_Controller->Auth->autoRedirect = false; // don't redirect after Auth->login() |
|
| 313 | - $this->_Controller->Auth->allow('display'); // access to static pages in views/pages is allowed |
|
| 314 | - $this->_Controller->Auth->authError = __('auth_autherror'); // l10n |
|
| 315 | - } |
|
| 316 | - |
|
| 317 | - } |
|
| 284 | + protected function _configureAuth() { |
|
| 285 | + // delegate authenticate method |
|
| 286 | + // $this->_Controller->Auth->authenticate = $this->_User; |
|
| 287 | + |
|
| 288 | + $this->_Controller->Auth->authenticate = [ |
|
| 289 | + AuthComponent::ALL => [ |
|
| 290 | + 'useModel' => 'User', |
|
| 291 | + 'contain' => false, |
|
| 292 | + 'scope' => [ |
|
| 293 | + // user has activated his account (e.g. email confirmation) |
|
| 294 | + 'User.activate_code' => 0, |
|
| 295 | + // user is not banned by admin or mod |
|
| 296 | + 'User.user_lock' => 0 |
|
| 297 | + ] |
|
| 298 | + ], |
|
| 299 | + // 'Mlf' and 'Mlf2' could be 'Form' with different passwordHasher, but |
|
| 300 | + // see: https://cakephp.lighthouseapp.com/projects/42648/tickets/3907-allow-multiple-passwordhasher-with-same-authenticate-class-in-auth-config#ticket-3907-1 |
|
| 301 | + 'Mlf', // mylittleforum 1 auth |
|
| 302 | + 'Mlf2', // mylittleforum 2 auth |
|
| 303 | + 'Form' => ['passwordHasher' => 'Blowfish'] // blowfish saito standard |
|
| 304 | + ]; |
|
| 305 | + |
|
| 306 | + if ($this->isLoggedIn()): |
|
| 307 | + $this->_Controller->Auth->allow(); |
|
| 308 | + else: |
|
| 309 | + $this->_Controller->Auth->deny(); |
|
| 310 | + endif; |
|
| 311 | + |
|
| 312 | + $this->_Controller->Auth->autoRedirect = false; // don't redirect after Auth->login() |
|
| 313 | + $this->_Controller->Auth->allow('display'); // access to static pages in views/pages is allowed |
|
| 314 | + $this->_Controller->Auth->authError = __('auth_autherror'); // l10n |
|
| 315 | + } |
|
| 316 | + |
|
| 317 | + } |
|
| 318 | 318 | |
@@ -305,8 +305,10 @@ |
||
| 305 | 305 | |
| 306 | 306 | if ($this->isLoggedIn()): |
| 307 | 307 | $this->_Controller->Auth->allow(); |
| 308 | - else: |
|
| 308 | + else { |
|
| 309 | + : |
|
| 309 | 310 | $this->_Controller->Auth->deny(); |
| 311 | + } |
|
| 310 | 312 | endif; |
| 311 | 313 | |
| 312 | 314 | $this->_Controller->Auth->autoRedirect = false; // don't redirect after Auth->login() |
@@ -1,42 +1,42 @@ |
||
| 1 | 1 | <?php |
| 2 | 2 | |
| 3 | - App::uses('Component', 'Controller'); |
|
| 3 | + App::uses('Component', 'Controller'); |
|
| 4 | 4 | |
| 5 | - class ShoutsComponent extends Component { |
|
| 5 | + class ShoutsComponent extends Component { |
|
| 6 | 6 | |
| 7 | - public $settings = ['maxNumberOfShouts' => 10]; |
|
| 7 | + public $settings = ['maxNumberOfShouts' => 10]; |
|
| 8 | 8 | |
| 9 | - protected $_Controller; |
|
| 9 | + protected $_Controller; |
|
| 10 | 10 | |
| 11 | - protected $_ShoutModel = null; |
|
| 11 | + protected $_ShoutModel = null; |
|
| 12 | 12 | |
| 13 | - public function startup(Controller $controller) { |
|
| 14 | - $this->_Controller = $controller; |
|
| 15 | - $this->settings['maxNumberOfShouts'] = (int)Configure::read( |
|
| 16 | - 'Saito.Settings.shoutbox_max_shouts'); |
|
| 17 | - } |
|
| 13 | + public function startup(Controller $controller) { |
|
| 14 | + $this->_Controller = $controller; |
|
| 15 | + $this->settings['maxNumberOfShouts'] = (int)Configure::read( |
|
| 16 | + 'Saito.Settings.shoutbox_max_shouts'); |
|
| 17 | + } |
|
| 18 | 18 | |
| 19 | - public function setShoutsForView() { |
|
| 20 | - // @performance only do if cache is not valid and html need to be rendered |
|
| 21 | - $this->_Controller->set('shouts', $this->get()); |
|
| 22 | - } |
|
| 19 | + public function setShoutsForView() { |
|
| 20 | + // @performance only do if cache is not valid and html need to be rendered |
|
| 21 | + $this->_Controller->set('shouts', $this->get()); |
|
| 22 | + } |
|
| 23 | 23 | |
| 24 | - public function get() { |
|
| 25 | - return $this->_model()->get(); |
|
| 26 | - } |
|
| 24 | + public function get() { |
|
| 25 | + return $this->_model()->get(); |
|
| 26 | + } |
|
| 27 | 27 | |
| 28 | - public function push($data) { |
|
| 29 | - return $this->_model()->push($data); |
|
| 30 | - } |
|
| 28 | + public function push($data) { |
|
| 29 | + return $this->_model()->push($data); |
|
| 30 | + } |
|
| 31 | 31 | |
| 32 | - protected function _model() { |
|
| 33 | - if ($this->_ShoutModel !== null) { |
|
| 34 | - return $this->_ShoutModel; |
|
| 35 | - } |
|
| 36 | - $this->_Controller->loadModel('Shout'); |
|
| 37 | - $this->_ShoutModel = $this->_Controller->Shout; |
|
| 38 | - $this->_ShoutModel->maxNumberOfShouts = $this->settings['maxNumberOfShouts']; |
|
| 39 | - return $this->_ShoutModel; |
|
| 40 | - } |
|
| 32 | + protected function _model() { |
|
| 33 | + if ($this->_ShoutModel !== null) { |
|
| 34 | + return $this->_ShoutModel; |
|
| 35 | + } |
|
| 36 | + $this->_Controller->loadModel('Shout'); |
|
| 37 | + $this->_ShoutModel = $this->_Controller->Shout; |
|
| 38 | + $this->_ShoutModel->maxNumberOfShouts = $this->settings['maxNumberOfShouts']; |
|
| 39 | + return $this->_ShoutModel; |
|
| 40 | + } |
|
| 41 | 41 | |
| 42 | - } |
|
| 42 | + } |
|
@@ -1,67 +1,67 @@ |
||
| 1 | 1 | <?php |
| 2 | 2 | |
| 3 | - use Saito\Cache\CacheSupport; |
|
| 4 | - use Saito\Cache\ItemCache; |
|
| 5 | - use Saito\Cache\LineCacheSupportCachelet; |
|
| 6 | - use Saito\Cache\SaitoCacheEngineAppCache; |
|
| 3 | + use Saito\Cache\CacheSupport; |
|
| 4 | + use Saito\Cache\ItemCache; |
|
| 5 | + use Saito\Cache\LineCacheSupportCachelet; |
|
| 6 | + use Saito\Cache\SaitoCacheEngineAppCache; |
|
| 7 | 7 | |
| 8 | - App::uses('Component', 'Controller'); |
|
| 8 | + App::uses('Component', 'Controller'); |
|
| 9 | 9 | |
| 10 | - class CacheSupportComponent extends Component { |
|
| 10 | + class CacheSupportComponent extends Component { |
|
| 11 | 11 | |
| 12 | - protected $_CacheSupport; |
|
| 12 | + protected $_CacheSupport; |
|
| 13 | 13 | |
| 14 | - /** * @var ItemCache */ |
|
| 15 | - public $LineCache; |
|
| 14 | + /** * @var ItemCache */ |
|
| 15 | + public $LineCache; |
|
| 16 | 16 | |
| 17 | - public function initialize(Controller $Controller) { |
|
| 18 | - $this->_CacheSupport = new CacheSupport(); |
|
| 19 | - if ($Controller->modelClass) { |
|
| 20 | - $Controller->{$Controller->modelClass}->SharedObjects['CacheSupport'] = $this->_CacheSupport; |
|
| 21 | - } |
|
| 22 | - $this->_addConfigureCachelets(); |
|
| 23 | - $this->_initLineCache($Controller); |
|
| 24 | - } |
|
| 17 | + public function initialize(Controller $Controller) { |
|
| 18 | + $this->_CacheSupport = new CacheSupport(); |
|
| 19 | + if ($Controller->modelClass) { |
|
| 20 | + $Controller->{$Controller->modelClass}->SharedObjects['CacheSupport'] = $this->_CacheSupport; |
|
| 21 | + } |
|
| 22 | + $this->_addConfigureCachelets(); |
|
| 23 | + $this->_initLineCache($Controller); |
|
| 24 | + } |
|
| 25 | 25 | |
| 26 | - protected function _initLineCache() { |
|
| 27 | - $this->LineCache = new ItemCache( |
|
| 28 | - 'Saito.LineCache', |
|
| 29 | - new SaitoCacheEngineAppCache, |
|
| 30 | - // duration: update relative time values in HTML at least every hour |
|
| 31 | - ['duration' => 3600, 'maxItems' => 600] |
|
| 32 | - ); |
|
| 33 | - $this->_CacheSupport->add(new LineCacheSupportCachelet($this->LineCache)); |
|
| 34 | - } |
|
| 26 | + protected function _initLineCache() { |
|
| 27 | + $this->LineCache = new ItemCache( |
|
| 28 | + 'Saito.LineCache', |
|
| 29 | + new SaitoCacheEngineAppCache, |
|
| 30 | + // duration: update relative time values in HTML at least every hour |
|
| 31 | + ['duration' => 3600, 'maxItems' => 600] |
|
| 32 | + ); |
|
| 33 | + $this->_CacheSupport->add(new LineCacheSupportCachelet($this->LineCache)); |
|
| 34 | + } |
|
| 35 | 35 | |
| 36 | - /** |
|
| 37 | - * Adds additional cachelets from Configure `Saito.Cachelets` |
|
| 38 | - * |
|
| 39 | - * E.g. use in `Plugin/<foo>/Config/bootstrap.php`: |
|
| 40 | - * |
|
| 41 | - * <code> |
|
| 42 | - * Configure::write('Saito.Cachelets.M', ['location' => 'M.Lib', 'name' => 'MCacheSupportCachelet']); |
|
| 43 | - * </code> |
|
| 44 | - */ |
|
| 45 | - protected function _addConfigureCachelets() { |
|
| 46 | - $_additionalCachelets = Configure::read('Saito.Cachelets'); |
|
| 47 | - if (!$_additionalCachelets) { |
|
| 48 | - return; |
|
| 49 | - } |
|
| 50 | - foreach ($_additionalCachelets as $_c) { |
|
| 51 | - App::uses($_c['name'], $_c['location']); |
|
| 52 | - $this->_CacheSupport->add(new $_c['name']); |
|
| 53 | - } |
|
| 54 | - } |
|
| 36 | + /** |
|
| 37 | + * Adds additional cachelets from Configure `Saito.Cachelets` |
|
| 38 | + * |
|
| 39 | + * E.g. use in `Plugin/<foo>/Config/bootstrap.php`: |
|
| 40 | + * |
|
| 41 | + * <code> |
|
| 42 | + * Configure::write('Saito.Cachelets.M', ['location' => 'M.Lib', 'name' => 'MCacheSupportCachelet']); |
|
| 43 | + * </code> |
|
| 44 | + */ |
|
| 45 | + protected function _addConfigureCachelets() { |
|
| 46 | + $_additionalCachelets = Configure::read('Saito.Cachelets'); |
|
| 47 | + if (!$_additionalCachelets) { |
|
| 48 | + return; |
|
| 49 | + } |
|
| 50 | + foreach ($_additionalCachelets as $_c) { |
|
| 51 | + App::uses($_c['name'], $_c['location']); |
|
| 52 | + $this->_CacheSupport->add(new $_c['name']); |
|
| 53 | + } |
|
| 54 | + } |
|
| 55 | 55 | |
| 56 | - public function beforeRender(Controller $Controller) { |
|
| 57 | - $Controller->set('LineCache', $this->LineCache); |
|
| 58 | - } |
|
| 56 | + public function beforeRender(Controller $Controller) { |
|
| 57 | + $Controller->set('LineCache', $this->LineCache); |
|
| 58 | + } |
|
| 59 | 59 | |
| 60 | - public function __call($method, $params) { |
|
| 61 | - $proxy = [$this->_CacheSupport, $method]; |
|
| 62 | - if (is_callable($proxy)) { |
|
| 63 | - return call_user_func_array($proxy, $params); |
|
| 64 | - } |
|
| 65 | - } |
|
| 60 | + public function __call($method, $params) { |
|
| 61 | + $proxy = [$this->_CacheSupport, $method]; |
|
| 62 | + if (is_callable($proxy)) { |
|
| 63 | + return call_user_func_array($proxy, $params); |
|
| 64 | + } |
|
| 65 | + } |
|
| 66 | 66 | |
| 67 | - } |
|
| 67 | + } |
|