forked from Hexlet/hexlet-correction
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Hexlet#159] add oauth2handlers and login via github on sign up page
- Loading branch information
Showing
10 changed files
with
108 additions
and
63 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
23 changes: 0 additions & 23 deletions
23
src/main/java/io/hexlet/typoreporter/controller/OAuth2Controller.java
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
19 changes: 19 additions & 0 deletions
19
src/main/java/io/hexlet/typoreporter/handler/OAuth2LoginFailureHandler.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package io.hexlet.typoreporter.handler; | ||
|
||
import jakarta.servlet.ServletException; | ||
import jakarta.servlet.http.HttpServletRequest; | ||
import jakarta.servlet.http.HttpServletResponse; | ||
import org.springframework.security.core.AuthenticationException; | ||
import org.springframework.security.web.authentication.AuthenticationFailureHandler; | ||
|
||
import java.io.IOException; | ||
|
||
public class OAuth2LoginFailureHandler implements AuthenticationFailureHandler { | ||
@Override | ||
public void onAuthenticationFailure(HttpServletRequest request, | ||
HttpServletResponse response, | ||
AuthenticationException exception) throws IOException, ServletException { | ||
request.getSession().setAttribute("isOAuth2Fail", true); | ||
response.sendRedirect("/login"); | ||
} | ||
} |
27 changes: 27 additions & 0 deletions
27
src/main/java/io/hexlet/typoreporter/handler/OAuth2LoginSuccessHandler.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package io.hexlet.typoreporter.handler; | ||
|
||
import io.hexlet.typoreporter.domain.account.CustomOAuth2User; | ||
import io.hexlet.typoreporter.service.AccountService; | ||
import jakarta.servlet.ServletException; | ||
import jakarta.servlet.http.HttpServletRequest; | ||
import jakarta.servlet.http.HttpServletResponse; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.security.core.Authentication; | ||
import org.springframework.security.web.authentication.SavedRequestAwareAuthenticationSuccessHandler; | ||
|
||
import java.io.IOException; | ||
|
||
public class OAuth2LoginSuccessHandler extends SavedRequestAwareAuthenticationSuccessHandler { | ||
@Autowired | ||
private AccountService accountService; | ||
|
||
@Override | ||
public void onAuthenticationSuccess(HttpServletRequest request, | ||
HttpServletResponse response, | ||
Authentication authentication) throws ServletException, IOException { | ||
CustomOAuth2User user = (CustomOAuth2User) authentication.getPrincipal(); | ||
accountService.createOrUpdate(user); | ||
request.getSession().setAttribute("isOAuth2Fail", false); | ||
response.sendRedirect("/workspaces"); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters