diff --git a/src/main/java/io/hexlet/typoreporter/config/SecurityConfig.java b/src/main/java/io/hexlet/typoreporter/config/SecurityConfig.java index ae74543d..9456b6bf 100644 --- a/src/main/java/io/hexlet/typoreporter/config/SecurityConfig.java +++ b/src/main/java/io/hexlet/typoreporter/config/SecurityConfig.java @@ -108,7 +108,6 @@ public SecurityFilterChain filterChain(HttpSecurity http, .userService(oAuth2UserService) .and() .successHandler(getOAuth2SuccessHandler()) - .defaultSuccessUrl("/workspaces") ) .csrf(csrf -> csrf .ignoringRequestMatchers( diff --git a/src/main/java/io/hexlet/typoreporter/handler/OAuth2SuccessHandler.java b/src/main/java/io/hexlet/typoreporter/handler/OAuth2SuccessHandler.java index 81160709..0d08d856 100644 --- a/src/main/java/io/hexlet/typoreporter/handler/OAuth2SuccessHandler.java +++ b/src/main/java/io/hexlet/typoreporter/handler/OAuth2SuccessHandler.java @@ -22,6 +22,10 @@ public void onAuthenticationSuccess(HttpServletRequest request, HttpServletResponse response, Authentication authentication) throws IOException, ServletException { CustomOAuth2User oAuth2User = (CustomOAuth2User) authentication.getPrincipal(); + if (oAuth2User.getEmail() == null) { + //TODO: добавить ошибку на фронт, если email приватный + response.sendRedirect("/login"); + } accountService.processOAuthPostLogin(oAuth2User); response.sendRedirect("/workspaces"); } diff --git a/src/main/java/io/hexlet/typoreporter/service/AccountService.java b/src/main/java/io/hexlet/typoreporter/service/AccountService.java index 5c6512fb..b2884021 100644 --- a/src/main/java/io/hexlet/typoreporter/service/AccountService.java +++ b/src/main/java/io/hexlet/typoreporter/service/AccountService.java @@ -151,7 +151,7 @@ public void processOAuthPostLogin(CustomOAuth2User user) { account.setUsername(user.getLogin()); account.setPassword(user.getPassword()); account.setFirstName(user.getFirstName()); - account.setLastName(user.getFirstName()); + account.setLastName(user.getLastName()); accountRepository.save(account); } }