Skip to content
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

Closed
wants to merge 17 commits into from
Closed

Added redirection check for administrator and site owner roles. #351

wants to merge 17 commits into from

Conversation

kairamkondarajesh
Copy link

ymcatwincities#140

Steps to test:

  • Pull the code from openy-140 branch.
  • Locate a staff member (Site Owner and/or Virtual YMCA Editor roles) with an email address registered within Nationwide Membership. Example: [email protected]
  • Attempt a login with this email address on the Virtual Y Login landing page.
  • image
  • If the staff user had administrator or site owner roles prior to this login, they should redirect to user/login page.

// Redirecting user login page.
$userRolesArray = [
'administrator',
'site_owner',
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@kairamkondarajesh site_owner is a Y Cloud specific role and should not be here. You'll need to provide a way for this array to be supplemented by other code, or provide a comment that suggests that it be patched in case new roles need to be added.

@hamrant hamrant requested a review from anpolimus July 1, 2021 06:45
@fivejars fivejars deleted a comment from fjbot Jul 1, 2021
@fivejars fivejars deleted a comment from fjbot Jul 1, 2021
@fivejars fivejars deleted a comment from fjbot Jul 1, 2021
@fivejars fivejars deleted a comment from fjbot Jul 1, 2021
@fivejars fivejars deleted a comment from fjbot Jul 1, 2021
@fivejars fivejars deleted a comment from fjbot Jul 1, 2021
@fivejars fivejars deleted a comment from fjbot Jul 1, 2021
@fivejars fivejars deleted a comment from fjbot Jul 1, 2021
// Redirecting user login page.
foreach ($userRolesArray as $role) {
if ($account->hasRole($role)) {
$response = new RedirectResponse('/user/login', 301);

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:

Suggested change
$response = new RedirectResponse('/user/login', 301);
$response = new RedirectResponse($loginUrl, 301);

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.

Copy link
Author

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.

foreach ($userRolesArray as $role) {
if ($account->hasRole($role)) {
$response = new RedirectResponse('/user/login', 301);
$response->send();

Choose a reason for hiding this comment

The 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.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@anpolimus I have added Drupal message, Can you please review.

@fjbot
Copy link

fjbot commented Jul 15, 2021

Build 3293
Coding standards checks failed.
See https://ci.fivejars.com/job/OPENY_GC_PR/3293/display/redirect

@fjbot
Copy link

fjbot commented Jul 15, 2021

Build 3293
Build failed.
See https://ci.fivejars.com/job/OPENY_GC_PR/3293/display/redirect for details.

@fjbot
Copy link

fjbot commented Jul 15, 2021

Build 3294
Coding standards checks failed.
See https://ci.fivejars.com/job/OPENY_GC_PR/3294/display/redirect

@fjbot
Copy link

fjbot commented Jul 15, 2021

Build 3294
Build failed.
See https://ci.fivejars.com/job/OPENY_GC_PR/3294/display/redirect for details.

@fjbot
Copy link

fjbot commented Jul 15, 2021

Build 3295
Coding standards checks failed.
See https://ci.fivejars.com/job/OPENY_GC_PR/3295/display/redirect

@fjbot
Copy link

fjbot commented Jul 15, 2021

Build 3295
Build failed.
See https://ci.fivejars.com/job/OPENY_GC_PR/3295/display/redirect for details.

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.'));
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Saying this user is an administrator could be a security risk. I'd suggest rewriting this to:

Please retry your login on this form.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated message. Please review.

anpolimus
anpolimus previously approved these changes Aug 16, 2021
@anpolimus
Copy link

@AnastasiiaPys we have to QA it.

@AnastasiiaPys
Copy link

AnastasiiaPys commented Aug 16, 2021

Tested on macOS(Chrome). Please review my steps to reproduce whether I did it correct

  • log in to the site as admin

  • enable Y-USA auth provider

  • log in to the site as user

  • assign to this user Contributor role

  • in the anonymous window go to Landing page and enter user's email

Expected behavior: the user is redirected to the /user/login page

Actual result: the user is logged in as Contributor
https://monosnap.com/file/Chjz94YsQzyCYi72A0l7vzayfvnust

The test failed.

@kairamkondarajesh
Copy link
Author

kairamkondarajesh commented Aug 16, 2021

Tested on macOS(Chrome). Please review my steps to reproduce whether I did it correct

  • log in to the site as admin
  • enable Y-USA auth provider
  • log in to the site as user
  • assign to this user Contributor role
  • in the anonymous window go to Landing page and enter user's email

Expected behavior: the user is redirected to the /user/login page

Actual result: the user is logged in as Contributor
https://monosnap.com/file/Chjz94YsQzyCYi72A0l7vzayfvnust

The test failed.

We are checking two user roles ( 'administrator', 'virtual_ymca_editor') to redirect to /user/login page when they try login from landing page user email option.

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.'));
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This line is throwing an error:

Error: Call to undefined method Drupal\openy_gc_auth\GCUserAuthorizer::t() in Drupal\openy_gc_auth\GCUserAuthorizer->authorizeUser() (line 97 of /.../docroot/modules/contrib/openy_gated_content/modules/openy_gc_auth/src/GCUserAuthorizer.php)

We're reviewing for a fix.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated the code as per suggestions, Please review.

@fjbot
Copy link

fjbot commented Aug 20, 2021

Build 4251
Coding standards checks failed.
See https://ci.fivejars.com/job/OPENY_GC_PR/4251/display/redirect

@fjbot
Copy link

fjbot commented Aug 20, 2021

Build 4251
Build failed.
See https://ci.fivejars.com/job/OPENY_GC_PR/4251/display/redirect for details.

@fjbot
Copy link

fjbot commented Aug 20, 2021

Build 4252
Coding standards checks failed.
See https://ci.fivejars.com/job/OPENY_GC_PR/4252/display/redirect

@fjbot
Copy link

fjbot commented Aug 20, 2021

Build 4252
Build failed.
See https://ci.fivejars.com/job/OPENY_GC_PR/4252/display/redirect for details.

@fjbot
Copy link

fjbot commented Aug 20, 2021

Build 4253
Coding standards checks failed.
See https://ci.fivejars.com/job/OPENY_GC_PR/4253/display/redirect

@fjbot
Copy link

fjbot commented Aug 20, 2021

Build 4253
Build failed.
See https://ci.fivejars.com/job/OPENY_GC_PR/4253/display/redirect for details.

@anpolimus
Copy link

@kairamkondarajesh ,please fix conflicts.
Your builds should work now

@fjbot
Copy link

fjbot commented Nov 23, 2021

Build 4414
Coding standards checks failed.
See https://ci.fivejars.com/job/OPENY_GC_PR/4414/display/redirect

@fjbot
Copy link

fjbot commented Nov 23, 2021

Build 4414
Build failed.
See https://ci.fivejars.com/job/OPENY_GC_PR/4414/display/redirect for details.

@kairamkondarajesh kairamkondarajesh closed this by deleting the head repository Nov 22, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants