. */ namespace SP\Modules\Web\Controllers\UserPassReset; use Exception; use SP\Core\Events\Event; use SP\Core\Events\EventMessage; use SP\Core\Exceptions\ValidationException; use SP\Http\JsonResponse; use SP\Modules\Web\Controllers\Traits\JsonTrait; /** * Class SaveResetController */ final class SaveResetController extends UserPassResetSaveBase { use JsonTrait; /** * @return bool * @throws \JsonException */ public function saveResetAction(): bool { try { $this->checkTracking(); $pass = $this->request->analyzeEncrypted('password'); $passR = $this->request->analyzeEncrypted('password_repeat'); if (!$pass || !$passR) { throw new ValidationException(__u('Password cannot be blank')); } if ($pass !== $passR) { throw new ValidationException(__u('Passwords do not match')); } $hash = $this->request->analyzeString('hash'); $userId = $this->userPassRecoverService->getUserIdForHash($hash); $this->userPassRecoverService->toggleUsedByHash($hash); $this->userService->updatePass($userId, $pass); $user = $this->userService->getById($userId); $this->eventDispatcher->notify( 'edit.user.password', new Event( $this, EventMessage::factory() ->addDescription(__u('Password updated')) ->addDetail(__u('User'), $user->getLogin()) ->addExtra('userId', $userId) ->addExtra('email', $user->getEmail()) ) ); return $this->returnJsonResponse(JsonResponse::JSON_SUCCESS, __u('Password updated')); } catch (Exception $e) { processException($e); $this->addTracking(); $this->eventDispatcher->notify('exception', new Event($e)); return $this->returnJsonResponseException($e); } } }