Tweak audit hooks
authorBrion Vibber <brion@users.mediawiki.org>
Tue, 8 May 2007 18:31:32 +0000 (18:31 +0000)
committerBrion Vibber <brion@users.mediawiki.org>
Tue, 8 May 2007 18:31:32 +0000 (18:31 +0000)
docs/hooks.txt
includes/SpecialPreferences.php
includes/SpecialUserlogin.php

index 6f66b06..62e4c46 100644 (file)
@@ -409,10 +409,11 @@ after noinclude/includeonly/onlyinclude and other processing.
 &$text: string containing partially parsed text
 &$this->mStripState: Parser's internal StripState object
 
-'LoginBadPass': a login attempt has failed with an invalid password.
-                No return data is accepted; this hook is for auditing only.
+'LoginAuthenticateAudit': a login attempt for a valid user account either succeeded or failed.
+                          No return data is accepted; this hook is for auditing only.
 $user: the User object being authenticated against
 $password: the password being submitted and found wanting
+$retval: a LoginForm class constant with authenticateUserData() return value (SUCCESS, WRONG_PASS, etc)
 
 'LogPageValidTypes': action being logged. DEPRECATED: Use $wgLogTypes
 &$type: array of strings
index 660ede9..05605d3 100644 (file)
@@ -211,19 +211,23 @@ class PreferencesForm {
 
                if ( '' != $this->mNewpass && $wgAuth->allowPasswordChange() ) {
                        if ( $this->mNewpass != $this->mRetypePass ) {
+                               wfRunHooks( "PrefsPasswordAudit", array( $wgUser, $this->mNewpass, 'badretype' ) );
                                $this->mainPrefsForm( 'error', wfMsg( 'badretype' ) );
                                return;
                        }
 
                        if (!$wgUser->checkPassword( $this->mOldpass )) {
+                               wfRunHooks( "PrefsPasswordAudit", array( $wgUser, $this->mNewpass, 'wrongpassword' ) );
                                $this->mainPrefsForm( 'error', wfMsg( 'wrongpassword' ) );
                                return;
                        }
                        
                        try {
                                $wgUser->setPassword( $this->mNewpass );
+                               wfRunHooks( "PrefsPasswordAudit", array( $wgUser, $this->mNewpass, 'success' ) );
                                $this->mNewpass = $this->mOldpass = $this->mRetypePass = '';
                        } catch( PasswordError $e ) {
+                               wfRunHooks( "PrefsPasswordAudit", array( $wgUser, $this->mNewpass, 'error' ) );
                                $this->mainPrefsForm( 'error', $e->getMessage() );
                                return;
                        }
@@ -321,6 +325,9 @@ class PreferencesForm {
                                $wgUser->setCookies();
                                $wgUser->saveSettings();
                        }
+                       if( $oldadr != $newadr ) {
+                               wfRunHooks( "PrefsEmailAudit", array( $wgUser, $oldadr, $newadr ) );
+                       }
                }
 
                if( $needRedirect && $error === false ) {
index 26196b8..3bd7728 100644 (file)
@@ -400,17 +400,18 @@ class LoginForm {
                                // reset form; bot interfaces etc will probably just
                                // fail cleanly here.
                                //
-                               return self::RESET_PASS;
+                               $retval = self::RESET_PASS;
                        } else {
-                               wfRunHooks( 'LoginBadPass', array( $u, $this->mPassword ) );
-                               return '' == $this->mPassword ? self::EMPTY_PASS : self::WRONG_PASS;
+                               $retval = '' == $this->mPassword ? self::EMPTY_PASS : self::WRONG_PASS;
                        }
                } else {
                        $wgAuth->updateUser( $u );
                        $wgUser = $u;
 
-                       return self::SUCCESS;
+                       $retval = self::SUCCESS;
                }
+               wfRunHooks( 'LoginAuthenticateAudit', array( $u, $this->mPassword, $retval ) );
+               return $retval;
        }
 
        function processLogin() {