From 0756377b6e825657aa7d8b9f18716c6059d8092e Mon Sep 17 00:00:00 2001 From: Rajesh KAIRAMKONDA Date: Tue, 8 Jun 2021 19:21:40 +0530 Subject: [PATCH 01/15] Added redirection check for administrator and site owner roles. --- modules/openy_gc_auth/src/GCUserAuthorizer.php | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/modules/openy_gc_auth/src/GCUserAuthorizer.php b/modules/openy_gc_auth/src/GCUserAuthorizer.php index 5b923594d..ae6240e48 100644 --- a/modules/openy_gc_auth/src/GCUserAuthorizer.php +++ b/modules/openy_gc_auth/src/GCUserAuthorizer.php @@ -72,6 +72,14 @@ public function authorizeUser($name, $email, array $extra_data = []) { $account->save(); } } + // Redirecting user login page. + $userRolesArray = ['administrator', 'site_owner']; + foreach ($userRolesArray as $key => $role) { + if($account->hasRole($role)) { + $response = new RedirectResponse('/user/login', 301); + $response->send(); + } + } // Instantiate GC login user event. $event = new GCUserLoginEvent($account, $extra_data); // Dispatch the event. From fb2e04f09e644f68824fd840736d6fb1a6a28dd9 Mon Sep 17 00:00:00 2001 From: Rajesh KAIRAMKONDA Date: Tue, 8 Jun 2021 19:53:03 +0530 Subject: [PATCH 02/15] Added redirection check for administrator and site owner roles. --- modules/openy_gc_auth/src/GCUserAuthorizer.php | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/modules/openy_gc_auth/src/GCUserAuthorizer.php b/modules/openy_gc_auth/src/GCUserAuthorizer.php index ae6240e48..3366661d0 100644 --- a/modules/openy_gc_auth/src/GCUserAuthorizer.php +++ b/modules/openy_gc_auth/src/GCUserAuthorizer.php @@ -5,6 +5,7 @@ use Drupal\Core\Entity\EntityTypeManagerInterface; use Drupal\openy_gc_auth\Event\GCUserLoginEvent; use Symfony\Component\EventDispatcher\EventDispatcherInterface; +use Symfony\Component\HttpFoundation\RedirectResponse; /** * User Authorizer class. @@ -73,9 +74,13 @@ public function authorizeUser($name, $email, array $extra_data = []) { } } // Redirecting user login page. - $userRolesArray = ['administrator', 'site_owner']; - foreach ($userRolesArray as $key => $role) { - if($account->hasRole($role)) { + $userRolesArray = [ + 'administrator', + 'site_owner', + 'virtual_ymca_editor' + ]; + foreach ($userRolesArray as $role) { + if ($account->hasRole($role)) { $response = new RedirectResponse('/user/login', 301); $response->send(); } From cd210d43e0a8a5aaf8880a4fb2c768c5fdfa4fbb Mon Sep 17 00:00:00 2001 From: Rajesh KAIRAMKONDA Date: Tue, 8 Jun 2021 19:56:32 +0530 Subject: [PATCH 03/15] Added redirection check for administrator and site owner roles. --- modules/openy_gc_auth/src/GCUserAuthorizer.php | 1 - 1 file changed, 1 deletion(-) diff --git a/modules/openy_gc_auth/src/GCUserAuthorizer.php b/modules/openy_gc_auth/src/GCUserAuthorizer.php index 3366661d0..5867388d5 100644 --- a/modules/openy_gc_auth/src/GCUserAuthorizer.php +++ b/modules/openy_gc_auth/src/GCUserAuthorizer.php @@ -76,7 +76,6 @@ public function authorizeUser($name, $email, array $extra_data = []) { // Redirecting user login page. $userRolesArray = [ 'administrator', - 'site_owner', 'virtual_ymca_editor' ]; foreach ($userRolesArray as $role) { From 5e7850642c03ce7149507416e133142e20b6d34d Mon Sep 17 00:00:00 2001 From: Rajesh KAIRAMKONDA Date: Tue, 8 Jun 2021 20:10:31 +0530 Subject: [PATCH 04/15] Added redirection check for administrator and site owner roles. --- modules/openy_gc_auth/src/GCUserAuthorizer.php | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/modules/openy_gc_auth/src/GCUserAuthorizer.php b/modules/openy_gc_auth/src/GCUserAuthorizer.php index 5867388d5..d2d624f80 100644 --- a/modules/openy_gc_auth/src/GCUserAuthorizer.php +++ b/modules/openy_gc_auth/src/GCUserAuthorizer.php @@ -73,11 +73,12 @@ public function authorizeUser($name, $email, array $extra_data = []) { $account->save(); } } - // Redirecting user login page. + // List of roles to redirect user login page. $userRolesArray = [ 'administrator', - 'virtual_ymca_editor' + 'virtual_ymca_editor', ]; + // Redirecting user login page. foreach ($userRolesArray as $role) { if ($account->hasRole($role)) { $response = new RedirectResponse('/user/login', 301); From e1ee67b21f2de669c9c65b4883ddbf43dbf86211 Mon Sep 17 00:00:00 2001 From: Rajesh KAIRAMKONDA Date: Wed, 9 Jun 2021 04:55:34 +0530 Subject: [PATCH 05/15] Resolved php coding standards --- modules/openy_gc_auth/src/GCUserAuthorizer.php | 1 - 1 file changed, 1 deletion(-) diff --git a/modules/openy_gc_auth/src/GCUserAuthorizer.php b/modules/openy_gc_auth/src/GCUserAuthorizer.php index d2d624f80..67cf9e689 100644 --- a/modules/openy_gc_auth/src/GCUserAuthorizer.php +++ b/modules/openy_gc_auth/src/GCUserAuthorizer.php @@ -89,7 +89,6 @@ public function authorizeUser($name, $email, array $extra_data = []) { $event = new GCUserLoginEvent($account, $extra_data); // Dispatch the event. $this->eventDispatcher->dispatch(GCUserLoginEvent::EVENT_NAME, $event); - user_login_finalize($account); } From 784661ea71cae8ddf3b3818025af622d44f5f395 Mon Sep 17 00:00:00 2001 From: Rajesh KAIRAMKONDA Date: Fri, 16 Jul 2021 01:10:36 +0530 Subject: [PATCH 06/15] Resolved the coding standard suggestions. --- .../openy_gc_auth/openy_gc_auth.services.yml | 2 +- modules/openy_gc_auth/src/GCUserAuthorizer.php | 17 ++++++++++++++--- 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/modules/openy_gc_auth/openy_gc_auth.services.yml b/modules/openy_gc_auth/openy_gc_auth.services.yml index 9c67bc9c9..66bab00c6 100644 --- a/modules/openy_gc_auth/openy_gc_auth.services.yml +++ b/modules/openy_gc_auth/openy_gc_auth.services.yml @@ -14,4 +14,4 @@ services: openy_gc_auth.user_authorizer: class: Drupal\openy_gc_auth\GCUserAuthorizer - arguments: ['@entity_type.manager', '@event_dispatcher'] + arguments: ['@entity_type.manager', '@event_dispatcher', '@messenger'] diff --git a/modules/openy_gc_auth/src/GCUserAuthorizer.php b/modules/openy_gc_auth/src/GCUserAuthorizer.php index 67cf9e689..74b684667 100644 --- a/modules/openy_gc_auth/src/GCUserAuthorizer.php +++ b/modules/openy_gc_auth/src/GCUserAuthorizer.php @@ -6,6 +6,8 @@ use Drupal\openy_gc_auth\Event\GCUserLoginEvent; use Symfony\Component\EventDispatcher\EventDispatcherInterface; use Symfony\Component\HttpFoundation\RedirectResponse; +use Drupal\Core\Url; +use Drupal\Core\Messenger\MessengerInterface; /** * User Authorizer class. @@ -28,6 +30,13 @@ class GCUserAuthorizer { */ protected $eventDispatcher; + /** + * The Messenger service. + * + * @var \Drupal\Core\Messenger\MessengerInterface + */ + protected $messenger; + /** * GCUserAuthorizer constructor. * @@ -36,9 +45,10 @@ class GCUserAuthorizer { * @param \Symfony\Component\EventDispatcher\EventDispatcherInterface $event_dispatcher * Event dispatcher. */ - public function __construct(EntityTypeManagerInterface $entityTypeManager, EventDispatcherInterface $event_dispatcher) { + public function __construct(EntityTypeManagerInterface $entityTypeManager, EventDispatcherInterface $event_dispatcher, MessengerInterface $messenger) { $this->userStorage = $entityTypeManager->getStorage('user'); $this->eventDispatcher = $event_dispatcher; + $this->messenger = $messenger; } /** @@ -81,8 +91,9 @@ public function authorizeUser($name, $email, array $extra_data = []) { // Redirecting user login page. foreach ($userRolesArray as $role) { if ($account->hasRole($role)) { - $response = new RedirectResponse('/user/login', 301); - $response->send(); + $loginUrl = Url::fromRoute('user.login')->toString(); + $this->messenger->addMessage(t('You have to login as real user, since you are an administrator.')); + return new RedirectResponse($loginUrl, 302); } } // Instantiate GC login user event. From 44587980559eb0ede607a1d47f70af0b94aaf959 Mon Sep 17 00:00:00 2001 From: Rajesh KAIRAMKONDA Date: Fri, 16 Jul 2021 01:19:23 +0530 Subject: [PATCH 07/15] Resolved the coding standard suggestions. --- modules/openy_gc_auth/src/GCUserAuthorizer.php | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/modules/openy_gc_auth/src/GCUserAuthorizer.php b/modules/openy_gc_auth/src/GCUserAuthorizer.php index 74b684667..b92f73465 100644 --- a/modules/openy_gc_auth/src/GCUserAuthorizer.php +++ b/modules/openy_gc_auth/src/GCUserAuthorizer.php @@ -6,8 +6,8 @@ use Drupal\openy_gc_auth\Event\GCUserLoginEvent; use Symfony\Component\EventDispatcher\EventDispatcherInterface; use Symfony\Component\HttpFoundation\RedirectResponse; -use Drupal\Core\Url; use Drupal\Core\Messenger\MessengerInterface; +use Drupal\Core\Url; /** * User Authorizer class. @@ -44,6 +44,8 @@ class GCUserAuthorizer { * Entity Type Manager. * @param \Symfony\Component\EventDispatcher\EventDispatcherInterface $event_dispatcher * Event dispatcher. + * @param \Drupal\Core\Messenger\MessengerInterface $messenger + * The messenger service. */ public function __construct(EntityTypeManagerInterface $entityTypeManager, EventDispatcherInterface $event_dispatcher, MessengerInterface $messenger) { $this->userStorage = $entityTypeManager->getStorage('user'); @@ -92,7 +94,7 @@ public function authorizeUser($name, $email, array $extra_data = []) { foreach ($userRolesArray as $role) { if ($account->hasRole($role)) { $loginUrl = Url::fromRoute('user.login')->toString(); - $this->messenger->addMessage(t('You have to login as real user, since you are an administrator.')); + $this->messenger->addMessage($this->t('You have to login as real user, since you are an administrator.')); return new RedirectResponse($loginUrl, 302); } } From b13e42fe8a6b3ec9dede29c916a86b53d2a84654 Mon Sep 17 00:00:00 2001 From: Rajesh KAIRAMKONDA Date: Fri, 16 Jul 2021 01:26:52 +0530 Subject: [PATCH 08/15] Resolved the coding standard suggestions. --- modules/openy_gc_auth/src/GCUserAuthorizer.php | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/modules/openy_gc_auth/src/GCUserAuthorizer.php b/modules/openy_gc_auth/src/GCUserAuthorizer.php index b92f73465..31d609742 100644 --- a/modules/openy_gc_auth/src/GCUserAuthorizer.php +++ b/modules/openy_gc_auth/src/GCUserAuthorizer.php @@ -4,10 +4,11 @@ use Drupal\Core\Entity\EntityTypeManagerInterface; use Drupal\openy_gc_auth\Event\GCUserLoginEvent; -use Symfony\Component\EventDispatcher\EventDispatcherInterface; -use Symfony\Component\HttpFoundation\RedirectResponse; use Drupal\Core\Messenger\MessengerInterface; use Drupal\Core\Url; +use Symfony\Component\EventDispatcher\EventDispatcherInterface; +use Symfony\Component\HttpFoundation\RedirectResponse; + /** * User Authorizer class. @@ -44,7 +45,7 @@ class GCUserAuthorizer { * Entity Type Manager. * @param \Symfony\Component\EventDispatcher\EventDispatcherInterface $event_dispatcher * Event dispatcher. - * @param \Drupal\Core\Messenger\MessengerInterface $messenger + * @param \Drupal\Core\Messenger\MessengerInterface $messenger * The messenger service. */ public function __construct(EntityTypeManagerInterface $entityTypeManager, EventDispatcherInterface $event_dispatcher, MessengerInterface $messenger) { From 9c528e5338e73221a188d2cb0415188fb511570d Mon Sep 17 00:00:00 2001 From: Rajesh KAIRAMKONDA Date: Fri, 16 Jul 2021 01:39:23 +0530 Subject: [PATCH 09/15] Resolved the coding standard suggestions. --- modules/openy_gc_auth/src/GCUserAuthorizer.php | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/modules/openy_gc_auth/src/GCUserAuthorizer.php b/modules/openy_gc_auth/src/GCUserAuthorizer.php index 31d609742..4da6798cb 100644 --- a/modules/openy_gc_auth/src/GCUserAuthorizer.php +++ b/modules/openy_gc_auth/src/GCUserAuthorizer.php @@ -4,11 +4,10 @@ use Drupal\Core\Entity\EntityTypeManagerInterface; use Drupal\openy_gc_auth\Event\GCUserLoginEvent; -use Drupal\Core\Messenger\MessengerInterface; -use Drupal\Core\Url; use Symfony\Component\EventDispatcher\EventDispatcherInterface; use Symfony\Component\HttpFoundation\RedirectResponse; - +use Drupal\Core\Url; +use Drupal\Core\Messenger\MessengerInterface; /** * User Authorizer class. From dd1f51815b9c47205b2713997204b81798fe4c4c Mon Sep 17 00:00:00 2001 From: Rajesh KAIRAMKONDA Date: Fri, 16 Jul 2021 01:52:08 +0530 Subject: [PATCH 10/15] Resolved the coding standard suggestions. --- modules/openy_gc_auth/src/GCUserAuthorizer.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/modules/openy_gc_auth/src/GCUserAuthorizer.php b/modules/openy_gc_auth/src/GCUserAuthorizer.php index 4da6798cb..059a2c943 100644 --- a/modules/openy_gc_auth/src/GCUserAuthorizer.php +++ b/modules/openy_gc_auth/src/GCUserAuthorizer.php @@ -3,11 +3,11 @@ namespace Drupal\openy_gc_auth; use Drupal\Core\Entity\EntityTypeManagerInterface; +use Drupal\Core\Messenger\MessengerInterface; +use Drupal\Core\Url; use Drupal\openy_gc_auth\Event\GCUserLoginEvent; use Symfony\Component\EventDispatcher\EventDispatcherInterface; use Symfony\Component\HttpFoundation\RedirectResponse; -use Drupal\Core\Url; -use Drupal\Core\Messenger\MessengerInterface; /** * User Authorizer class. From 4c5b055d5363a4dcb7e3722c883dbe3105d6a9e4 Mon Sep 17 00:00:00 2001 From: Rajesh KAIRAMKONDA Date: Tue, 3 Aug 2021 15:30:24 +0530 Subject: [PATCH 11/15] Updated the message for redirected users. --- modules/openy_gc_auth/src/GCUserAuthorizer.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/openy_gc_auth/src/GCUserAuthorizer.php b/modules/openy_gc_auth/src/GCUserAuthorizer.php index 059a2c943..2d00ddf97 100644 --- a/modules/openy_gc_auth/src/GCUserAuthorizer.php +++ b/modules/openy_gc_auth/src/GCUserAuthorizer.php @@ -94,7 +94,7 @@ public function authorizeUser($name, $email, array $extra_data = []) { foreach ($userRolesArray as $role) { if ($account->hasRole($role)) { $loginUrl = Url::fromRoute('user.login')->toString(); - $this->messenger->addMessage($this->t('You have to login as real user, since you are an administrator.')); + $this->messenger->addMessage($this->t('Please retry your login on this form.')); return new RedirectResponse($loginUrl, 302); } } From 81528fd804161896b3c8822612a563346997c3e0 Mon Sep 17 00:00:00 2001 From: Rajesh K Date: Fri, 20 Aug 2021 07:00:22 +0530 Subject: [PATCH 12/15] Used string translation trait to use t function in the classes. --- modules/openy_gc_auth/src/GCUserAuthorizer.php | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/modules/openy_gc_auth/src/GCUserAuthorizer.php b/modules/openy_gc_auth/src/GCUserAuthorizer.php index 2d00ddf97..8e1b0419d 100644 --- a/modules/openy_gc_auth/src/GCUserAuthorizer.php +++ b/modules/openy_gc_auth/src/GCUserAuthorizer.php @@ -8,12 +8,16 @@ use Drupal\openy_gc_auth\Event\GCUserLoginEvent; use Symfony\Component\EventDispatcher\EventDispatcherInterface; use Symfony\Component\HttpFoundation\RedirectResponse; +use Drupal\Core\StringTranslation\StringTranslationTrait; +use Drupal\Core\Link; /** * User Authorizer class. */ class GCUserAuthorizer { + use StringTranslationTrait; + const VIRTUAL_Y_DEFAULT_ROLE = 'virtual_y'; /** @@ -93,9 +97,13 @@ public function authorizeUser($name, $email, array $extra_data = []) { // Redirecting user login page. foreach ($userRolesArray as $role) { if ($account->hasRole($role)) { - $loginUrl = Url::fromRoute('user.login')->toString(); - $this->messenger->addMessage($this->t('Please retry your login on this form.')); - return new RedirectResponse($loginUrl, 302); + $link = Link::createFromRoute($this->t('Login'), + 'user.login', + )->toString(); + $this->messenger->addStatus($this->t('Please retry your login from this link. @link', [ + '@link' => $link, + ])); + return; } } // Instantiate GC login user event. From eecf34ddeac7a1d1a445bf3ab51b0dfcb992fd10 Mon Sep 17 00:00:00 2001 From: Rajesh K Date: Fri, 20 Aug 2021 08:23:19 +0530 Subject: [PATCH 13/15] Used string translation trait to use t function in the classes. --- modules/openy_gc_auth/src/GCUserAuthorizer.php | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/modules/openy_gc_auth/src/GCUserAuthorizer.php b/modules/openy_gc_auth/src/GCUserAuthorizer.php index 8e1b0419d..e948e0aab 100644 --- a/modules/openy_gc_auth/src/GCUserAuthorizer.php +++ b/modules/openy_gc_auth/src/GCUserAuthorizer.php @@ -4,13 +4,10 @@ use Drupal\Core\Entity\EntityTypeManagerInterface; use Drupal\Core\Messenger\MessengerInterface; -use Drupal\Core\Url; use Drupal\openy_gc_auth\Event\GCUserLoginEvent; use Symfony\Component\EventDispatcher\EventDispatcherInterface; -use Symfony\Component\HttpFoundation\RedirectResponse; -use Drupal\Core\StringTranslation\StringTranslationTrait; use Drupal\Core\Link; - +use Drupal\Core\StringTranslation\StringTranslationTrait; /** * User Authorizer class. */ From 9adbcb44fa0e823dd845de4b9086d912d8757d95 Mon Sep 17 00:00:00 2001 From: Rajesh K Date: Fri, 20 Aug 2021 08:31:40 +0530 Subject: [PATCH 14/15] Used string translation trait to use t function in the classes. --- modules/openy_gc_auth/src/GCUserAuthorizer.php | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/modules/openy_gc_auth/src/GCUserAuthorizer.php b/modules/openy_gc_auth/src/GCUserAuthorizer.php index e948e0aab..0deaaa6bf 100644 --- a/modules/openy_gc_auth/src/GCUserAuthorizer.php +++ b/modules/openy_gc_auth/src/GCUserAuthorizer.php @@ -4,10 +4,11 @@ use Drupal\Core\Entity\EntityTypeManagerInterface; use Drupal\Core\Messenger\MessengerInterface; -use Drupal\openy_gc_auth\Event\GCUserLoginEvent; -use Symfony\Component\EventDispatcher\EventDispatcherInterface; use Drupal\Core\Link; use Drupal\Core\StringTranslation\StringTranslationTrait; +use Drupal\openy_gc_auth\Event\GCUserLoginEvent; +use Symfony\Component\EventDispatcher\EventDispatcherInterface; + /** * User Authorizer class. */ From f5275d67c0c6b989dadaf7761fc8f7a99bc2388b Mon Sep 17 00:00:00 2001 From: Rajesh K Date: Fri, 20 Aug 2021 11:40:12 +0530 Subject: [PATCH 15/15] Used string translation trait to use t function in the classes. --- modules/openy_gc_auth/src/GCUserAuthorizer.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/openy_gc_auth/src/GCUserAuthorizer.php b/modules/openy_gc_auth/src/GCUserAuthorizer.php index 0deaaa6bf..2c4da6ade 100644 --- a/modules/openy_gc_auth/src/GCUserAuthorizer.php +++ b/modules/openy_gc_auth/src/GCUserAuthorizer.php @@ -3,8 +3,8 @@ namespace Drupal\openy_gc_auth; use Drupal\Core\Entity\EntityTypeManagerInterface; -use Drupal\Core\Messenger\MessengerInterface; use Drupal\Core\Link; +use Drupal\Core\Messenger\MessengerInterface; use Drupal\Core\StringTranslation\StringTranslationTrait; use Drupal\openy_gc_auth\Event\GCUserLoginEvent; use Symfony\Component\EventDispatcher\EventDispatcherInterface;