-
Notifications
You must be signed in to change notification settings - Fork 10
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Added redirection check for administrator and site owner roles. #351
Changes from 5 commits
0756377
fb2e04f
cd210d4
5e78506
e1ee67b
784661e
4458798
b13e42f
9c528e5
dd1f518
4c5b055
8d87f84
81528fd
eecf34d
9adbcb4
f5275d6
5980de5
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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. | ||
|
@@ -72,11 +73,22 @@ public function authorizeUser($name, $email, array $extra_data = []) { | |
$account->save(); | ||
} | ||
} | ||
// List of roles to redirect user login page. | ||
$userRolesArray = [ | ||
'administrator', | ||
'virtual_ymca_editor', | ||
]; | ||
// Redirecting user login page. | ||
foreach ($userRolesArray as $role) { | ||
if ($account->hasRole($role)) { | ||
$response = new RedirectResponse('/user/login', 301); | ||
$response->send(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It is better to add Drupal message which is saying that you have to login as real user, sin you are an administrator. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @anpolimus I have added Drupal message, Can you please review. |
||
} | ||
} | ||
// Instantiate GC login user event. | ||
$event = new GCUserLoginEvent($account, $extra_data); | ||
// Dispatch the event. | ||
$this->eventDispatcher->dispatch(GCUserLoginEvent::EVENT_NAME, $event); | ||
|
||
user_login_finalize($account); | ||
|
||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please, add this code above:
$loginUrl = Url::fromRoute('user.login');
and replace this line:
It will be a more stable approach. I had many projects in the past when we were renaming user login/register routes to avoid spam bots attacks. In your case, it is hard-coded.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@anpolimus I have updated the code as per you suggestion, Can you please review.