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"> -
+

@@ -24,7 +24,7 @@ th:classappend="${!#fields.hasErrors('email') && formModified}? 'is-valid'" th:errorclass="is-invalid"> -
+

@@ -35,7 +35,7 @@ th:classappend="${!#fields.hasErrors('firstName') && formModified}? 'is-valid'" th:errorclass="is-invalid"> -
+

@@ -46,7 +46,7 @@ th:classappend="${!#fields.hasErrors('lastName') && formModified}? 'is-valid'" th:errorclass="is-invalid"> -
+

@@ -55,7 +55,7 @@ -
+

@@ -64,7 +64,7 @@ -
+

diff --git a/src/main/resources/templates/error-general.html b/src/main/resources/templates/error-general.html index 9fbfdc1c..e8b7e77e 100644 --- a/src/main/resources/templates/error-general.html +++ b/src/main/resources/templates/error-general.html @@ -2,7 +2,7 @@ -
+
diff --git a/src/main/resources/templates/login.html b/src/main/resources/templates/login.html index 86781e54..69a48f37 100644 --- a/src/main/resources/templates/login.html +++ b/src/main/resources/templates/login.html @@ -6,7 +6,7 @@
- +
diff --git a/src/main/resources/templates/widget/report-typo-error.html b/src/main/resources/templates/widget/report-typo-error.html index 2d524213..b9aeb711 100755 --- a/src/main/resources/templates/widget/report-typo-error.html +++ b/src/main/resources/templates/widget/report-typo-error.html @@ -2,7 +2,7 @@ -
+
diff --git a/src/main/resources/templates/widget/typo-form.html b/src/main/resources/templates/widget/typo-form.html index a56b617f..02ea2f1b 100755 --- a/src/main/resources/templates/widget/typo-form.html +++ b/src/main/resources/templates/widget/typo-form.html @@ -17,7 +17,7 @@ type="text" > -
+

diff --git a/src/main/resources/templates/workspace/wks-settings.html b/src/main/resources/templates/workspace/wks-settings.html index 0881b0d1..1c4ac2e3 100644 --- a/src/main/resources/templates/workspace/wks-settings.html +++ b/src/main/resources/templates/workspace/wks-settings.html @@ -49,7 +49,7 @@
-
    +
diff --git a/src/main/resources/templates/workspace/wks-users.html b/src/main/resources/templates/workspace/wks-users.html index 271b1b8f..b7023c12 100644 --- a/src/main/resources/templates/workspace/wks-users.html +++ b/src/main/resources/templates/workspace/wks-users.html @@ -27,7 +27,7 @@ placeholder="Enter user email. For example: hexlet@gmail.com" th:field="*{email}" th:classappend="${!#fields.hasErrors('email') && formModified}? 'is-valid'" th:errorclass="is-invalid" required> -
+

diff --git a/src/test/java/io/hexlet/typoreporter/web/AccountControllerIT.java b/src/test/java/io/hexlet/typoreporter/web/AccountControllerIT.java index 2e1328df..3603955c 100644 --- a/src/test/java/io/hexlet/typoreporter/web/AccountControllerIT.java +++ b/src/test/java/io/hexlet/typoreporter/web/AccountControllerIT.java @@ -20,6 +20,7 @@ import static io.hexlet.typoreporter.test.Constraints.POSTGRES_IMAGE; import static org.assertj.core.api.Assertions.assertThat; import static org.springframework.security.test.web.servlet.request.SecurityMockMvcRequestPostProcessors.csrf; +import static org.springframework.security.test.web.servlet.request.SecurityMockMvcRequestPostProcessors.user; import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post; import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.put; @@ -74,6 +75,7 @@ void updateAccountWithWrongEmailDomain() throws Exception { .param("confirmPassword", password) .param("firstName", userName) .param("lastName", userName) + .with(user(correctEmailDomain)) .with(csrf())); assertThat(accountRepository.findAccountByEmail(wrongEmailDomain)).isEmpty(); assertThat(accountRepository.findAccountByEmail(correctEmailDomain).orElseThrow().getEmail()) @@ -103,6 +105,7 @@ void updateAccountEmailUsingDifferentCase() throws Exception { .param("lastName", username) .param("username", username) .param("email", emailUpperCase) + .with(user(emailLowerCase)) .with(csrf())); assertThat(accountRepository.findAccountByEmail(emailUpperCase)).isEmpty(); assertThat(accountRepository.findAccountByEmail(emailLowerCase)).isNotEmpty(); diff --git a/src/test/java/io/hexlet/typoreporter/web/SignupControllerIT.java b/src/test/java/io/hexlet/typoreporter/web/SignupControllerIT.java index 81ce229d..d0b5ce1b 100644 --- a/src/test/java/io/hexlet/typoreporter/web/SignupControllerIT.java +++ b/src/test/java/io/hexlet/typoreporter/web/SignupControllerIT.java @@ -18,6 +18,7 @@ import org.testcontainers.containers.PostgreSQLContainer; import static com.github.database.rider.core.api.configuration.Orthography.LOWERCASE; +import static io.hexlet.typoreporter.test.factory.EntitiesFactory.ACCOUNT_INCORRECT_EMAIL; import static org.springframework.security.test.web.servlet.request.SecurityMockMvcRequestPostProcessors.csrf; import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post; import static org.assertj.core.api.Assertions.assertThat; @@ -123,4 +124,20 @@ void createAccountWithWrongPassword() throws Exception { assertThat(accountRepository.findAccountByEmail(email)).isEmpty(); } + + @Test + void signupInAccountWithBadEmail() throws Exception { + model.setEmail(ACCOUNT_INCORRECT_EMAIL); + var response = mockMvc.perform(post("/signup") + .param("username", model.getUsername()) + .param("email", model.getEmail()) + .param("password", model.getPassword()) + .param("confirmPassword", model.getConfirmPassword()) + .param("firstName", model.getFirstName()) + .param("lastName", model.getLastName()) + .with(csrf())) + .andReturn(); + var body = response.getResponse().getContentAsString(); + assertThat(body).contains(String.format("The email "%s" is not valid", ACCOUNT_INCORRECT_EMAIL)); + } } diff --git a/src/test/java/io/hexlet/typoreporter/web/WorkspaceControllerIT.java b/src/test/java/io/hexlet/typoreporter/web/WorkspaceControllerIT.java index d27d4211..7c90e348 100644 --- a/src/test/java/io/hexlet/typoreporter/web/WorkspaceControllerIT.java +++ b/src/test/java/io/hexlet/typoreporter/web/WorkspaceControllerIT.java @@ -403,7 +403,7 @@ void addUserNonValidEmailTest() throws Exception { .with(csrf())) .andReturn(); var body = response.getResponse().getContentAsString(); - assertThat(body).contains("The email %s is not valid", ACCOUNT_INCORRECT_EMAIL); + assertThat(body).contains(String.format("The email "%s" is not valid", ACCOUNT_INCORRECT_EMAIL)); } }