Add AuthManager
[lhc/web/wiklou.git] / includes / specials / SpecialUserlogin.php
index 9901d36..11182d4 100644 (file)
@@ -690,7 +690,12 @@ class LoginForm extends SpecialPage {
 
                $status = $u->addToDatabase();
                if ( !$status->isOK() ) {
-                       return $status;
+                       if ( $status->hasMessage( 'userexists' ) ) {
+                               // AuthManager probably just added the user.
+                               $u->saveSettings();
+                       } else {
+                               return $status;
+                       }
                }
 
                if ( $wgAuth->allowPasswordChange() ) {
@@ -699,13 +704,15 @@ class LoginForm extends SpecialPage {
 
                $u->setEmail( $this->mEmail );
                $u->setRealName( $this->mRealName );
-               $u->setToken();
+               SessionManager::singleton()->invalidateSessionsForUser( $u );
 
                Hooks::run( 'LocalUserCreated', [ $u, $autocreate ] );
-               $oldUser = $u;
-               $wgAuth->initUser( $u, $autocreate );
-               if ( $oldUser !== $u ) {
-                       wfWarn( get_class( $wgAuth ) . '::initUser() replaced the user object' );
+               if ( $wgAuth && !$wgAuth instanceof MediaWiki\Auth\AuthManagerAuthPlugin ) {
+                       $oldUser = $u;
+                       $wgAuth->initUser( $u, $autocreate );
+                       if ( $oldUser !== $u ) {
+                               wfWarn( get_class( $wgAuth ) . '::initUser() replaced the user object' );
+                       }
                }
 
                $u->saveSettings();
@@ -857,10 +864,12 @@ class LoginForm extends SpecialPage {
                        $this->mAbortLoginErrorMsg = 'resetpass-expired';
                } else {
                        Hooks::run( 'UserLoggedIn', [ $u ] );
-                       $oldUser = $u;
-                       $wgAuth->updateUser( $u );
-                       if ( $oldUser !== $u ) {
-                               wfWarn( get_class( $wgAuth ) . '::updateUser() replaced the user object' );
+                       if ( $wgAuth && !$wgAuth instanceof MediaWiki\Auth\AuthManagerAuthPlugin ) {
+                               $oldUser = $u;
+                               $wgAuth->updateUser( $u );
+                               if ( $oldUser !== $u ) {
+                                       wfWarn( get_class( $wgAuth ) . '::updateUser() replaced the user object' );
+                               }
                        }
                        $wgUser = $u;
                        // This should set it for OutputPage and the Skin
@@ -1059,7 +1068,6 @@ class LoginForm extends SpecialPage {
        function processLogin() {
                global $wgLang, $wgSecureLogin, $wgInvalidPasswordReset;
 
-               $cache = ObjectCache::getLocalClusterInstance();
                $authRes = $this->authenticateUserData();
                switch ( $authRes ) {
                        case self::SUCCESS:
@@ -1818,8 +1826,7 @@ class LoginForm extends SpecialPage {
        }
 
        /**
-        * Private function to check password expiration, until AuthManager comes
-        * along to handle that.
+        * Private function to check password expiration, until this is rewritten for AuthManager.
         * @param User $user
         * @return string|bool
         */