Track key authentication metrics
[lhc/web/wiklou.git] / includes / specials / SpecialUserlogin.php
index 472fdb7..f446a98 100644 (file)
@@ -20,6 +20,7 @@
  * @file
  * @ingroup SpecialPage
  */
+use MediaWiki\Logger\LoggerFactory;
 
 /**
  * Implements Special:UserLogin
@@ -338,6 +339,10 @@ class LoginForm extends SpecialPage {
                }
 
                $status = $this->addNewAccountInternal();
+               LoggerFactory::getInstance( 'authmanager' )->info( 'Account creation attempt with mailed password', array(
+                       'event' => 'accountcreation',
+                       'status' => $status,
+               ) );
                if ( !$status->isGood() ) {
                        $error = $status->getMessage();
                        $this->mainLoginForm( $error->toString() );
@@ -375,6 +380,11 @@ class LoginForm extends SpecialPage {
 
                # Create the account and abort if there's a problem doing so
                $status = $this->addNewAccountInternal();
+               LoggerFactory::getInstance( 'authmanager' )->info( 'Account creation attempt', array(
+                       'event' => 'accountcreation',
+                       'status' => $status,
+               ) );
+
                if ( !$status->isGood() ) {
                        $error = $status->getMessage();
                        $this->mainLoginForm( $error->toString() );
@@ -529,9 +539,9 @@ class LoginForm extends SpecialPage {
 
                # Now create a dummy user ($u) and check if it is valid
                $u = User::newFromName( $this->mUsername, 'creatable' );
-               if ( !is_object( $u ) ) {
+               if ( !$u ) {
                        return Status::newFatal( 'noname' );
-               } elseif ( 0 != $u->idForName() ) {
+               } elseif ( 0 != $u->idForName( User::READ_LOCKING ) ) {
                        return Status::newFatal( 'userexists' );
                }
 
@@ -545,7 +555,7 @@ class LoginForm extends SpecialPage {
                        }
 
                        # check for password validity, return a fatal Status if invalid
-                       $validity = $u->checkPasswordValidity( $this->mPassword );
+                       $validity = $u->checkPasswordValidity( $this->mPassword, 'create' );
                        if ( !$validity->isGood() ) {
                                $validity->ok = false; // make sure this Status is fatal
                                return $validity;
@@ -911,7 +921,8 @@ class LoginForm extends SpecialPage {
                global $wgMemc, $wgLang, $wgSecureLogin, $wgPasswordAttemptThrottle,
                        $wgInvalidPasswordReset;
 
-               switch ( $this->authenticateUserData() ) {
+               $status = $this->authenticateUserData();
+               switch ( $status ) {
                        case self::SUCCESS:
                                # We've verified now, update the real record
                                $user = $this->getUser();
@@ -948,7 +959,10 @@ class LoginForm extends SpecialPage {
                                        } elseif ( $wgInvalidPasswordReset
                                                && !$user->isValidPassword( $this->mPassword )
                                        ) {
-                                               $status = $user->checkPasswordValidity( $this->mPassword );
+                                               $status = $user->checkPasswordValidity(
+                                                       $this->mPassword,
+                                                       'login'
+                                               );
                                                $this->resetLoginForm(
                                                        $status->getMessage( 'resetpass-validity-soft' )
                                                );
@@ -1031,6 +1045,12 @@ class LoginForm extends SpecialPage {
                        default:
                                throw new MWException( 'Unhandled case value' );
                }
+
+               LoggerFactory::getInstance( 'authmanager' )->info( 'Login attempt', array(
+                       'event' => 'login',
+                       'successful' => $status === self::SUCCESS,
+                       'status' => $status,
+               ) );
        }
 
        /**
@@ -1387,6 +1407,7 @@ class LoginForm extends SpecialPage {
                        : is_array( $wgPasswordResetRoutes ) && in_array( true, array_values( $wgPasswordResetRoutes ) );
 
                $template->set( 'header', '' );
+               $template->set( 'formheader', '' );
                $template->set( 'skin', $this->getSkin() );
                $template->set( 'name', $this->mUsername );
                $template->set( 'password', $this->mPassword );