From d7477b6ecc01e4a07868de07acb8a860a1eb4661 Mon Sep 17 00:00:00 2001 From: privrja Date: Tue, 27 Apr 2021 21:49:17 +0200 Subject: [PATCH] Refactoring --- src/Controller/SecurityController.php | 11 ++++++++--- src/CycloBranch/BlockMergeFormulaCycloBranch.php | 2 +- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/src/Controller/SecurityController.php b/src/Controller/SecurityController.php index 6486316..b8f2671 100644 --- a/src/Controller/SecurityController.php +++ b/src/Controller/SecurityController.php @@ -28,6 +28,7 @@ use App\Structure\ResetStructure; use App\Structure\ResetTransformed; use DateTime; +use Doctrine\DBAL\Exception\UniqueConstraintViolationException; use Doctrine\ORM\EntityManagerInterface; use Exception; use Psr\Log\LoggerInterface; @@ -317,8 +318,12 @@ public function changeMail(Request $request, EntityManagerInterface $entityManag /** @var User $user */ $user = $security->getUser(); $user->setMail($trans->mail); - $entityManager->persist($user); - $entityManager->flush(); + try { + $entityManager->persist($user); + $entityManager->flush(); + } catch (UniqueConstraintViolationException $ex) { + return ResponseHelper::jsonResponse(new Message('Mail is taken')); + } return ResponseHelper::jsonResponse(Message::createNoContent()); } @@ -573,7 +578,7 @@ public function generatePassword(Request $request, EntityManagerInterface $entit return ResponseHelper::jsonResponse(new Message(ErrorConstants::ERROR_SOMETHING_GO_WRONG, Response::HTTP_INTERNAL_SERVER_ERROR)); } try { - mail($user->getMail(), 'MassSpecBlocks - password reset', 'You request a new password for Mass Spec Blocks. New generated password: ' . $pass . '. After first login with new password we recommended you to change it. Thanks'); + mail($user->getMail(), 'MassSpecBlocks - password reset', 'You requested a new password for MassSpecBlocks. The new password is: ' . $pass . '. After the first login with the new password, we recommend you change it. Thanks'); } catch (Exception $exception) { return ResponseHelper::jsonResponse(new Message('Server doesn\'t support sending mails')); } diff --git a/src/CycloBranch/BlockMergeFormulaCycloBranch.php b/src/CycloBranch/BlockMergeFormulaCycloBranch.php index 36105d9..08a314f 100644 --- a/src/CycloBranch/BlockMergeFormulaCycloBranch.php +++ b/src/CycloBranch/BlockMergeFormulaCycloBranch.php @@ -14,7 +14,7 @@ public function download(): string { if (!empty($arResult)) { foreach ($arResult as $block) { $this->data .= str_replace(',', '.', $block['block_name']) . self::TABULATOR - . $block['acronym'] . self::TABULATOR + . str_replace(',', '.', $block['acronym']) . self::TABULATOR . $block['residue'] . self::TABULATOR . $block['block_mass'] . self::TABULATOR . $block['losses'] . self::TABULATOR