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

Issue #55: [UPD] make userkey respect suspended status of users #87

Open
wants to merge 3 commits into
base: MOODLE_33PLUS
Choose a base branch
from

Conversation

IJOL
Copy link

@IJOL IJOL commented Nov 14, 2022

No description provided.

auth.php Outdated Show resolved Hide resolved
@dmitriim
Copy link
Member

Hi @IJOL !

Thanks for your patch. It mostly looks ok. Just a couple of things to fix before we can land it,

  1. Can you please create an issue describing the problem you are trying to solve. This is for others who may be struggling to know that it has been fixed.
  2. Can you please add automatic tests to cover a new logic?

@dmitriim
Copy link
Member

dmitriim commented Mar 30, 2023

Hi @IJOL any chance you can fix issues before we can merge the code in?

@dmitriim dmitriim changed the title [UPD] make userkey respect suspended status of users Issue #55: [UPD] make userkey respect suspended status of users May 17, 2023
…ing event will add a log record to an application log."
@IJOL
Copy link
Author

IJOL commented Aug 2, 2023

Hmm, is starting to be self evident that i need some help to pass the tests, is my first test case for php ever, and I'm little confused.. any help will be great..


$user = $this->getDataGenerator()->create_user();
$user->suspended = 1;
$this->setUser($user);
Copy link
Member

Choose a reason for hiding this comment

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

What are you trying to test here? I don't think you need set a user here and then try to login again, but using a key.

public function test_throwing_exception_if_user_is_suspended() {
global $USER, $SESSION;

$user = $this->getDataGenerator()->create_user();
Copy link
Member

Choose a reason for hiding this comment

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

there is already created user for the test. You can use $this->user.

global $USER, $SESSION;

$user = $this->getDataGenerator()->create_user();
$user->suspended = 1;
Copy link
Member

Choose a reason for hiding this comment

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

you need to save this state to DB.

$this->create_user_private_key();
$_POST['key'] = 'TestKey';

$this->expectException(invalid_parameter_exception::class);
Copy link
Member

Choose a reason for hiding this comment

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

before checking this, can you please check that login failed event has been triggered?

@@ -172,6 +172,15 @@ public function user_login_userkey() {
$this->userkeymanager->delete_keys($key->userid);

$user = get_complete_user_data('id', $key->userid);
if (!empty($user->suspended)) {
$failurereason = AUTH_LOGIN_SUSPENDED;
Copy link
Member

Choose a reason for hiding this comment

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

do you really need this variable? Could be passed as is to the code below.

$event = \core\event\user_login_failed::create(array('userid' => $user->id,
'other' => array('username' => $user->username, 'reason' => $failurereason)));
$event->trigger();
throw new invalid_parameter_exception('User suspended');
Copy link
Member

@dmitriim dmitriim Aug 2, 2023

Choose a reason for hiding this comment

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

If this error will be displayed to a user, can we please replace this with moodle_exception + add a lang string so it could be localised.

@dmitriim
Copy link
Member

dmitriim commented Aug 2, 2023

Thanks @IJOL
The patch looks almost ready. Few things to polish it up and we can merge. Great job!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants