From 04c6553ebe8bd6e0fc736fcb9827e8b584509074 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Florian=20Kr=C3=A4mer?= Date: Tue, 16 Feb 2016 18:20:37 +0100 Subject: [PATCH 1/8] Use appropriate flashes for success/error --- src/Controller/Component/UserToolComponent.php | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/src/Controller/Component/UserToolComponent.php b/src/Controller/Component/UserToolComponent.php index 666dc5d..65ef9e3 100644 --- a/src/Controller/Component/UserToolComponent.php +++ b/src/Controller/Component/UserToolComponent.php @@ -463,7 +463,7 @@ protected function _afterLogin($user, array $options) { public function login($options = []) { $options = Hash::merge($this->config('login'), $options); $this->_handleUserBeingAlreadyLoggedIn($options); - $entity = $this->UserTable->newEntity([], ['validate' => false]); + $entity = $this->UserTable->newEntity(null, ['validate' => false]); if ($this->request->is('post')) { $user = $this->_beforeLogin($entity, $options); if ($user) { @@ -623,7 +623,7 @@ public function verifyEmailToken($options = []) { */ public function requestPassword($options = []) { $options = Hash::merge($this->config('requestPassword'), $options); - $entity = $this->UserTable->newEntity(['validate' => 'requestPassword']); + $entity = $this->UserTable->newEntity(null, ['validate' => 'requestPassword']); if ($this->request->is('post')) { $entity = $this->UserTable->patchEntity($entity, $this->request->data, ['validate' => 'requestPassword']); @@ -641,12 +641,20 @@ public function requestPassword($options = []) { unset($this->request->data[$options['field']]); return false; } + if ($options['setEntity']) { $this->_controller->set('userEntity', $entity); } } - protected function _initPasswordReset($entity, $options) { + /** + * Initializes the password reset and handles a possible errors. + * + * @param \Cake\Datasource\EntityInterface + * @param array $options Options array + * @return bool + */ + protected function _initPasswordReset(Entity $entity, $options) { try { $this->UserTable->initPasswordReset($this->request->data[$options['field']]); $this->handleFlashAndRedirect('success', $options); @@ -810,7 +818,7 @@ protected function _handleFlash($type, $options) { if (isset($options[$type . 'FlashOptions'])) { $flashOptions = $options[$type . 'FlashOptions']; } - $this->Flash->set($options[$type . 'Message'], $flashOptions); + $this->Flash->$type($options[$type . 'Message'], $flashOptions); return true; } } From fab2998c9881fc926c4cbba5bc56b606339c38b9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Florian=20Kr=C3=A4mer?= Date: Tue, 16 Feb 2016 18:21:11 +0100 Subject: [PATCH 2/8] Made it possible to modify the getUser() query object. --- src/Model/Behavior/UserBehavior.php | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/Model/Behavior/UserBehavior.php b/src/Model/Behavior/UserBehavior.php index 93e0e81..55c033d 100644 --- a/src/Model/Behavior/UserBehavior.php +++ b/src/Model/Behavior/UserBehavior.php @@ -717,6 +717,10 @@ protected function _getUser($value, $options = []) { $query->where([$options['field'] => $value]); } + if (isset($options['queryCallback']) && is_callable($options['queryCallback'])) { + $query = $options['queryCallback']($query, $options); + } + $result = $query->first(); if (empty($result)) { From 6f9a83984c680087cc252149f9989d0ee22f5fc5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Florian=20Kr=C3=A4mer?= Date: Wed, 17 Feb 2016 00:18:04 +0100 Subject: [PATCH 3/8] Doc blocks and translation domain corrections --- .../Component/UserToolComponent.php | 21 +++++++++++++------ src/Model/Behavior/UserBehavior.php | 2 +- src/Template/UserTools/view.ctp | 12 +++++------ 3 files changed, 22 insertions(+), 13 deletions(-) diff --git a/src/Controller/Component/UserToolComponent.php b/src/Controller/Component/UserToolComponent.php index 65ef9e3..da036f9 100644 --- a/src/Controller/Component/UserToolComponent.php +++ b/src/Controller/Component/UserToolComponent.php @@ -364,6 +364,10 @@ public function mapAction() { return $this->_mapAction($action); } + /** + * @param string $action + * @return \Cake\Network\Response A response object containing the rendered view. + */ protected function _directMapping($action) { if (!method_exists($this, $action)) { return false; @@ -375,6 +379,12 @@ protected function _directMapping($action) { return $this->_controller->render($action); } + /** + * Maps an action of the controller to the component + * + * @param string $action + * @return bool|\Cake\Network\Response + */ protected function _mapAction($action) { $actionMap = $this->config('actionMap'); if (isset($actionMap[$action]) && method_exists($this, $actionMap[$action]['method'])) { @@ -545,19 +555,18 @@ protected function _getUserEntity($userId) { * Logout * * @param array $options Options array. - * @return void + * @return \Cake\Network\Response */ public function logout($options = []) { $options = Hash::merge($this->config('logout'), $options); $Auth = $this->_getAuthObject(); $user = $Auth->user(); + if (empty($user)) { - $this->_controller->redirect($this->_controller->referer()); - return; + return $this->_controller->redirect($this->_controller->referer()); } - $this->handleFlashAndRedirect('success', $options); - $this->_controller->redirect($Auth->logout()); - return; + + return $this->handleFlashAndRedirect('success', $options); } /** diff --git a/src/Model/Behavior/UserBehavior.php b/src/Model/Behavior/UserBehavior.php index 55c033d..1532058 100644 --- a/src/Model/Behavior/UserBehavior.php +++ b/src/Model/Behavior/UserBehavior.php @@ -595,7 +595,7 @@ protected function validationOldPassword($validator) { $validator->provider('userTable', $this->_table); $validator->add('old_password', 'notBlank', [ 'rule' => 'notBlank', - 'message' => __d('userTools', 'Enter your old password.') + 'message' => __d('user_tools', 'Enter your old password.') ]); $validator->add('old_password', 'oldPassword', [ 'rule' => ['validateOldPassword', 'password'], diff --git a/src/Template/UserTools/view.ctp b/src/Template/UserTools/view.ctp index d4613e9..fd6b743 100644 --- a/src/Template/UserTools/view.ctp +++ b/src/Template/UserTools/view.ctp @@ -1,13 +1,13 @@

username) ?>

-
+
username) ?>
-
+
email) ?>
-
+
active) ?>
-
+
email_verified) ?>
-
+
created) ?>
-
\ No newline at end of file + From 595c35d3ec019c79c445d5327f958838f04caaed Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Florian=20Kr=C3=A4mer?= Date: Wed, 17 Feb 2016 00:18:22 +0100 Subject: [PATCH 4/8] Adding the user_tools.pot --- src/Locale/user_tools.pot | 305 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 305 insertions(+) create mode 100644 src/Locale/user_tools.pot diff --git a/src/Locale/user_tools.pot b/src/Locale/user_tools.pot new file mode 100644 index 0000000..7e0527d --- /dev/null +++ b/src/Locale/user_tools.pot @@ -0,0 +1,305 @@ +# LANGUAGE translation of CakePHP Application +# Copyright YEAR NAME +# +#, fuzzy +msgid "" +msgstr "" +"Project-Id-Version: PROJECT VERSION\n" +"POT-Creation-Date: 2016-02-16 23:14+0000\n" +"PO-Revision-Date: YYYY-mm-DD HH:MM+ZZZZ\n" +"Last-Translator: NAME \n" +"Language-Team: LANGUAGE \n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=utf-8\n" +"Content-Transfer-Encoding: 8bit\n" +"Plural-Forms: nplurals=INTEGER; plural=EXPRESSION;\n" + +#: C:/xampp/htdocs/hema/vendor/burzum/cakephp-user-tools/src/Controller/Component/UserToolComponent.php:244 +msgid "An email was send to your address, please check your inbox." +msgstr "" + +#: C:/xampp/htdocs/hema/vendor/burzum/cakephp-user-tools/src/Controller/Component/UserToolComponent.php:245 +msgid "Invalid user." +msgstr "" + +#: C:/xampp/htdocs/hema/vendor/burzum/cakephp-user-tools/src/Controller/Component/UserToolComponent.php:248 +msgid "Your password has been reset, you can now login." +msgstr "" + +#: C:/xampp/htdocs/hema/vendor/burzum/cakephp-user-tools/src/Controller/Component/UserToolComponent.php:249 +msgid "Please check your inputs." +msgstr "" + +#: C:/xampp/htdocs/hema/vendor/burzum/cakephp-user-tools/src/Controller/Component/UserToolComponent.php:250 +msgid "Invalid token!" +msgstr "" + +#: C:/xampp/htdocs/hema/vendor/burzum/cakephp-user-tools/src/Controller/Component/UserToolComponent.php:251 +msgid "The token has expired!" +msgstr "" + +#: C:/xampp/htdocs/hema/vendor/burzum/cakephp-user-tools/src/Controller/Component/UserToolComponent.php:254 +msgid "Your password has been updated." +msgstr "" + +#: C:/xampp/htdocs/hema/vendor/burzum/cakephp-user-tools/src/Controller/Component/UserToolComponent.php:255 +msgid "Could not update your password, please check for errors and try again." +msgstr "" + +#: C:/xampp/htdocs/hema/vendor/burzum/cakephp-user-tools/src/Controller/Component/UserToolComponent.php:258 +msgid "Thank you for signing up!" +msgstr "" + +#: C:/xampp/htdocs/hema/vendor/burzum/cakephp-user-tools/src/Controller/Component/UserToolComponent.php:259 +msgid "Please check your inputs" +msgstr "" + +#: C:/xampp/htdocs/hema/vendor/burzum/cakephp-user-tools/src/Controller/Component/UserToolComponent.php:262 +msgid "You are logged in!" +msgstr "" + +#: C:/xampp/htdocs/hema/vendor/burzum/cakephp-user-tools/src/Controller/Component/UserToolComponent.php:263 +msgid "Invalid login credentials." +msgstr "" + +#: C:/xampp/htdocs/hema/vendor/burzum/cakephp-user-tools/src/Controller/Component/UserToolComponent.php:266 +msgid "You are logged out!" +msgstr "" + +#: C:/xampp/htdocs/hema/vendor/burzum/cakephp-user-tools/src/Controller/Component/UserToolComponent.php:269 +msgid "Email verified, you can now login!" +msgstr "" + +#: C:/xampp/htdocs/hema/vendor/burzum/cakephp-user-tools/src/Controller/Component/UserToolComponent.php:270 +msgid "Invalid email token!" +msgstr "" + +#: C:/xampp/htdocs/hema/vendor/burzum/cakephp-user-tools/src/Controller/Component/UserToolComponent.php:273 +msgid "Token verified!" +msgstr "" + +#: C:/xampp/htdocs/hema/vendor/burzum/cakephp-user-tools/src/Controller/Component/UserToolComponent.php:771 +msgid "No token present!" +msgstr "" + +#: C:/xampp/htdocs/hema/vendor/burzum/cakephp-user-tools/src/Model/Behavior/UserBehavior.php:136 +msgid "Invalid field \"%s\"!" +msgstr "" + +#: C:/xampp/htdocs/hema/vendor/burzum/cakephp-user-tools/src/Model/Behavior/UserBehavior.php:373 +msgid "Invalid token." +msgstr "" + +#: C:/xampp/htdocs/hema/vendor/burzum/cakephp-user-tools/src/Model/Behavior/UserBehavior.php:598 +msgid "Enter your old password." +msgstr "" + +#: C:/xampp/htdocs/hema/vendor/burzum/cakephp-user-tools/src/Model/Behavior/UserBehavior.php:603 +msgid "Wrong password, please try again." +msgstr "" + +#: C:/xampp/htdocs/hema/vendor/burzum/cakephp-user-tools/src/Model/Behavior/UserBehavior.php:668 +msgid "User not found." +msgstr "" + +#: C:/xampp/htdocs/hema/vendor/burzum/cakephp-user-tools/src/Model/Behavior/UserBehavior.php:705 +msgid "User not found" +msgstr "" + +#: C:/xampp/htdocs/hema/vendor/burzum/cakephp-user-tools/src/Model/Behavior/UserBehavior.php:751 +msgid "Invalid user" +msgstr "" + +#: C:/xampp/htdocs/hema/vendor/burzum/cakephp-user-tools/src/Model/Behavior/UserBehavior.php:808 +msgid "Your password reset" +msgstr "" + +#: C:/xampp/htdocs/hema/vendor/burzum/cakephp-user-tools/src/Model/Behavior/UserBehavior.php:825 +msgid "Your new password" +msgstr "" + +#: C:/xampp/htdocs/hema/vendor/burzum/cakephp-user-tools/src/Model/Behavior/UserBehavior.php:842 +msgid "Please verify your Email" +msgstr "" + +#: C:/xampp/htdocs/hema/vendor/burzum/cakephp-user-tools/src/Model/Behavior/UserBehavior.php:878 +#: C:/xampp/htdocs/hema/vendor/burzum/cakephp-user-tools/src/Validation/UsersValidator.php:37 +msgid "An username is required." +msgstr "" + +#: C:/xampp/htdocs/hema/vendor/burzum/cakephp-user-tools/src/Model/Behavior/UserBehavior.php:882 +#: C:/xampp/htdocs/hema/vendor/burzum/cakephp-user-tools/src/Validation/UsersValidator.php:41 +msgid "The username must be between 3 and 32 characters." +msgstr "" + +#: C:/xampp/htdocs/hema/vendor/burzum/cakephp-user-tools/src/Model/Behavior/UserBehavior.php:887 +#: C:/xampp/htdocs/hema/vendor/burzum/cakephp-user-tools/src/Validation/UsersValidator.php:46 +msgid "The username is already in use." +msgstr "" + +#: C:/xampp/htdocs/hema/vendor/burzum/cakephp-user-tools/src/Model/Behavior/UserBehavior.php:891 +#: C:/xampp/htdocs/hema/vendor/burzum/cakephp-user-tools/src/Validation/UsersValidator.php:50 +msgid "The username must be alpha numeric." +msgstr "" + +#: C:/xampp/htdocs/hema/vendor/burzum/cakephp-user-tools/src/Model/Behavior/UserBehavior.php:911 +#: C:/xampp/htdocs/hema/vendor/burzum/cakephp-user-tools/src/Validation/UsersValidator.php:66 +msgid "An email is required." +msgstr "" + +#: C:/xampp/htdocs/hema/vendor/burzum/cakephp-user-tools/src/Model/Behavior/UserBehavior.php:918 +#: C:/xampp/htdocs/hema/vendor/burzum/cakephp-user-tools/src/Validation/UsersValidator.php:71 +msgid "The email is already in use." +msgstr "" + +#: C:/xampp/htdocs/hema/vendor/burzum/cakephp-user-tools/src/Model/Behavior/UserBehavior.php:922 +#: C:/xampp/htdocs/hema/vendor/burzum/cakephp-user-tools/src/Validation/UsersValidator.php:75 +msgid "Must be a valid email address." +msgstr "" + +#: C:/xampp/htdocs/hema/vendor/burzum/cakephp-user-tools/src/Model/Behavior/UserBehavior.php:942;971 +#: C:/xampp/htdocs/hema/vendor/burzum/cakephp-user-tools/src/Validation/UsersValidator.php:91;116 +msgid "A password is required." +msgstr "" + +#: C:/xampp/htdocs/hema/vendor/burzum/cakephp-user-tools/src/Model/Behavior/UserBehavior.php:946;975 +#: C:/xampp/htdocs/hema/vendor/burzum/cakephp-user-tools/src/Validation/UsersValidator.php:95;120 +msgid "The password must have at least 6 characters." +msgstr "" + +#: C:/xampp/htdocs/hema/vendor/burzum/cakephp-user-tools/src/Model/Behavior/UserBehavior.php:950;979 +#: C:/xampp/htdocs/hema/vendor/burzum/cakephp-user-tools/src/Validation/UsersValidator.php:99;124 +msgid "The passwords don't match!" +msgstr "" + +#: C:/xampp/htdocs/hema/vendor/burzum/cakephp-user-tools/src/Shell/UserShell.php:65 +msgid "You need to call this command with at least tow arguments." +msgstr "" + +#: C:/xampp/htdocs/hema/vendor/burzum/cakephp-user-tools/src/Shell/UserShell.php:47 +msgid "Removed {0,number,integer} expired registration." +msgid_plural "Removed {0,number,integer} expired registrations." +msgstr[0] "" +msgstr[1] "" + +#: C:/xampp/htdocs/hema/vendor/burzum/cakephp-user-tools/src/Template/Element/login_form.ctp:4 +#: C:/xampp/htdocs/hema/vendor/burzum/cakephp-user-tools/src/Template/Element/request_password_form.ctp:4 +#: C:/xampp/htdocs/hema/vendor/burzum/cakephp-user-tools/src/Template/Element/table.ctp:4 +#: C:/xampp/htdocs/hema/vendor/burzum/cakephp-user-tools/src/Template/UserTools/view.ctp:5 +msgid "Email" +msgstr "" + +#: C:/xampp/htdocs/hema/vendor/burzum/cakephp-user-tools/src/Template/Element/login_form.ctp:9 +msgid "Password" +msgstr "" + +#: C:/xampp/htdocs/hema/vendor/burzum/cakephp-user-tools/src/Template/Element/login_form.ctp:15 +msgid "Register" +msgstr "" + +#: C:/xampp/htdocs/hema/vendor/burzum/cakephp-user-tools/src/Template/Element/login_form.ctp:17 +msgid "Reset Password" +msgstr "" + +#: C:/xampp/htdocs/hema/vendor/burzum/cakephp-user-tools/src/Template/Element/login_form.ctp:21 +#: C:/xampp/htdocs/hema/vendor/burzum/cakephp-user-tools/src/Template/UserTools/login.ctp:2 +msgid "Login" +msgstr "" + +#: C:/xampp/htdocs/hema/vendor/burzum/cakephp-user-tools/src/Template/Element/registration_form.ctp:9 +#: C:/xampp/htdocs/hema/vendor/burzum/cakephp-user-tools/src/Template/Element/table.ctp:3 +#: C:/xampp/htdocs/hema/vendor/burzum/cakephp-user-tools/src/Template/UserTools/view.ctp:3 +msgid "Username" +msgstr "" + +#: C:/xampp/htdocs/hema/vendor/burzum/cakephp-user-tools/src/Template/Element/registration_form.ctp:16 +#: C:/xampp/htdocs/hema/vendor/burzum/cakephp-user-tools/src/Template/UserTools/register.ctp:2 +msgid "Sign up" +msgstr "" + +#: C:/xampp/htdocs/hema/vendor/burzum/cakephp-user-tools/src/Template/Element/request_password_form.ctp:7 +#: C:/xampp/htdocs/hema/vendor/burzum/cakephp-user-tools/src/Template/Element/reset_password_form.ctp:12 +#: C:/xampp/htdocs/hema/vendor/burzum/cakephp-user-tools/src/Template/UserTools/change_password.ctp:21 +msgid "Submit" +msgstr "" + +#: C:/xampp/htdocs/hema/vendor/burzum/cakephp-user-tools/src/Template/Element/reset_password_form.ctp:4 +msgid "New Password" +msgstr "" + +#: C:/xampp/htdocs/hema/vendor/burzum/cakephp-user-tools/src/Template/Element/reset_password_form.ctp:9 +msgid "Repeat Password" +msgstr "" + +#: C:/xampp/htdocs/hema/vendor/burzum/cakephp-user-tools/src/Template/Element/table.ctp:5 +#: C:/xampp/htdocs/hema/vendor/burzum/cakephp-user-tools/src/Template/UserTools/view.ctp:9 +msgid "Email Verified" +msgstr "" + +#: C:/xampp/htdocs/hema/vendor/burzum/cakephp-user-tools/src/Template/Element/table.ctp:6 +#: C:/xampp/htdocs/hema/vendor/burzum/cakephp-user-tools/src/Template/UserTools/view.ctp:11 +msgid "Created" +msgstr "" + +#: C:/xampp/htdocs/hema/vendor/burzum/cakephp-user-tools/src/Template/Element/table.ctp:17 +msgid "Yes" +msgstr "" + +#: C:/xampp/htdocs/hema/vendor/burzum/cakephp-user-tools/src/Template/Element/table.ctp:17 +msgid "No" +msgstr "" + +#: C:/xampp/htdocs/hema/vendor/burzum/cakephp-user-tools/src/Template/Element/table.ctp:22 +msgid "N/A" +msgstr "" + +#: C:/xampp/htdocs/hema/vendor/burzum/cakephp-user-tools/src/Template/Email/text/Users/new_password.ctp:1 +#: C:/xampp/htdocs/hema/vendor/burzum/cakephp-user-tools/src/Template/Email/text/Users/password_reset.ctp:1 +#: C:/xampp/htdocs/hema/vendor/burzum/cakephp-user-tools/src/Template/Email/text/Users/verification_email.ctp:1 +msgid "Hello {0}!" +msgstr "" + +#: C:/xampp/htdocs/hema/vendor/burzum/cakephp-user-tools/src/Template/Email/text/Users/new_password.ctp:3 +msgid "Your new password is: %s" +msgstr "" + +#: C:/xampp/htdocs/hema/vendor/burzum/cakephp-user-tools/src/Template/Email/text/Users/password_reset.ctp:3 +msgid "Please click this link to reset your password." +msgstr "" + +#: C:/xampp/htdocs/hema/vendor/burzum/cakephp-user-tools/src/Template/Email/text/Users/verification_email.ctp:3 +msgid "Please click this link to activate your account." +msgstr "" + +#: C:/xampp/htdocs/hema/vendor/burzum/cakephp-user-tools/src/Template/UserTools/change_password.ctp:2 +msgid "Change password" +msgstr "" + +#: C:/xampp/htdocs/hema/vendor/burzum/cakephp-user-tools/src/Template/UserTools/change_password.ctp:8 +msgid "Old password" +msgstr "" + +#: C:/xampp/htdocs/hema/vendor/burzum/cakephp-user-tools/src/Template/UserTools/change_password.ctp:15 +msgid "New password" +msgstr "" + +#: C:/xampp/htdocs/hema/vendor/burzum/cakephp-user-tools/src/Template/UserTools/change_password.ctp:19 +msgid "Confirm password" +msgstr "" + +#: C:/xampp/htdocs/hema/vendor/burzum/cakephp-user-tools/src/Template/UserTools/index.ctp:2 +msgid "Users" +msgstr "" + +#: C:/xampp/htdocs/hema/vendor/burzum/cakephp-user-tools/src/Template/UserTools/request_password.ctp:2 +msgid "Request a new password" +msgstr "" + +#: C:/xampp/htdocs/hema/vendor/burzum/cakephp-user-tools/src/Template/UserTools/reset_password.ctp:2 +msgid "Reset your password" +msgstr "" + +#: C:/xampp/htdocs/hema/vendor/burzum/cakephp-user-tools/src/Template/UserTools/view.ctp:7 +msgid "Active" +msgstr "" + From 0b04c5a7d8cf80d3831a8b9a4063ed0bd166b136 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Florian=20Kr=C3=A4mer?= Date: Wed, 17 Feb 2016 00:26:34 +0100 Subject: [PATCH 5/8] Attempt to resolve #29, fixing logout redirect --- src/Controller/Component/UserToolComponent.php | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/Controller/Component/UserToolComponent.php b/src/Controller/Component/UserToolComponent.php index da036f9..dbcb85d 100644 --- a/src/Controller/Component/UserToolComponent.php +++ b/src/Controller/Component/UserToolComponent.php @@ -82,7 +82,7 @@ class UserToolComponent extends Component { ], 'logout' => [ 'successFlashOptions' => [], - 'successRedirectUrl' => '/', + 'successRedirectUrl' => null, ], 'verifyEmailToken' => [ 'queryParam' => 'token', @@ -566,6 +566,9 @@ public function logout($options = []) { return $this->_controller->redirect($this->_controller->referer()); } + if (is_null($options['successRedirectUrl'])) { + $options['successRedirectUrl'] = $Auth->logout(); + } return $this->handleFlashAndRedirect('success', $options); } From 5b163f818dfc580481a10decf538c9ca2e8d1678 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Florian=20Kr=C3=A4mer?= Date: Wed, 17 Feb 2016 01:22:54 +0100 Subject: [PATCH 6/8] Making sure UserToolsComponent::logout() calls always AuthComponent::logout() --- src/Controller/Component/UserToolComponent.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/Controller/Component/UserToolComponent.php b/src/Controller/Component/UserToolComponent.php index dbcb85d..7e472b3 100644 --- a/src/Controller/Component/UserToolComponent.php +++ b/src/Controller/Component/UserToolComponent.php @@ -566,9 +566,11 @@ public function logout($options = []) { return $this->_controller->redirect($this->_controller->referer()); } + $logoutRedirect = $Auth->logout(); if (is_null($options['successRedirectUrl'])) { - $options['successRedirectUrl'] = $Auth->logout(); + $options['successRedirectUrl'] = $logoutRedirect; } + return $this->handleFlashAndRedirect('success', $options); } From c31988916d65a07d6465258b499d57d66e3a7508 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Florian=20Kr=C3=A4mer?= Date: Wed, 17 Feb 2016 10:50:09 +0100 Subject: [PATCH 7/8] Moving the flash and redirect into a FlashAndRedirectTrait --- .../Component/FlashAndRedirectTrait.php | 70 +++++++++++++++++++ .../Component/UserToolComponent.php | 57 +-------------- 2 files changed, 71 insertions(+), 56 deletions(-) create mode 100644 src/Controller/Component/FlashAndRedirectTrait.php diff --git a/src/Controller/Component/FlashAndRedirectTrait.php b/src/Controller/Component/FlashAndRedirectTrait.php new file mode 100644 index 0000000..2f576ad --- /dev/null +++ b/src/Controller/Component/FlashAndRedirectTrait.php @@ -0,0 +1,70 @@ +_handleFlash($type, $options); + return $this->_handleRedirect($type, $options); + } + + /** + * Handles the redirect options. + * + * @param string $type Prefix for the array key, mostly "success" or "error" + * @param array $options Options + * @return mixed + */ + protected function _handleRedirect($type, $options) { + if (isset($options[$type . 'RedirectUrl']) && $options[$type . 'RedirectUrl'] !== false) { + $controller = $this->_registry->getController(); + $result = $controller->redirect($options[$type . 'RedirectUrl']); + $this->_redirectResponse = $result; + return $result; + } + return false; + } + + /** + * Handles the flash options. + * + * @param string $type Prefix for the array key, mostly "success" or "error" + * @param array $options Options + * @return boolean + */ + protected function _handleFlash($type, $options) { + if (isset($options[$type . 'Message']) && $options[$type . 'Message'] !== false) { + if (is_string($options[$type . 'Message'])) { + $flashOptions = []; + if (isset($options[$type . 'FlashOptions'])) { + $flashOptions = $options[$type . 'FlashOptions']; + } + $this->Flash->$type($options[$type . 'Message'], $flashOptions); + return true; + } + } + return false; + } +} diff --git a/src/Controller/Component/UserToolComponent.php b/src/Controller/Component/UserToolComponent.php index 7e472b3..46ee4ab 100644 --- a/src/Controller/Component/UserToolComponent.php +++ b/src/Controller/Component/UserToolComponent.php @@ -23,6 +23,7 @@ class UserToolComponent extends Component { use EventManagerTrait; + use FlashAndRedirectTrait; /** * Components @@ -201,14 +202,6 @@ class UserToolComponent extends Component { */ public $response = null; - /** - * Helper property to detect a redirect - * - * @see UserToolComponent::handleFlashAndRedirect(); - * @var \Cake\Network\Response - */ - protected $_redirectResponse = null; - /** * Convenience property to avoid the need to go through the registry all time. * @@ -791,54 +784,6 @@ public function verifyToken($options = []) { return $result; } - /** - * Handles flashes and redirects - * - * @param string $type Prefix for the array key, mostly "success" or "error" - * @param array $options Options - * @return mixed - */ - public function handleFlashAndRedirect($type, $options) { - $this->_handleFlash($type, $options); - $this->_handleRedirect($type, $options); - } - - /** - * Handles the redirect options. - * - * @param string $type Prefix for the array key, mostly "success" or "error" - * @param array $options Options - * @return mixed - */ - protected function _handleRedirect($type, $options) { - if (isset($options[$type . 'RedirectUrl']) && $options[$type . 'RedirectUrl'] !== false) { - $result = $this->_controller->redirect($options[$type . 'RedirectUrl']); - return $this->_redirectResponse = $result; - } - return false; - } - - /** - * Handles the flash options. - * - * @param string $type Prefix for the array key, mostly "success" or "error" - * @param array $options Options - * @return boolean - */ - protected function _handleFlash($type, $options) { - if (isset($options[$type . 'Message']) && $options[$type . 'Message'] !== false) { - if (is_string($options[$type . 'Message'])) { - $flashOptions = []; - if (isset($options[$type . 'FlashOptions'])) { - $flashOptions = $options[$type . 'FlashOptions']; - } - $this->Flash->$type($options[$type . 'Message'], $flashOptions); - return true; - } - } - return false; - } - /** * Gets the auth component object * From 4c066c5e0818d5b2e251135cc14506a238027afe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Florian=20Kr=C3=A4mer?= Date: Wed, 17 Feb 2016 10:50:30 +0100 Subject: [PATCH 8/8] Translations --- src/Locale/user_tools.pot | 10 +++------- src/Model/Behavior/UserBehavior.php | 2 +- 2 files changed, 4 insertions(+), 8 deletions(-) diff --git a/src/Locale/user_tools.pot b/src/Locale/user_tools.pot index 7e0527d..5c24354 100644 --- a/src/Locale/user_tools.pot +++ b/src/Locale/user_tools.pot @@ -5,7 +5,7 @@ msgid "" msgstr "" "Project-Id-Version: PROJECT VERSION\n" -"POT-Creation-Date: 2016-02-16 23:14+0000\n" +"POT-Creation-Date: 2016-02-17 00:30+0000\n" "PO-Revision-Date: YYYY-mm-DD HH:MM+ZZZZ\n" "Last-Translator: NAME \n" "Language-Team: LANGUAGE \n" @@ -78,7 +78,7 @@ msgstr "" msgid "Token verified!" msgstr "" -#: C:/xampp/htdocs/hema/vendor/burzum/cakephp-user-tools/src/Controller/Component/UserToolComponent.php:771 +#: C:/xampp/htdocs/hema/vendor/burzum/cakephp-user-tools/src/Controller/Component/UserToolComponent.php:776 msgid "No token present!" msgstr "" @@ -98,14 +98,10 @@ msgstr "" msgid "Wrong password, please try again." msgstr "" -#: C:/xampp/htdocs/hema/vendor/burzum/cakephp-user-tools/src/Model/Behavior/UserBehavior.php:668 +#: C:/xampp/htdocs/hema/vendor/burzum/cakephp-user-tools/src/Model/Behavior/UserBehavior.php:668;705 msgid "User not found." msgstr "" -#: C:/xampp/htdocs/hema/vendor/burzum/cakephp-user-tools/src/Model/Behavior/UserBehavior.php:705 -msgid "User not found" -msgstr "" - #: C:/xampp/htdocs/hema/vendor/burzum/cakephp-user-tools/src/Model/Behavior/UserBehavior.php:751 msgid "Invalid user" msgstr "" diff --git a/src/Model/Behavior/UserBehavior.php b/src/Model/Behavior/UserBehavior.php index 1532058..987d7f2 100644 --- a/src/Model/Behavior/UserBehavior.php +++ b/src/Model/Behavior/UserBehavior.php @@ -702,7 +702,7 @@ public function getUser($value, $options = []) { */ protected function _getUser($value, $options = []) { $defaults = [ - 'notFoundErrorMessage' => __d('user_tools', 'User not found'), + 'notFoundErrorMessage' => __d('user_tools', 'User not found.'), 'field' => $this->_table->alias() . '.' . $this->_table->primaryKey() ]; $options = Hash::merge($defaults, $options);