mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/LoginNotify
synced 2024-11-11 16:49:30 +00:00
Update LoginNotify for AuthManager.
I left the old hook in place for back-compatibility Bug: T135270 Change-Id: I5800c7de902718958cd4a8edb33cbffd93dd827d
This commit is contained in:
parent
21432dd25f
commit
143d7caa44
|
@ -6,6 +6,8 @@
|
|||
* @ingroup Extensions
|
||||
*/
|
||||
|
||||
use MediaWiki\Auth\AuthenticationResponse;
|
||||
|
||||
class LoginNotifyHooks {
|
||||
|
||||
const OPTIONS_FAKE_TRUTH = 2;
|
||||
|
@ -79,7 +81,7 @@ class LoginNotifyHooks {
|
|||
}
|
||||
|
||||
/**
|
||||
* Hook to check login result
|
||||
* Old hook for pre 1.27 or wikis with auth manager disabled.
|
||||
*
|
||||
* @todo Doesn't catcha captcha or throttle failures
|
||||
* @param $user User User in question
|
||||
|
@ -91,16 +93,54 @@ class LoginNotifyHooks {
|
|||
if ( !class_exists( 'EchoEvent' ) ) {
|
||||
throw new FatalError( "LoginNotify extension requires the Echo extension to be installed" );
|
||||
}
|
||||
$loginNotify = new LoginNotify();
|
||||
|
||||
if ( $retval === LoginForm::WRONG_PASS ) {
|
||||
$loginNotify->recordFailure( $user );
|
||||
self::doFailedLogin( $user );
|
||||
} elseif ( $retval === LoginForm::SUCCESS ) {
|
||||
$loginNotify->clearCounters( $user );
|
||||
$loginNotify->sendSuccessNotice( $user );
|
||||
$loginNotify->setCurrentAddressAsKnown( $user );
|
||||
self::doSuccessfulLogin( $user );
|
||||
}
|
||||
// We ignore things like RESET_PASS for now
|
||||
}
|
||||
|
||||
/**
|
||||
* Hook for login auditing post 1.27
|
||||
*
|
||||
* @param $ret AuthenticationResponse Is login succesful?
|
||||
* @param $user User|null User object on successful auth
|
||||
* @param $username String Username for failed attempts.
|
||||
*/
|
||||
public static function onAuthManagerLoginAuthenticateAudit(
|
||||
AuthenticationResponse $ret, $user, $username
|
||||
) {
|
||||
if ( !class_exists( 'EchoEvent' ) ) {
|
||||
throw new FatalError( "LoginNotify extension requires the Echo extension to be installed" );
|
||||
}
|
||||
if ( $user ) {
|
||||
$userObj = $user;
|
||||
} else {
|
||||
$userObj = User::newFromName( $username, 'usable' );
|
||||
}
|
||||
if ( !$userObj ) {
|
||||
return;
|
||||
}
|
||||
|
||||
if ( $ret->status === AuthenticationResponse::PASS ) {
|
||||
self::doSuccessfulLogin( $userObj );
|
||||
} elseif ( $ret->status === AuthenticationResponse::FAIL ) {
|
||||
self::doFailedLogin( $userObj );
|
||||
}
|
||||
// Other statuses include Abstain, Redirect, or UI. We ignore such
|
||||
// statuses.
|
||||
}
|
||||
|
||||
public static function doSuccessfulLogin( User $user ) {
|
||||
$loginNotify = new LoginNotify();
|
||||
$loginNotify->clearCounters( $user );
|
||||
$loginNotify->sendSuccessNotice( $user );
|
||||
$loginNotify->setCurrentAddressAsKnown( $user );
|
||||
}
|
||||
|
||||
public static function doFailedLogin( User $user ) {
|
||||
$loginNotify = new LoginNotify();
|
||||
$loginNotify->recordFailure( $user );
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -32,6 +32,9 @@
|
|||
"LoginAuthenticateAudit": [
|
||||
"LoginNotifyHooks::onLoginAuthenticateAudit"
|
||||
],
|
||||
"AuthManagerLoginAuthenticateAudit": [
|
||||
"LoginNotifyHooks::onAuthManagerLoginAuthenticateAudit"
|
||||
],
|
||||
"AddNewAccount": [
|
||||
"LoginNotifyHooks::onAddNewAccount"
|
||||
],
|
||||
|
|
Loading…
Reference in a new issue