Track key authentication metrics
[lhc/web/wiklou.git] / includes / specials / SpecialUserlogin.php
index 8259718..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() );
@@ -453,8 +463,7 @@ class LoginForm extends SpecialPage {
         * @return Status
         */
        public function addNewAccountInternal() {
-               global $wgAuth, $wgMemc, $wgAccountCreationThrottle,
-                       $wgMinimalPasswordLength, $wgEmailConfirmToEdit;
+               global $wgAuth, $wgMemc, $wgAccountCreationThrottle, $wgEmailConfirmToEdit;
 
                // If the user passes an invalid domain, something is fishy
                if ( !$wgAuth->validDomain( $this->mDomain ) ) {
@@ -530,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' );
                }
 
@@ -546,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;
@@ -912,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();
@@ -949,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' )
                                                );
@@ -1032,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,
+               ) );
        }
 
        /**
@@ -1283,8 +1302,9 @@ class LoginForm extends SpecialPage {
        function mainLoginForm( $msg, $msgtype = 'error' ) {
                global $wgEnableEmail, $wgEnableUserEmail;
                global $wgHiddenPrefs, $wgLoginLanguageSelector;
-               global $wgAuth, $wgEmailConfirmToEdit, $wgCookieExpiration;
+               global $wgAuth, $wgEmailConfirmToEdit;
                global $wgSecureLogin, $wgPasswordResetRoutes;
+               global $wgExtendedLoginCookieExpiration, $wgCookieExpiration;
 
                $titleObj = $this->getPageTitle();
                $user = $this->getUser();
@@ -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 );
@@ -1407,7 +1428,7 @@ class LoginForm extends SpecialPage {
                $template->set( 'emailothers', $wgEnableUserEmail );
                $template->set( 'canreset', $wgAuth->allowPasswordChange() );
                $template->set( 'resetlink', $resetLink );
-               $template->set( 'canremember', ( $wgCookieExpiration > 0 ) );
+               $template->set( 'canremember', $wgExtendedLoginCookieExpiration === null ? ( $wgCookieExpiration > 0 ) : ( $wgExtendedLoginCookieExpiration > 0 ) );
                $template->set( 'usereason', $user->isLoggedIn() );
                $template->set( 'remember', $this->mRemember );
                $template->set( 'cansecurelogin', ( $wgSecureLogin === true ) );