From 401466b2b7c90a4214003d3cfa4d764fc2a8d546 Mon Sep 17 00:00:00 2001 From: Chokri K Date: Mon, 23 Jul 2018 20:09:56 +0100 Subject: [PATCH 1/3] Added EVENT_AFTER_REGISTER_CONFIRM to EventManager when user valide --- src/Controller/Component/UsersAuthComponent.php | 1 + src/Controller/Traits/UserValidationTrait.php | 9 +++++++++ 2 files changed, 10 insertions(+) diff --git a/src/Controller/Component/UsersAuthComponent.php b/src/Controller/Component/UsersAuthComponent.php index f45ef42a4..d5d218ea6 100644 --- a/src/Controller/Component/UsersAuthComponent.php +++ b/src/Controller/Component/UsersAuthComponent.php @@ -30,6 +30,7 @@ class UsersAuthComponent extends Component const EVENT_AFTER_COOKIE_LOGIN = 'Users.Component.UsersAuth.afterCookieLogin'; const EVENT_BEFORE_REGISTER = 'Users.Component.UsersAuth.beforeRegister'; const EVENT_AFTER_REGISTER = 'Users.Component.UsersAuth.afterRegister'; + const EVENT_AFTER_REGISTER_CONFIRM = 'Users.Component.UsersAuth.afterRegister.confirm'; const EVENT_BEFORE_LOGOUT = 'Users.Component.UsersAuth.beforeLogout'; const EVENT_AFTER_LOGOUT = 'Users.Component.UsersAuth.afterLogout'; const EVENT_BEFORE_SOCIAL_LOGIN_USER_CREATE = 'Users.Component.UsersAuth.beforeSocialLoginUserCreate'; diff --git a/src/Controller/Traits/UserValidationTrait.php b/src/Controller/Traits/UserValidationTrait.php index 2229c7abb..e7c95dad0 100644 --- a/src/Controller/Traits/UserValidationTrait.php +++ b/src/Controller/Traits/UserValidationTrait.php @@ -11,6 +11,8 @@ namespace CakeDC\Users\Controller\Traits; +use CakeDC\Users\Controller\Component\UsersAuthComponent; +use Cake\Event\Event; use CakeDC\Users\Exception\TokenExpiredException; use CakeDC\Users\Exception\UserAlreadyActiveException; use CakeDC\Users\Exception\UserNotFoundException; @@ -39,7 +41,14 @@ public function validate($type = null, $token = null) case 'email': try { $result = $this->getUsersTable()->validate($token, 'activateUser'); + if ($result) { + $event = $this->dispatchEvent(UsersAuthComponent::EVENT_AFTER_REGISTER, [ + 'user' => $result + ]); + if ($event->result instanceof Response) { + return $this->redirect(['action' => 'login']); + } $this->Flash->success(__d('CakeDC/Users', 'User account validated successfully')); } else { $this->Flash->error(__d('CakeDC/Users', 'User account could not be validated')); From e31d2f56588e9210ebd42e18e937680485e5125c Mon Sep 17 00:00:00 2001 From: Chokri K Date: Mon, 23 Jul 2018 20:12:32 +0100 Subject: [PATCH 2/3] Missing CONFIRM --- src/Controller/Traits/UserValidationTrait.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Controller/Traits/UserValidationTrait.php b/src/Controller/Traits/UserValidationTrait.php index e7c95dad0..53781087c 100644 --- a/src/Controller/Traits/UserValidationTrait.php +++ b/src/Controller/Traits/UserValidationTrait.php @@ -43,7 +43,7 @@ public function validate($type = null, $token = null) $result = $this->getUsersTable()->validate($token, 'activateUser'); if ($result) { - $event = $this->dispatchEvent(UsersAuthComponent::EVENT_AFTER_REGISTER, [ + $event = $this->dispatchEvent(UsersAuthComponent::EVENT_AFTER_REGISTER_CONFIRM, [ 'user' => $result ]); if ($event->result instanceof Response) { From fd0b055181f1c5518c3d032aae3b32428b5a088f Mon Sep 17 00:00:00 2001 From: Chokri K Date: Tue, 24 Jul 2018 15:31:37 +0100 Subject: [PATCH 3/3] adding data-theme, data-size and data-tabindex to addReCaptcha function --- src/Controller/Traits/ProfileTrait.php | 4 ++-- src/View/Helper/UserHelper.php | 5 ++++- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/src/Controller/Traits/ProfileTrait.php b/src/Controller/Traits/ProfileTrait.php index db61724d3..f7c18a443 100644 --- a/src/Controller/Traits/ProfileTrait.php +++ b/src/Controller/Traits/ProfileTrait.php @@ -40,8 +40,8 @@ public function profile($id = null) $appContain = (array)Configure::read('Auth.authenticate.' . AuthComponent::ALL . '.contain'); $socialContain = Configure::read('Users.Social.login') ? ['SocialAccounts']: []; $user = $this->getUsersTable()->get($id, [ - 'contain' => array_merge((array)$appContain, (array)$socialContain) - ]); + 'contain' => array_merge((array)$appContain, (array)$socialContain) + ]); $this->set('avatarPlaceholder', Configure::read('Users.Avatar.placeholder')); if ($user->id === $loggedUserId) { $isCurrentUser = true; diff --git a/src/View/Helper/UserHelper.php b/src/View/Helper/UserHelper.php index c1f4cb7b7..e59f85b5a 100644 --- a/src/View/Helper/UserHelper.php +++ b/src/View/Helper/UserHelper.php @@ -146,7 +146,10 @@ public function addReCaptcha() return $this->Html->tag('div', '', [ 'class' => 'g-recaptcha', - 'data-sitekey' => Configure::read('Users.reCaptcha.key') + 'data-sitekey' => Configure::read('Users.reCaptcha.key'), + 'data-theme' => Configure::read('Users.reCaptcha.theme') ?: 'light', + 'data-size' => Configure::read('Users.reCaptcha.size') ?: 'normal', + 'data-tabindex' => Configure::read('Users.reCaptcha.tabindex') ?: '3', ]); }