diff --git a/src/main/java/io/hexlet/typoreporter/handler/OAuth2SuccessHandler.java b/src/main/java/io/hexlet/typoreporter/handler/OAuth2SuccessHandler.java index 0d08d856..27819e11 100644 --- a/src/main/java/io/hexlet/typoreporter/handler/OAuth2SuccessHandler.java +++ b/src/main/java/io/hexlet/typoreporter/handler/OAuth2SuccessHandler.java @@ -22,7 +22,8 @@ public void onAuthenticationSuccess(HttpServletRequest request, HttpServletResponse response, Authentication authentication) throws IOException, ServletException { CustomOAuth2User oAuth2User = (CustomOAuth2User) authentication.getPrincipal(); - if (oAuth2User.getEmail() == null) { + if (oAuth2User.getEmail() == null + || (oAuth2User.getFirstName() == null && oAuth2User.getLastName() == null)) { //TODO: добавить ошибку на фронт, если email приватный response.sendRedirect("/login"); } diff --git a/src/main/java/io/hexlet/typoreporter/service/AccountService.java b/src/main/java/io/hexlet/typoreporter/service/AccountService.java index b2884021..97071b98 100644 --- a/src/main/java/io/hexlet/typoreporter/service/AccountService.java +++ b/src/main/java/io/hexlet/typoreporter/service/AccountService.java @@ -141,15 +141,13 @@ public Account updatePassword(final UpdatePassword updatePassword, final String } @Transactional public void processOAuthPostLogin(CustomOAuth2User user) { - //TODO: убрать после тестирования - //accountRepository.deleteAll(); var existUser = accountRepository.existsByEmail(user.getEmail()); if (!existUser) { Account account = new Account(); account.setEmail(user.getEmail()); account.setAuthProvider(AuthProvider.GITHUB); account.setUsername(user.getLogin()); - account.setPassword(user.getPassword()); + account.setPassword(passwordEncoder.encode(user.getPassword())); account.setFirstName(user.getFirstName()); account.setLastName(user.getLastName()); accountRepository.save(account); diff --git a/src/main/java/io/hexlet/typoreporter/service/dto/account/UpdateProfile.java b/src/main/java/io/hexlet/typoreporter/service/dto/account/UpdateProfile.java index 5fa41634..9f16a1fc 100644 --- a/src/main/java/io/hexlet/typoreporter/service/dto/account/UpdateProfile.java +++ b/src/main/java/io/hexlet/typoreporter/service/dto/account/UpdateProfile.java @@ -16,7 +16,8 @@ public class UpdateProfile { @AccountUsername private String username; - @Email(regexp = "^[\\w-\\.]+@([\\w-]+\\.)+[\\w-]{2,4}$", message = "The email \"{0}\" incorrect") + @Email(regexp = "^[\\w-\\.]+@([\\w-]+\\.)+[\\w-]{2,4}$", + message = "The email \"${validatedValue}\" is not valid") private String email; @NotBlank diff --git a/src/main/java/io/hexlet/typoreporter/web/model/SignupAccountModel.java b/src/main/java/io/hexlet/typoreporter/web/model/SignupAccountModel.java index 16e5edee..b475a10b 100644 --- a/src/main/java/io/hexlet/typoreporter/web/model/SignupAccountModel.java +++ b/src/main/java/io/hexlet/typoreporter/web/model/SignupAccountModel.java @@ -26,7 +26,8 @@ public class SignupAccountModel { @AccountUsername private String username; - @Email(regexp = "^[\\w-\\.]+@([\\w-]+\\.)+[\\w-]{2,4}$", message = "The email \"{0}\" incorrect") + @Email(regexp = "^[\\w-\\.]+@([\\w-]+\\.)+[\\w-]{2,4}$", + message = "The email \"${validatedValue}\" is not valid") private String email; @AccountPassword diff --git a/src/main/java/io/hexlet/typoreporter/web/model/WorkspaceUserModel.java b/src/main/java/io/hexlet/typoreporter/web/model/WorkspaceUserModel.java index c58c57f0..17d088a7 100644 --- a/src/main/java/io/hexlet/typoreporter/web/model/WorkspaceUserModel.java +++ b/src/main/java/io/hexlet/typoreporter/web/model/WorkspaceUserModel.java @@ -12,6 +12,7 @@ @NoArgsConstructor public class WorkspaceUserModel { - @Email(regexp = "^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\\.[a-zA-Z]{2,}$", message = "The email \"{0}\" is not valid") + @Email(regexp = "^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\\.[a-zA-Z]{2,}$", + message = "The email \"${validatedValue}\" is not valid") private String email; } diff --git a/src/main/resources/templates/account/signup.html b/src/main/resources/templates/account/signup.html index 600dfb40..328c8fd2 100644 --- a/src/main/resources/templates/account/signup.html +++ b/src/main/resources/templates/account/signup.html @@ -13,7 +13,7 @@ th:classappend="${!#fields.hasErrors('username') && formModified}? 'is-valid'" th:errorclass="is-invalid"> -