From 956b47c7cd67c773aff848a8e09e4fa39e5d3575 Mon Sep 17 00:00:00 2001 From: Nho Quy Dinh Date: Fri, 21 Jun 2024 19:39:24 +0200 Subject: [PATCH] Refactoring --- .../java/com/nonononoki/alovoa/repo/UserRepository.java | 2 +- .../java/com/nonononoki/alovoa/rest/Oauth2Controller.java | 4 +--- .../com/nonononoki/alovoa/service/RegisterService.java | 8 +++----- .../com/nonononoki/alovoa/service/ScheduleService.java | 2 +- 4 files changed, 6 insertions(+), 10 deletions(-) diff --git a/src/main/java/com/nonononoki/alovoa/repo/UserRepository.java b/src/main/java/com/nonononoki/alovoa/repo/UserRepository.java index 3c599ed0..38274a77 100644 --- a/src/main/java/com/nonononoki/alovoa/repo/UserRepository.java +++ b/src/main/java/com/nonononoki/alovoa/repo/UserRepository.java @@ -29,7 +29,7 @@ default List usersSearch(UserSearchRequest request, Pageable page) { request.getLikeIds(), request.getHideIds(), request.getBlockIds(), request.getGenderIds(), page); } - List findByConfirmedIsFalseAndDatesCreationDateBefore(Date date); + List findByConfirmedIsFalseAndAdminFalseAndDatesCreationDateBefore(Date date); @Query(value = "SELECT u FROM User u WHERE u.disabled = FALSE AND u.admin = FALSE AND u.confirmed = TRUE AND u.intention IS NOT NULL AND " + "u.locationLatitude IS NOT NULL AND u.locationLongitude IS NOT NULL AND u.profilePicture IS NOT NULL " diff --git a/src/main/java/com/nonononoki/alovoa/rest/Oauth2Controller.java b/src/main/java/com/nonononoki/alovoa/rest/Oauth2Controller.java index e2d03247..999e0901 100644 --- a/src/main/java/com/nonononoki/alovoa/rest/Oauth2Controller.java +++ b/src/main/java/com/nonononoki/alovoa/rest/Oauth2Controller.java @@ -101,9 +101,7 @@ public ModelAndView oauth2Facebook(@PathVariable String redirectUrlEncoded) { @SuppressWarnings("rawtypes") @GetMapping("/login/oauth2/success") - public ModelAndView oauth2Success() - throws InvalidKeyException, IllegalBlockSizeException, BadPaddingException, NoSuchAlgorithmException, - NoSuchPaddingException, InvalidAlgorithmParameterException, UnsupportedEncodingException, AlovoaException { + public ModelAndView oauth2Success() { Authentication authentication = SecurityContextHolder.getContext().getAuthentication(); try { diff --git a/src/main/java/com/nonononoki/alovoa/service/RegisterService.java b/src/main/java/com/nonononoki/alovoa/service/RegisterService.java index 58c0eee1..b4ee2342 100644 --- a/src/main/java/com/nonononoki/alovoa/service/RegisterService.java +++ b/src/main/java/com/nonononoki/alovoa/service/RegisterService.java @@ -152,8 +152,7 @@ public String register(RegisterDto dto) } public void registerOauth(RegisterDto dto) throws MessagingException, IOException, AlovoaException, - NumberFormatException, InvalidKeyException, IllegalBlockSizeException, BadPaddingException, - NoSuchAlgorithmException, NoSuchPaddingException, InvalidAlgorithmParameterException { + NumberFormatException { String email = Tools.cleanEmail(authService.getOauth2Email()); if (email == null) { @@ -210,8 +209,7 @@ public UserRegisterToken generateToken(User user) { } public User registerConfirm(String tokenString) throws MessagingException, IOException, AlovoaException, - NumberFormatException, InvalidKeyException, IllegalBlockSizeException, BadPaddingException, - NoSuchAlgorithmException, NoSuchPaddingException, InvalidAlgorithmParameterException { + NumberFormatException { UserRegisterToken token = registerTokenRepo.findByContent(tokenString); if (token == null) { @@ -225,7 +223,7 @@ public User registerConfirm(String tokenString) throws MessagingException, IOExc } if (user.isConfirmed()) { - throw new AlovoaException("user_not_confirmed"); + throw new AlovoaException("user_already_confirmed"); } try { diff --git a/src/main/java/com/nonononoki/alovoa/service/ScheduleService.java b/src/main/java/com/nonononoki/alovoa/service/ScheduleService.java index ef8c799f..0001a6e2 100644 --- a/src/main/java/com/nonononoki/alovoa/service/ScheduleService.java +++ b/src/main/java/com/nonononoki/alovoa/service/ScheduleService.java @@ -75,7 +75,7 @@ public void cleanNonConfirmedUsers(final Date date) { ms -= nonConfirmedUsersCleanupDelay; Date d = new Date(ms); - List users = userRepo.findByConfirmedIsFalseAndDatesCreationDateBefore(d); + List users = userRepo.findByConfirmedIsFalseAndAdminFalseAndDatesCreationDateBefore(d); userRepo.deleteAll(users); userRepo.flush();