Package app.YUP.controller
Class AuthenticationController
java.lang.Object
app.YUP.controller.AuthenticationController
This class is a controller for handling authentication related requests.
It provides endpoints for logging in, logging out, and displaying the login page.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionapiLogin(AuthenticationRequest authenticationRequest, jakarta.servlet.http.HttpServletResponse response, String captcha) This method is used to authenticate a user.apiLogout(jakarta.servlet.http.HttpServletRequest request, jakarta.servlet.http.HttpServletResponse response) This method is used to log out a user.loginPage(org.springframework.ui.Model model, jakarta.servlet.http.HttpServletResponse response) This method is used to display the login page.
-
Constructor Details
-
AuthenticationController
public AuthenticationController()
-
-
Method Details
-
loginPage
@GetMapping("/login") public String loginPage(org.springframework.ui.Model model, jakarta.servlet.http.HttpServletResponse response) This method is used to display the login page. It takes a Model object as a parameter and adds a new AuthenticationRequest object to it. It returns a string that represents the name of the view to be rendered.- Parameters:
model- This is the Model object that can be used to pass attributes to the view.- Returns:
- String This returns the name of the view to be rendered.
-
apiLogin
@PostMapping("/api/login") public String apiLogin(@ModelAttribute AuthenticationRequest authenticationRequest, jakarta.servlet.http.HttpServletResponse response, @RequestParam("g-recaptcha-response") String captcha) This method is used to authenticate a user. It takes an AuthenticationRequest object, a HttpServletResponse object, and a captcha string as parameters. It uses the UserService to validate the captcha and the AuthenticationService to authenticate the user and set a JWT token in a cookie. It also sends an email to the user with the login details.- Parameters:
authenticationRequest- This is a request object that contains the username and password of the user.response- This is the HttpServletResponse object that contains the response details.captcha- This is a string that contains the captcha response.- Returns:
- String This returns a redirect URL to the homepage.
-
apiLogout
@GetMapping("/api/logout") public String apiLogout(jakarta.servlet.http.HttpServletRequest request, jakarta.servlet.http.HttpServletResponse response) This method is used to log out a user. It takes a HttpServletRequest object and a HttpServletResponse object as parameters. It uses the AuthenticationService to delete the JWT cookie. It logs the logout operation and returns a string that represents the name of the view to be rendered.- Parameters:
request- This is the HttpServletRequest object that contains the request details.response- This is the HttpServletResponse object that contains the response details.- Returns:
- String This returns the name of the view to be rendered.
-