FeUserService

class

namespace Infochy\InfochyFeuserexample\Domain\Service;

use TYPO3\CMS\Extbase\DomainObject\DomainObjectInterface;

class FeUserService implements \TYPO3\CMS\Core\SingletonInterface {

  /**
   * @var \TYPO3\CMS\Extbase\Domain\Repository\FrontendUserRepository
   * @inject
   */
  protected $frontendUserRepository;

  /**
   * @return boolean
   */
  public function isUserActive() {
    return $this->getFrontendController()->loginUser;
  }

  /**
   * @return FrontendUser
   */
  public function getFrontendUser() {
    return $this->frontendUserRepository->findByIdentifier($this->getFrontendController()->fe_user->user['uid']);
  }

  /**
   * @param DomainObjectInterface $user
   * @return void
   */
  public function setFeUserActiv(DomainObjectInterface $user) {
    $frontendController = $this->getFrontendController();
    $frontendController->fe_user->createUserSession($user->_getCleanProperties());
    $frontendController->fe_user->loginSessionStarted = TRUE;
    $frontendController->fe_user->user = $frontendController->fe_user->fetchUserSession();
    $frontendController->loginUser = TRUE;
  }

  /**
   * @return \TYPO3\CMS\Frontend\Controller\TypoScriptFrontendController
   */
  protected function getFrontendController() {
    return $GLOBALS['TSFE'];
  }
}

inject

    /**
     * @var \Infochy\InfochyFeuserexample\Domain\Service\FeUserService
     * @inject
     */
    protected $feUserService;