Update LoginNotify for AuthManager.

I left the old hook in place for back-compatibility

Bug: T135270
Change-Id: I5800c7de902718958cd4a8edb33cbffd93dd827d
This commit is contained in:
Brian Wolff 2016-07-06 18:06:27 -04:00
parent 21432dd25f
commit 143d7caa44
2 changed files with 51 additions and 8 deletions

View file

@ -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 );
}
/**

View file

@ -32,6 +32,9 @@
"LoginAuthenticateAudit": [
"LoginNotifyHooks::onLoginAuthenticateAudit"
],
"AuthManagerLoginAuthenticateAudit": [
"LoginNotifyHooks::onAuthManagerLoginAuthenticateAudit"
],
"AddNewAccount": [
"LoginNotifyHooks::onAddNewAccount"
],