<?php
/**
 * @copyright (c) Kufer Software GmbH, Oderstraße 7, D-84453 Mühldorf
 */

namespace Kufer\Web\KuferTools\Oeffentlich\DoLogin;

class DoLoginController extends \Kufer\Web\KuferTools\Basis\Controller\Controller
{
  protected function getUseCase(): \Kufer\Web\KuferTools\Basis\UseCase\UseCase
  {
    return new DoLoginUseCase(
      $this->getRequestObj(),
      new \SecurityOperations()
    );
  }

  protected function getRequestObj()
  {
    $request = new DoLoginRequest();
    if (PRAESENTATION) {
      $request->username = \FilterBasis::filterPasswort(\RequestOperations::getVarValue('username'));
      $request->password = \FilterBasis::filterPasswort(\RequestOperations::getVarValue('password'));
    } else {
      $request->username = \FilterBasis::filterPasswort(\PostOperations::getVarValue('username'));
      $request->password = \FilterBasis::filterPasswort(\PostOperations::getVarValue('password'));
    }
    $action = $this->getActionVal();

    $request = $this->handleXsrf($request, $action);

    
    
    if (\DBWorkBASysSettings::isKoelnAksAkademieSteuern()) {
      $request->isXsrfOk = true;
    }

    $forward_to_tool = \GetOperations::getVarValue('forward_to_tool');
    if ($forward_to_tool !== '' && \CleanOperations::isInt($forward_to_tool)) {
      $request->forward_to_tool = (int)$forward_to_tool;
      $request->forward_to_id = \GetOperations::getVarValue('forward_to_id');
    }

    return $request;
  }

  protected function getPresenter($pUseCaseResponse)
  {
    return new StartseiteVonDoLoginPresenter($pUseCaseResponse);
  }

  protected function getControllerToForward($pUseCaseResponse)
  {
    if ($pUseCaseResponse->loginSuccess) {
      return \Kufer\Web\KuferTools\Utils\Oeffentlich\OeffentlichUtils::getAfterLoginController(null, $pUseCaseResponse);

    
    
    
    } else {
      return null;
    }
  }
}