Class UserController

java.lang.Object
app.YUP.controller.UserController

@Controller @RequestMapping("/user/") public class UserController extends Object
This class is a controller for handling user related requests. It provides endpoints for creating a new user and viewing user details.
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    changePassword(ChangePasswordRequest changePasswordRequest, jakarta.servlet.http.HttpServletRequest request, jakarta.servlet.http.HttpServletResponse response)
    This method is used to change a user's password.
    org.springframework.http.ResponseEntity<Boolean>
    checkIfUserExist(Map<String,String> payload, jakarta.servlet.http.HttpServletResponse response)
    This method is used to check if a user with a given username exists in the system.
    deleteUser(jakarta.servlet.http.HttpServletRequest request, jakarta.servlet.http.HttpServletResponse response)
    This method is used to delete a user from the system.
    register(RegistrationRequest registrationRequest, String captcha, jakarta.servlet.http.HttpServletResponse response)
    This method is used to register a new user.
    registrationPage(org.springframework.ui.Model model, jakarta.servlet.http.HttpServletResponse response)
    This method is used to display the registration page.
    updateUser(UserUpdateRequest userUpdateRequest, jakarta.servlet.http.HttpServletRequest request, jakarta.servlet.http.HttpServletResponse response)
    This method is used to update a user's details.
    userPage(org.springframework.ui.Model model, jakarta.servlet.http.HttpServletRequest request, jakarta.servlet.http.HttpServletResponse response)
    This method is used to display the user page.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • UserController

      public UserController()
  • Method Details

    • register

      @PostMapping("/api/newUser") public String register(@ModelAttribute RegistrationRequest registrationRequest, @RequestParam("g-recaptcha-response") String captcha, jakarta.servlet.http.HttpServletResponse response)
      This method is used to register a new user. It takes a RegistrationRequest object and a captcha string as parameters. It uses the UserService to validate the captcha and create a new user. It also sends an email to the user with the registration details.
      Parameters:
      registrationRequest - This is a request object that contains the details of the user to be registered.
      captcha - This is a string that contains the captcha response.
      Returns:
      String This returns a redirect URL to the login page.
    • deleteUser

      @PostMapping("/api/delete") public String deleteUser(jakarta.servlet.http.HttpServletRequest request, jakarta.servlet.http.HttpServletResponse response)
      This method is used to delete a user from the system. It retrieves the user ID from the authentication cookie in the request. It then uses the UserService to fetch the user from the database and delete it. Finally, it redirects the user to the login page.
      Parameters:
      request - The HttpServletRequest object containing the request details.
      response - The HttpServletResponse object to handle the response.
      Returns:
      A string representing the redirect URL to the login page.
    • updateUser

      @PostMapping("/api/update") public String updateUser(@ModelAttribute UserUpdateRequest userUpdateRequest, jakarta.servlet.http.HttpServletRequest request, jakarta.servlet.http.HttpServletResponse response)
      This method is used to update a user's details.
      Parameters:
      userUpdateRequest - The request object containing the updated user details.
      request - The HTTP request object.
      response - The HTTP response object.
      Returns:
      A string representing a redirect to the user view page.
    • changePassword

      @PostMapping("/api/changePassword") public String changePassword(ChangePasswordRequest changePasswordRequest, jakarta.servlet.http.HttpServletRequest request, jakarta.servlet.http.HttpServletResponse response)
      This method is used to change a user's password.
      Parameters:
      changePasswordRequest - The request object containing the new password and its confirmation.
      request - The HTTP request object.
      response - The HTTP response object.
      Returns:
      A string representing a redirect to the login page.
    • registrationPage

      @GetMapping("/newUser") public String registrationPage(org.springframework.ui.Model model, jakarta.servlet.http.HttpServletResponse response)
      This method is used to display the registration page. It takes a Model object as a parameter and adds a new RegistrationRequest 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.
    • userPage

      @GetMapping("/viewUser") public String userPage(org.springframework.ui.Model model, jakarta.servlet.http.HttpServletRequest request, jakarta.servlet.http.HttpServletResponse response)
      This method is used to display the user page. It takes a Model object, a HttpServletRequest object, and a HttpServletResponse object as parameters. It uses the AuthenticationService to get the username from the cookie in the request. It then uses the UserService to get the User object and map it to a UserResponse object. It adds the UserResponse object to the model and sets the HTTP status code of the response to 200 (OK). 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.
      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.
    • checkIfUserExist

      @PostMapping("/checkIfUserExist") public org.springframework.http.ResponseEntity<Boolean> checkIfUserExist(@RequestBody Map<String,String> payload, jakarta.servlet.http.HttpServletResponse response)
      This method is used to check if a user with a given username exists in the system.
      Parameters:
      payload - A map containing the username to be checked. The key is "message".
      response - The HttpServletResponse object to handle the response.
      Returns:
      A ResponseEntity containing a boolean value indicating whether a user with the given username exists. If the user exists, the boolean value is true; otherwise, it is false.