From 3ebee958d4a85860ae592db424ec9d3af0e11462 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Florian=20Kr=C3=A4mer?= Date: Wed, 19 Apr 2017 17:57:28 +0200 Subject: [PATCH 01/15] Updating the change password --- .../Component/UserToolComponent.php | 11 +++---- src/Model/Behavior/UserBehavior.php | 30 ++++++++++++++----- 2 files changed, 27 insertions(+), 14 deletions(-) diff --git a/src/Controller/Component/UserToolComponent.php b/src/Controller/Component/UserToolComponent.php index 0a6b744..60dedab 100644 --- a/src/Controller/Component/UserToolComponent.php +++ b/src/Controller/Component/UserToolComponent.php @@ -734,11 +734,10 @@ public function resetPassword($token = null, $options = []) { * @return void */ public function changePassword($options = []) { - $options = (Hash::merge($this->config('changePassword'), $options)); + $options = Hash::merge($this->config('changePassword'), $options); $entity = $this->UserTable->newEntity(); $entity->accessible([ - 'id', 'old_password', 'password', 'new_password', @@ -746,22 +745,20 @@ public function changePassword($options = []) { ], true); if ($this->request->is(['post', 'put'])) { - $this->request->data['id'] = $this->_getAuthObject()->user('id'); + $entity = $this->UserTable->get($this->_getAuthObject()->user('id')); $entity = $this->UserTable->patchEntity($entity, $this->request->data, [ 'validate' => 'changePassword' ]); - $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->_setViewVar('entity', $entity); } diff --git a/src/Model/Behavior/UserBehavior.php b/src/Model/Behavior/UserBehavior.php index f480fdf..c4d5b0b 100644 --- a/src/Model/Behavior/UserBehavior.php +++ b/src/Model/Behavior/UserBehavior.php @@ -26,6 +26,9 @@ use Cake\Utility\Text; use RuntimeException; +/** + * User Behavior + */ class UserBehavior extends Behavior { use EventDispatcherTrait; @@ -81,8 +84,13 @@ class UserBehavior extends Behavior { 'slug' => 'slug', ], 'beforeSave' => [ + // Enable this only if you're not using the built in password change + // and want the password hash to be updated automatically 'handleNewPasswordByOldPassword' => false ], + 'changePassword' => [ + 'hashPassword' => true + ], 'updateLastActivity' => [ 'dateFormat' => 'Y-m-d H:i:s', ], @@ -501,21 +509,22 @@ public function removeExpiredRegistrations($conditions = []) { * Changes the password for an user. * * @param \Cake\Datasource\EntityInterface $entity User entity + * @param array $options Options * @return boolean */ - public function changePassword(EntityInterface $entity) { + public function changePassword(EntityInterface $entity, array $options = []) { + $options = Hash::merge($this->_config['changePassword'], $options); + if ($entity->errors()) { return false; } - $field = $this->_field('password'); - $entity->set($field, $this->hashPassword($entity->get($field))); - - if ($this->_table->save($entity)) { - return true; + if ($options['hashPassword'] === true) { + $field = $this->_field('password'); + $entity->set($field, $this->hashPassword($entity->get($field))); } - return false; + return (bool)$this->_table->save($entity); } /** @@ -663,6 +672,13 @@ public function sendNewPassword($email, $options = []) { return $this->sendNewPasswordEmail($result, ['to' => $result->get($this->_field('email'))]); } + /** + * beforeSave callback + * + * @param \Cake\Event\Event $event + * @param \Cake\Datasource\EntityInterface + * @return void + */ public function beforeSave(Event $event, EntityInterface $entity) { $config = (array)$this->config('beforeSave'); if ($config['handleNewPasswordByOldPassword'] === true) { From a8348e1f990d37884e5783d6c0c51ec9d363635c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Florian=20Kr=C3=A4mer?= Date: Mon, 24 Apr 2017 15:06:37 +0200 Subject: [PATCH 02/15] Fixing a bug with the resetPassword() flash messages --- .../Component/FlashAndRedirectTrait.php | 10 +++- .../Component/UserToolComponent.php | 47 ++++++++++++++----- 2 files changed, 44 insertions(+), 13 deletions(-) diff --git a/src/Controller/Component/FlashAndRedirectTrait.php b/src/Controller/Component/FlashAndRedirectTrait.php index 2f576ad..3417227 100644 --- a/src/Controller/Component/FlashAndRedirectTrait.php +++ b/src/Controller/Component/FlashAndRedirectTrait.php @@ -44,6 +44,8 @@ protected function _handleRedirect($type, $options) { $this->_redirectResponse = $result; return $result; } + + $this->_redirectResponse = false; return false; } @@ -61,7 +63,13 @@ protected function _handleFlash($type, $options) { if (isset($options[$type . 'FlashOptions'])) { $flashOptions = $options[$type . 'FlashOptions']; } - $this->Flash->$type($options[$type . 'Message'], $flashOptions); + + if (method_exists($this->Flash, $type)) { + $this->Flash->$type($options[$type . 'Message'], $flashOptions); + } else { + $this->Flash->set($options[$type . 'Message'], $flashOptions); + } + return true; } } diff --git a/src/Controller/Component/UserToolComponent.php b/src/Controller/Component/UserToolComponent.php index 60dedab..543b3d9 100644 --- a/src/Controller/Component/UserToolComponent.php +++ b/src/Controller/Component/UserToolComponent.php @@ -15,8 +15,8 @@ use Cake\Datasource\Exception\RecordNotFoundException; use Cake\Event\EventManagerTrait; use Cake\Event\Event; +use Cake\Http\Response; use Cake\Network\Exception\NotFoundException; -use Cake\Network\Response; use Cake\ORM\TableRegistry; use Cake\Utility\Hash; @@ -101,16 +101,24 @@ class UserToolComponent extends Component { 'setEntity' => true, ], 'resetPassword' => [ + 'queryParam' => 'token', + 'tokenOptions' => [], + // Success 'successFlashOptions' => [], 'successRedirectUrl' => '/', + // Normal error 'errorFlashOptions' => [], 'errorRedirectUrl' => false, - 'invalidErrorFlashOptions' => [], + // Invalid Token error + 'invalidErrorFlashOptions' => [ + 'element' => 'Flash/error' + ], 'invalidErrorRedirectUrl' => '/', - 'expiredErrorFlashOptions' => [], - 'expiredErrorRedirectUrl' => '/', - 'queryParam' => 'token', - 'tokenOptions' => [], + // Token expired error + 'expiredErrorFlashOptions' => [ + 'element' => 'Flash/error' + ], + 'expiredErrorRedirectUrl' => '/' ], 'changePassword' => [ 'successFlashOptions' => [], @@ -697,33 +705,48 @@ public function resetPassword($token = null, $options = []) { if (!empty($this->request->query[$options['queryParam']])) { $token = $this->request->query[$options['queryParam']]; } + + // Check of the token exists try { $entity = $this->UserTable->verifyPasswordResetToken($token, $options['tokenOptions']); } catch (RecordNotFoundException $e) { - if (empty($options['invalidErrorMessage'])) { - $options['invalidErrorMessage'] = $e->getMessage(); + if (empty($options['errorMessage']) && $options['errorMessage'] !== false) { + $options['errorMessage'] = $e->getMessage(); + } + + $redirect = $this->handleFlashAndRedirect('invalidError', $options); + if ($redirect instanceof Response) { + return $redirect; } - $this->handleFlashAndRedirect('invalidError', $options); $entity = $this->UserTable->newEntity(); } - if (isset($entity->token_is_expired) && $entity->token_is_expired === true) { + // Check if the token has expired + if ($entity->get('token_is_expired') === true) { if (empty($options['invalidErrorMessage'])) { $options['invalidErrorMessage'] = $e->getMessage(); } $this->handleFlashAndRedirect('expiredError', $options); + if ($redirect instanceof Response) { + return $redirect; + } } + // Handle the POST if ($this->request->is('post')) { $entity = $this->UserTable->patchEntity($entity, $this->request->data); if ($this->UserTable->resetPassword($entity)) { - $this->handleFlashAndRedirect('success', $options); + $redirect = $this->handleFlashAndRedirect('success', $options); } else { - $this->handleFlashAndRedirect('error', $options); + $redirect = $this->handleFlashAndRedirect('error', $options); + } + if ($redirect instanceof Response) { + return $redirect; } } else { $entity = $this->UserTable->newEntity(); } + $this->_setViewVar('entity', $entity); } From b9d4421879227e9b377576618bf1657d2ecd26c3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Florian=20Kr=C3=A4mer?= Date: Mon, 24 Apr 2017 23:06:01 +0200 Subject: [PATCH 03/15] Minor fixes, forgotten variable declaration --- src/Controller/Component/UserToolComponent.php | 2 +- src/Model/Behavior/UserBehavior.php | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/src/Controller/Component/UserToolComponent.php b/src/Controller/Component/UserToolComponent.php index 543b3d9..56e0a09 100644 --- a/src/Controller/Component/UserToolComponent.php +++ b/src/Controller/Component/UserToolComponent.php @@ -726,7 +726,7 @@ public function resetPassword($token = null, $options = []) { if (empty($options['invalidErrorMessage'])) { $options['invalidErrorMessage'] = $e->getMessage(); } - $this->handleFlashAndRedirect('expiredError', $options); + $redirect = $this->handleFlashAndRedirect('expiredError', $options); if ($redirect instanceof Response) { return $redirect; } diff --git a/src/Model/Behavior/UserBehavior.php b/src/Model/Behavior/UserBehavior.php index c4d5b0b..fd4b41d 100644 --- a/src/Model/Behavior/UserBehavior.php +++ b/src/Model/Behavior/UserBehavior.php @@ -391,7 +391,7 @@ public function verifyToken($token, $options = []) { ]); $time = new Time(); - $result->token_is_expired = $result->{$options['expirationField']} <= $time; + $result->set('token_is_expired', $result->get($options['expirationField']) <= $time); $this->afterTokenVerification($result, $options); @@ -399,6 +399,7 @@ public function verifyToken($token, $options = []) { 'data' => $result, 'options' => $options ]); + $this->eventManager()->dispatch($event); if ($event->isStopped()) { return (bool) $event->result; From 28b852805038260a06731d4d04fab30c3e440def Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Florian=20Kr=C3=A4mer?= Date: Thu, 27 Apr 2017 22:17:13 +0200 Subject: [PATCH 04/15] Fixing passing arguments from the URL to component methods --- src/Controller/Component/UserToolComponent.php | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/Controller/Component/UserToolComponent.php b/src/Controller/Component/UserToolComponent.php index 56e0a09..4ddc1b7 100644 --- a/src/Controller/Component/UserToolComponent.php +++ b/src/Controller/Component/UserToolComponent.php @@ -373,7 +373,8 @@ protected function _directMapping($action) { if (!method_exists($this, $action)) { return false; } - $result = $this->{$action}(); + $pass = (array)$this->request->getParam('pass'); + $result = call_user_func_array([$this, $action], $pass); if ($result instanceof Response) { return $result; } @@ -389,7 +390,8 @@ protected function _directMapping($action) { protected function _mapAction($action) { $actionMap = $this->config('actionMap'); if (isset($actionMap[$action]) && method_exists($this, $actionMap[$action]['method'])) { - $this->{$actionMap[$action]['method']}(); + $pass = (array)$this->request->getParam('pass'); + call_user_func_array([$this, $actionMap[$action]['method']], $pass); if ($this->_redirectResponse instanceof Response) { return $this->_redirectResponse; } @@ -700,7 +702,7 @@ protected function _initPasswordReset(EntityInterface $entity, $options) { * @return void */ public function resetPassword($token = null, $options = []) { - $options = (Hash::merge($this->config('resetPassword'), $options)); + $options = Hash::merge($this->config('resetPassword'), $options); if (!empty($this->request->query[$options['queryParam']])) { $token = $this->request->query[$options['queryParam']]; From 9a9317d3faf2624aced107e766069aa65fe7f28e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Florian=20Kr=C3=A4mer?= Date: Thu, 27 Apr 2017 22:18:12 +0200 Subject: [PATCH 05/15] Updating travis config --- .travis.yml | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/.travis.yml b/.travis.yml index 84b0a18..f6f24de 100644 --- a/.travis.yml +++ b/.travis.yml @@ -3,15 +3,13 @@ language: php php: - 5.6 - 7.0 + - 7.1 matrix: - allow_failures: - - php: 7.0 - fast_finish: true include: - - php: 5.6 + - php: 7.1 env: - COVERALLS=1 From 46d2af60c57dd5d7ab151ce7ce4e4d6c35aa0c4b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Florian=20Kr=C3=A4mer?= Date: Thu, 27 Apr 2017 22:47:37 +0200 Subject: [PATCH 06/15] Updating travis --- .travis.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index f6f24de..aeb382e 100644 --- a/.travis.yml +++ b/.travis.yml @@ -20,8 +20,8 @@ before_script: - sh -c "if [ '$COVERALLS' = '1' ]; then mkdir -p build/logs; fi" script: - - phpunit - - sh -c "if [ '$COVERALLS' = '1' ]; then phpunit --stderr --coverage-clover build/logs/clover.xml; fi" + - vendor/bin/phpunit + - sh -c "if [ '$COVERALLS' = '1' ]; then vendor/bin/phpunit --stderr --coverage-clover build/logs/clover.xml; fi" - sh -c "if [ '$COVERALLS' = '1' ]; then php vendor/bin/coveralls -c .coveralls.yml -v; fi" notifications: From 8810ff1f6832d8051dbf90faeac23936b461e28f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Florian=20Kr=C3=A4mer?= Date: Thu, 27 Apr 2017 22:47:48 +0200 Subject: [PATCH 07/15] Minor code formatting changes --- .../Component/UserToolComponent.php | 10 ++++++++-- src/Model/Behavior/UserBehavior.php | 19 ++++++++++++++----- 2 files changed, 22 insertions(+), 7 deletions(-) diff --git a/src/Controller/Component/UserToolComponent.php b/src/Controller/Component/UserToolComponent.php index 4ddc1b7..72710b8 100644 --- a/src/Controller/Component/UserToolComponent.php +++ b/src/Controller/Component/UserToolComponent.php @@ -649,10 +649,14 @@ public function verifyEmailToken($options = []) { */ public function requestPassword($options = []) { $options = Hash::merge($this->config('requestPassword'), $options); - $entity = $this->UserTable->newEntity(null, ['validate' => 'requestPassword']); + $entity = $this->UserTable->newEntity(null, [ + 'validate' => 'requestPassword' + ]); if ($this->request->is('post')) { - $entity = $this->UserTable->patchEntity($entity, $this->request->data, ['validate' => 'requestPassword']); + $entity = $this->UserTable->patchEntity($entity, $this->request->data, [ + 'validate' => 'requestPassword' + ]); if (!$entity->errors($options['field']) && $this->_initPasswordReset($entity, $options)) { return true; @@ -687,10 +691,12 @@ protected function _initPasswordReset(EntityInterface $entity, $options) { if ($options['setEntity']) { $this->_setViewVar('userEntity', $entity); } + return true; } catch (RecordNotFoundException $e) { $this->handleFlashAndRedirect('error', $options); } + return false; } diff --git a/src/Model/Behavior/UserBehavior.php b/src/Model/Behavior/UserBehavior.php index fd4b41d..58df91f 100644 --- a/src/Model/Behavior/UserBehavior.php +++ b/src/Model/Behavior/UserBehavior.php @@ -550,8 +550,12 @@ public function initPasswordReset($value, $options = []) { throw new RecordNotFoundException(__d('burzum/user_tools', 'User not found.')); } - $result->set($this->_field('passwordToken'), $this->generateToken($options['tokenLength'])); - $result->set($this->_field('passwordTokenExpires'), $this->expirationTime($options['expires'])); + $result->set([ + $this->_field('passwordToken') => $this->generateToken($options['tokenLength']), + $this->_field('passwordTokenExpires') => $this->expirationTime($options['expires']) + ], [ + 'guard' => false + ]); if (!$this->_table->save($result, ['checkRules' => false])) { new RuntimeException('Could not initialize password reset. Data could not be saved.'); @@ -659,14 +663,19 @@ public function sendNewPassword($email, $options = []) { $this->_table->aliasField($this->_field('email')) => $email ]) ->first(); + if (empty($result)) { throw new RecordNotFoundException(__d('user_tools', 'Invalid user')); } } $password = $this->generatePassword(); - $result->set('clear_password', $password); - $result->set($this->_field('password'), $this->hashPassword($password)); + $result->set([ + $this->_field('password') => $this->hashPassword($password), + 'clear_password' => $password + ], [ + 'guard' => false + ]); $this->_table->save($result, ['validate' => false]); @@ -716,7 +725,7 @@ public function handleNewPasswordByOldPassword(EntityInterface $user) { } $newPassword = $this->hashPassword($user->get($this->_field('password'))); - $user->set($this->_field('password'), $newPassword); + $user->set($this->_field('password'), $newPassword, ['guard' => false]); } /** From 765b5a82cb29f5c8354f855187bc223a473d68bc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Florian=20Kr=C3=A4mer?= Date: Thu, 27 Apr 2017 22:54:51 +0200 Subject: [PATCH 08/15] More minor changes to entity calls --- src/Model/Behavior/UserBehavior.php | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/src/Model/Behavior/UserBehavior.php b/src/Model/Behavior/UserBehavior.php index 58df91f..2879518 100644 --- a/src/Model/Behavior/UserBehavior.php +++ b/src/Model/Behavior/UserBehavior.php @@ -409,7 +409,7 @@ public function verifyToken($token, $options = []) { return $result; } - return $result->token_is_expired; + return $result->get('token_is_expired'); } /** @@ -420,14 +420,19 @@ public function verifyToken($token, $options = []) { * @return mixed */ public function afterTokenVerification(Entity $user, $options = []) { - if ($user->token_is_expired === true) { + if ($user->get('token_is_expired') === true) { return false; } if ($options['tokenField'] === $this->_field('emailToken')) { - $user->{$this->_field('emailVerified')} = 1; - $user->{$this->_field('emailToken')} = null; - $user->{$this->_field('emailTokenExpires')} = null; + $user->set([ + $user->{$this->_field('emailVerified')} => true, + $user->{$this->_field('emailToken')} => null, + $user->{$this->_field('emailTokenExpires')} => null + ], [ + 'guard' => false + ]); } + return $this->_table->save($user, ['validate' => false]); } From 4d469c9634d60e23a48303db0cb662237abf50a8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Florian=20Kr=C3=A4mer?= Date: Thu, 27 Apr 2017 22:58:07 +0200 Subject: [PATCH 09/15] Fixing a missing use statement --- src/Controller/Component/UserToolComponent.php | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/Controller/Component/UserToolComponent.php b/src/Controller/Component/UserToolComponent.php index 72710b8..af8783a 100644 --- a/src/Controller/Component/UserToolComponent.php +++ b/src/Controller/Component/UserToolComponent.php @@ -13,7 +13,7 @@ use Cake\Controller\ComponentRegistry; use Cake\Datasource\EntityInterface; use Cake\Datasource\Exception\RecordNotFoundException; -use Cake\Event\EventManagerTrait; +use Cake\Event\EventDispatcherTrait; use Cake\Event\Event; use Cake\Http\Response; use Cake\Network\Exception\NotFoundException; @@ -22,7 +22,7 @@ class UserToolComponent extends Component { - use EventManagerTrait; + use EventDispatcherTrait; use FlashAndRedirectTrait; /** @@ -206,7 +206,7 @@ class UserToolComponent extends Component { /** * Response object * - * @var \Cake\Network\Response + * @var \Cake\Http\Response */ public $response = null; @@ -367,17 +367,20 @@ public function mapAction() { /** * @param string $action - * @return \Cake\Network\Response A response object containing the rendered view. + * @return \Cake\Http\Response|bool A response object containing the rendered view. */ protected function _directMapping($action) { if (!method_exists($this, $action)) { return false; } + $pass = (array)$this->request->getParam('pass'); $result = call_user_func_array([$this, $action], $pass); + if ($result instanceof Response) { return $result; } + return $this->_controller->render($action); } From 40e2ba91122601166bad95f54a8dd7d8e00777a5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Florian=20Kr=C3=A4mer?= Date: Thu, 27 Apr 2017 23:01:58 +0200 Subject: [PATCH 10/15] Fixing doc blocks --- src/Controller/Component/FlashAndRedirectTrait.php | 5 +++-- src/Model/Behavior/UserBehavior.php | 2 +- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/src/Controller/Component/FlashAndRedirectTrait.php b/src/Controller/Component/FlashAndRedirectTrait.php index 3417227..f32422f 100644 --- a/src/Controller/Component/FlashAndRedirectTrait.php +++ b/src/Controller/Component/FlashAndRedirectTrait.php @@ -14,7 +14,7 @@ trait FlashAndRedirectTrait { * Helper property to detect a redirect * * @see UserToolComponent::handleFlashAndRedirect(); - * @var \Cake\Network\Response + * @var \Cake\Http\Response|null */ protected $_redirectResponse = null; @@ -45,7 +45,8 @@ protected function _handleRedirect($type, $options) { return $result; } - $this->_redirectResponse = false; + $this->_redirectResponse = null; + return false; } diff --git a/src/Model/Behavior/UserBehavior.php b/src/Model/Behavior/UserBehavior.php index 2879518..49fc82d 100644 --- a/src/Model/Behavior/UserBehavior.php +++ b/src/Model/Behavior/UserBehavior.php @@ -117,7 +117,7 @@ class UserBehavior extends Behavior { * Keeping a reference to the table in order to be able to retrieve associations * and fetch records for counting. * - * @var array + * @var \Cake\ORM\Table */ protected $_table; From 711a847a309906417c8608de8f52957342f3d47e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Florian=20Kr=C3=A4mer?= Date: Thu, 27 Apr 2017 23:10:50 +0200 Subject: [PATCH 11/15] Updating README.md --- README.md | 1 - 1 file changed, 1 deletion(-) diff --git a/README.md b/README.md index 22227ff..d3282db 100644 --- a/README.md +++ b/README.md @@ -23,7 +23,6 @@ Requirements ------------ * CakePHP 3.0+ -* PHP 5.4.19 Complementary plugins --------------------- From f7dbaf7470be70878e005b74e1e9cba6b606dec3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Florian=20Kr=C3=A4mer?= Date: Tue, 16 May 2017 12:20:22 +0200 Subject: [PATCH 12/15] Fixing the email verification --- src/Model/Behavior/UserBehavior.php | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/Model/Behavior/UserBehavior.php b/src/Model/Behavior/UserBehavior.php index 49fc82d..6e5182d 100644 --- a/src/Model/Behavior/UserBehavior.php +++ b/src/Model/Behavior/UserBehavior.php @@ -423,11 +423,12 @@ public function afterTokenVerification(Entity $user, $options = []) { if ($user->get('token_is_expired') === true) { return false; } + if ($options['tokenField'] === $this->_field('emailToken')) { $user->set([ - $user->{$this->_field('emailVerified')} => true, - $user->{$this->_field('emailToken')} => null, - $user->{$this->_field('emailTokenExpires')} => null + $this->_field('emailVerified') => true, + $this->_field('emailToken') => null, + $this->_field('emailTokenExpires') => null ], [ 'guard' => false ]); From 7833fd5be4147e34532dff1fa2b629fa97227bf5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Florian=20Kr=C3=A4mer?= Date: Mon, 29 May 2017 00:05:49 +0200 Subject: [PATCH 13/15] Adding a way to dynamically load templates --- src/Controller/Component/UserToolComponent.php | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/Controller/Component/UserToolComponent.php b/src/Controller/Component/UserToolComponent.php index af8783a..b82d6f2 100644 --- a/src/Controller/Component/UserToolComponent.php +++ b/src/Controller/Component/UserToolComponent.php @@ -395,15 +395,24 @@ protected function _mapAction($action) { if (isset($actionMap[$action]) && method_exists($this, $actionMap[$action]['method'])) { $pass = (array)$this->request->getParam('pass'); call_user_func_array([$this, $actionMap[$action]['method']], $pass); + if ($this->_redirectResponse instanceof Response) { return $this->_redirectResponse; } + if (is_string($actionMap[$action]['view'])) { - return $this->_controller->render($actionMap[$action]['view']); + try { + return $this->_controller->render($this->_controller->request->getParam('action')); + } catch (MissingTemplateException $e) { + return $this->_controller->render($actionMap[$action]['view']); + } + + return true; } else { return $this->response; } } + return false; } From 6656d0fae218bf324adcf9403164e1326c8eadcd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Florian=20Kr=C3=A4mer?= Date: Wed, 31 May 2017 12:29:49 +0200 Subject: [PATCH 14/15] Updating the copyright year --- src/Auth/DefaultAuthSetupTrait.php | 2 +- src/Model/Behavior/UserBehavior.php | 2 +- src/Shell/UserShell.php | 2 +- src/Validation/UsersValidator.php | 2 +- src/View/Helper/AuthHelper.php | 2 +- tests/Fixture/ProfileFixture.php | 2 +- tests/Fixture/UserFixture.php | 2 +- tests/TestCase/Auth/DefaultAuthSetupTraitTest.php | 2 +- tests/TestCase/Controller/Component/UserToolComponentTest.php | 2 +- tests/TestCase/Model/Behavior/UserBehaviorTest.php | 2 +- tests/TestCase/View/Helper/AuthHelperTest.php | 2 +- 11 files changed, 11 insertions(+), 11 deletions(-) diff --git a/src/Auth/DefaultAuthSetupTrait.php b/src/Auth/DefaultAuthSetupTrait.php index ab637ad..b043a1b 100644 --- a/src/Auth/DefaultAuthSetupTrait.php +++ b/src/Auth/DefaultAuthSetupTrait.php @@ -3,7 +3,7 @@ * UserToolComponent * * @author Florian Krämer - * @copyright 2013 - 2016 Florian Krämer + * @copyright 2013 - 2017 Florian Krämer * @license MIT */ namespace Burzum\UserTools\Auth; diff --git a/src/Model/Behavior/UserBehavior.php b/src/Model/Behavior/UserBehavior.php index 6e5182d..380ae95 100644 --- a/src/Model/Behavior/UserBehavior.php +++ b/src/Model/Behavior/UserBehavior.php @@ -3,7 +3,7 @@ * UserBehavior * * @author Florian Krämer - * @copyright 2013 - 2016 Florian Krämer + * @copyright 2013 - 2017 Florian Krämer * @copyright 2012 Cake Development Corporation * @license MIT */ diff --git a/src/Shell/UserShell.php b/src/Shell/UserShell.php index 9de58dc..3901c80 100644 --- a/src/Shell/UserShell.php +++ b/src/Shell/UserShell.php @@ -3,7 +3,7 @@ * UserShell * * @author Florian Krämer - * @copyright 2013 - 2016 Florian Krämer + * @copyright 2013 - 2017 Florian Krämer * @license MIT */ namespace Burzum\UserTools\Shell; diff --git a/src/Validation/UsersValidator.php b/src/Validation/UsersValidator.php index 196f96e..2c148a5 100644 --- a/src/Validation/UsersValidator.php +++ b/src/Validation/UsersValidator.php @@ -3,7 +3,7 @@ * UserRegistrationValidator * * @author Florian Krämer - * @copyright 2013 - 2016 Florian Krämer + * @copyright 2013 - 2017 Florian Krämer * @license MIT */ namespace Burzum\UserTools\Validation; diff --git a/src/View/Helper/AuthHelper.php b/src/View/Helper/AuthHelper.php index 07bf5f5..4da60f5 100644 --- a/src/View/Helper/AuthHelper.php +++ b/src/View/Helper/AuthHelper.php @@ -3,7 +3,7 @@ * AuthHelper * * @author Florian Krämer - * @copyright 2013 - 2016 Florian Krämer + * @copyright 2013 - 2017 Florian Krämer * @license MIT */ namespace Burzum\UserTools\View\Helper; diff --git a/tests/Fixture/ProfileFixture.php b/tests/Fixture/ProfileFixture.php index a1cde5a..f31d97b 100644 --- a/tests/Fixture/ProfileFixture.php +++ b/tests/Fixture/ProfileFixture.php @@ -7,7 +7,7 @@ * ProfileFixture * * @author Florian Krämer - * ]@copyright 2013 - 2016 Florian Krämer + * ]@copyright 2013 - 2017 Florian Krämer * @license MIT */ class ProfileFixture extends TestFixture { diff --git a/tests/Fixture/UserFixture.php b/tests/Fixture/UserFixture.php index fdab55a..2d308cb 100644 --- a/tests/Fixture/UserFixture.php +++ b/tests/Fixture/UserFixture.php @@ -7,7 +7,7 @@ * UserFixture * * @author Florian Krämer - * ]@copyright 2013 - 2016 Florian Krämer + * ]@copyright 2013 - 2017 Florian Krämer * @license MIT */ class UserFixture extends TestFixture { diff --git a/tests/TestCase/Auth/DefaultAuthSetupTraitTest.php b/tests/TestCase/Auth/DefaultAuthSetupTraitTest.php index 170f076..b591ae6 100644 --- a/tests/TestCase/Auth/DefaultAuthSetupTraitTest.php +++ b/tests/TestCase/Auth/DefaultAuthSetupTraitTest.php @@ -17,7 +17,7 @@ class DefaultAuthSetupTraitController extends Controller { * DefaultAuthSetupTraitTest * * @author Florian Kr�mer - * @copyright 2013 - 2016 Florian Kr�mer + * @copyright 2013 - 2017 Florian Kr�mer * @license MIT */ class DefaultAuthSetupTraitTest extends TestCase { diff --git a/tests/TestCase/Controller/Component/UserToolComponentTest.php b/tests/TestCase/Controller/Component/UserToolComponentTest.php index 35686e9..1a30689 100644 --- a/tests/TestCase/Controller/Component/UserToolComponentTest.php +++ b/tests/TestCase/Controller/Component/UserToolComponentTest.php @@ -16,7 +16,7 @@ class UsersController extends Controller { * UserToolComponent * * @author Florian Krämer - * ]@copyright 2013 - 2016 Florian Krämer + * ]@copyright 2013 - 2017 Florian Krämer * @license MIT */ class UserToolComponentTest extends TestCase { diff --git a/tests/TestCase/Model/Behavior/UserBehaviorTest.php b/tests/TestCase/Model/Behavior/UserBehaviorTest.php index f264db1..48b26ec 100644 --- a/tests/TestCase/Model/Behavior/UserBehaviorTest.php +++ b/tests/TestCase/Model/Behavior/UserBehaviorTest.php @@ -11,7 +11,7 @@ * UserBehaviorTest * * @author Florian Krämer - * ]@copyright 2013 - 2016 Florian Krämer + * ]@copyright 2013 - 2017 Florian Krämer * @license MIT */ diff --git a/tests/TestCase/View/Helper/AuthHelperTest.php b/tests/TestCase/View/Helper/AuthHelperTest.php index a4ef771..7b2cefd 100644 --- a/tests/TestCase/View/Helper/AuthHelperTest.php +++ b/tests/TestCase/View/Helper/AuthHelperTest.php @@ -12,7 +12,7 @@ * AuthHelperTestCase * * @author Florian Krämer - * ]@copyright 2013 - 2016 Florian Krämer + * ]@copyright 2013 - 2017 Florian Krämer * @license MIT */ class AuthHelperTestCase extends TestCase { From 8121303ec4b950177fef5bd2266f2f288b7a05ad Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Florian=20Kr=C3=A4mer?= Date: Wed, 31 May 2017 12:31:39 +0200 Subject: [PATCH 15/15] Fixing the flash message type setting --- src/Controller/Component/FlashAndRedirectTrait.php | 8 ++++---- src/Controller/Component/UserToolComponent.php | 3 ++- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/src/Controller/Component/FlashAndRedirectTrait.php b/src/Controller/Component/FlashAndRedirectTrait.php index f32422f..8474fd5 100644 --- a/src/Controller/Component/FlashAndRedirectTrait.php +++ b/src/Controller/Component/FlashAndRedirectTrait.php @@ -3,7 +3,7 @@ * FlashAndRedirectTrait * * @author Florian Krämer - * @copyright 2013 - 2016 Florian Krämer + * @copyright 2013 - 2017 Florian Krämer * @license MIT */ namespace Burzum\UserTools\Controller\Component; @@ -65,15 +65,15 @@ protected function _handleFlash($type, $options) { $flashOptions = $options[$type . 'FlashOptions']; } - if (method_exists($this->Flash, $type)) { - $this->Flash->$type($options[$type . 'Message'], $flashOptions); - } else { + if (!isset($flashOptions['element'])) { + $flashOptions['element'] = $type; $this->Flash->set($options[$type . 'Message'], $flashOptions); } return true; } } + return false; } } diff --git a/src/Controller/Component/UserToolComponent.php b/src/Controller/Component/UserToolComponent.php index b82d6f2..6fc47b0 100644 --- a/src/Controller/Component/UserToolComponent.php +++ b/src/Controller/Component/UserToolComponent.php @@ -3,7 +3,7 @@ * UserToolComponent * * @author Florian Krämer - * @copyright 2013 - 2016 Florian Krämer + * @copyright 2013 - 2017 Florian Krämer * @license MIT */ namespace Burzum\UserTools\Controller\Component; @@ -19,6 +19,7 @@ use Cake\Network\Exception\NotFoundException; use Cake\ORM\TableRegistry; use Cake\Utility\Hash; +use Cake\View\Exception\MissingTemplateException; class UserToolComponent extends Component {