public function loginFrontEndUser($userId)
    {
        if ((int)$userId === 0) {
            throw new \InvalidArgumentException('The user ID must be > 0.', 1334439475);
        }
        if (!$this->hasFakeFrontEnd()) {
            throw new Exception('Please create a front end before calling loginFrontEndUser.', 1334439483);
        }

        if ($this->isLoggedIn()) {
            $this->logoutFrontEndUser();
        }

        $this->suppressFrontEndCookies();

        // With current TYPO3 versions we have to ensure an user id
        $tempUser = [
            $GLOBALS['TSFE']->fe_user->userid_column => $userId,
        ];
        $GLOBALS['TSFE']->fe_user->createUserSession($tempUser);
        $GLOBALS['TSFE']->fe_user->user = $GLOBALS['TSFE']->fe_user->getRawUserByUid($userId);
        $GLOBALS['TSFE']->fe_user->fetchGroupData();
        $GLOBALS['TSFE']->loginUser = 1;
    }
public function loginFrontEndUser($userId)
    {
        if ((int)$userId === 0) {
            throw new \InvalidArgumentException('The user ID must be > 0.', 1334439475);
        }
        if (!$this->hasFakeFrontEnd()) {
            throw new Exception('Please create a front end before calling loginFrontEndUser.', 1334439483);
        }

        if ($this->isLoggedIn()) {
            $this->logoutFrontEndUser();
        }

        $this->suppressFrontEndCookies();

        // With current TYPO3 versions we have to ensure an user id
        $tempUser = [
            $GLOBALS['TSFE']->fe_user->userid_column => $userId,
        ];
        $GLOBALS['TSFE']->fe_user->createUserSession($tempUser);
        $GLOBALS['TSFE']->fe_user->user = $GLOBALS['TSFE']->fe_user->getRawUserByUid($userId);
        $GLOBALS['TSFE']->fe_user->fetchGroupData();
        $GLOBALS['TSFE']->loginUser = 1;
    }
public function loginFrontEndUser ( $ userId ) { if ( ( int ) $ userId === 0 ) { throw new \ InvalidArgumentException ( 'The user ID must be > 0.' , 1334439475 ) ; } if ( ! $ this -> hasFakeFrontEnd ( ) ) { throw new Exception ( 'Please create a front end before calling loginFrontEndUser.' , 1334439483 ) ; } if ( $ this -> isLoggedIn ( ) ) { $ this -> logoutFrontEndUser ( ) ; } $ this -> suppressFrontEndCookies ( ) ; // With current TYPO3 versions we have to ensure an user id $ tempUser = [ $ GLOBALS [ 'TSFE' ] -> fe_user -> userid_column => $ userId , ] ; $ GLOBALS [ 'TSFE' ] -> fe_user -> createUserSession ( $ tempUser ) ; $ GLOBALS [ 'TSFE' ] -> fe_user -> user = $ GLOBALS [ 'TSFE' ] -> fe_user -> getRawUserByUid ( $ userId ) ; $ GLOBALS [ 'TSFE' ] -> fe_user -> fetchGroupData ( ) ; $ GLOBALS [ 'TSFE' ] -> loginUser = 1 ; }
Fakes that a front-end user has logged in.

If a front-end user currently is logged in, he/she will be logged out
first.

Note: To set the logged-in users group data properly, the front-end user
and his groups must actually exist in the database.

@param int $userId
UID of the FE user, must not necessarily exist in the database,
must be > 0

@return void

@throws Exception if no front end has been created
@throws \InvalidArgumentException
Fakes that a front - end user has logged in .