. */ namespace SP\Modules\Web\Controllers\UserPassReset; use Exception; use SP\Core\Application; use SP\Core\Exceptions\SPException; use SP\Domain\Notification\Ports\MailServiceInterface; use SP\Domain\Security\Ports\TrackServiceInterface; use SP\Domain\User\Ports\UserPassRecoverServiceInterface; use SP\Domain\User\Ports\UserServiceInterface; use SP\Infrastructure\Security\Repositories\TrackRequest; use SP\Modules\Web\Controllers\ControllerBase; use SP\Mvc\Controller\WebControllerHelper; /** * Class UserPassResetSaveBase */ abstract class UserPassResetSaveBase extends ControllerBase { protected UserPassRecoverServiceInterface $userPassRecoverService; protected UserServiceInterface $userService; protected MailServiceInterface $mailService; private TrackServiceInterface $trackService; private TrackRequest $trackRequest; /** * @throws \SP\Core\Exceptions\SessionTimeout * @throws \SP\Core\Exceptions\InvalidArgumentException * @throws \JsonException */ public function __construct( Application $application, WebControllerHelper $webControllerHelper, UserPassRecoverServiceInterface $userPassRecoverService, UserServiceInterface $userService, MailServiceInterface $mailService, TrackServiceInterface $trackService ) { parent::__construct($application, $webControllerHelper); $this->userPassRecoverService = $userPassRecoverService; $this->userService = $userService; $this->mailService = $mailService; $this->trackService = $trackService; $this->trackRequest = $this->trackService->getTrackRequest($this->getViewBaseName()); } /** * @throws SPException * @throws Exception */ final protected function checkTracking(): void { if ($this->trackService->checkTracking($this->trackRequest)) { throw new SPException(__u('Attempts exceeded'), SPException::INFO); } } /** * Añadir un seguimiento */ final protected function addTracking(): void { try { $this->trackService->add($this->trackRequest); } catch (Exception $e) { processException($e); } } }