From 8f934f369d6d7ae5026a0728a989e0c6c459c097 Mon Sep 17 00:00:00 2001 From: Vladik Date: Fri, 25 Oct 2024 12:03:36 +0300 Subject: [PATCH] task: updated active contact after authentication - version beta for task --- .../controller/rest/AuthenticationController.java | 4 ++-- .../yourway/service/ActivateAccountService.java | 14 +++----------- .../yourway/service/AuthenticationService.java | 4 ++-- 3 files changed, 7 insertions(+), 15 deletions(-) diff --git a/src/main/java/com/chat/yourway/controller/rest/AuthenticationController.java b/src/main/java/com/chat/yourway/controller/rest/AuthenticationController.java index d6e5cc7..65fe137 100644 --- a/src/main/java/com/chat/yourway/controller/rest/AuthenticationController.java +++ b/src/main/java/com/chat/yourway/controller/rest/AuthenticationController.java @@ -88,8 +88,8 @@ public AuthResponseDto refreshToken(HttpServletRequest request) { content = @Content(schema = @Schema(implementation = ApiErrorResponseDto.class))) }) @PostMapping(path = ACTIVATE, consumes = APPLICATION_JSON_VALUE) - public void activateAccount(@RequestParam(name = "Email token") UUID token) { - authService.activateAccount(token); + public void activateAccount() { + authService.activateAccount(); } @Operation(summary = "Resend email", responses = { diff --git a/src/main/java/com/chat/yourway/service/ActivateAccountService.java b/src/main/java/com/chat/yourway/service/ActivateAccountService.java index b881b05..4dca734 100644 --- a/src/main/java/com/chat/yourway/service/ActivateAccountService.java +++ b/src/main/java/com/chat/yourway/service/ActivateAccountService.java @@ -25,21 +25,13 @@ public class ActivateAccountService { private final ContactService contactService; @Transactional - public void activateAccount(UUID token) { - log.trace("Started activateAccount by email token"); + public void activateAccount() { + log.trace("Started activateAccount by email"); - EmailToken emailToken = emailTokenRepository.findById(token) - .orElseThrow(() -> { - log.warn("Current email token does not exist in repository"); - return new EmailTokenNotFoundException(); - }); - - Contact contact = emailToken.getContact(); + final var contact = contactService.getCurrentContact(); contact.setActive(true); contactService.save(contact); - emailTokenRepository.delete(emailToken); - log.info("Account is activate for contact email [{}]", contact.getEmail()); } diff --git a/src/main/java/com/chat/yourway/service/AuthenticationService.java b/src/main/java/com/chat/yourway/service/AuthenticationService.java index 15e1e0c..a339f89 100644 --- a/src/main/java/com/chat/yourway/service/AuthenticationService.java +++ b/src/main/java/com/chat/yourway/service/AuthenticationService.java @@ -93,8 +93,8 @@ public AuthResponseDto refreshToken(HttpServletRequest request) { return AuthResponseDto.builder().accessToken(accessToken).refreshToken(refreshToken).build(); } - public void activateAccount(UUID token) { - activateAccountService.activateAccount(token); + public void activateAccount() { + activateAccountService.activateAccount(); } public void logout(HttpServletRequest request, HttpServletResponse response, Authentication auth) {