Class UserController

java.lang.Object
edu.ntnu.idatt2106_2023_06.backend.controller.UserController

@RestController @CrossOrigin("*") @RequestMapping("/user") public class UserController extends Object
UserController handles HTTP requests related to user management and authentication. This controller provides endpoints for user registration, login, and various user operations such as updating profile information, uploading and retrieving profile pictures, and changing the user's password.
Author:
Brage H. Kvamme, Trym Gudvangen
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    org.springframework.http.ResponseEntity<Object>
    deletePicture(org.springframework.security.core.Authentication authentication)
    Deletes the user's profile picture.
    org.springframework.http.ResponseEntity<Object>
    getInfo(org.springframework.security.core.Authentication authentication)
    Retrieves the user's text information.
    org.springframework.http.ResponseEntity<Object>
    getPicture(org.springframework.security.core.Authentication authentication)
    Retrieves the user's profile picture.
    org.springframework.http.ResponseEntity<Object>
    Retrieves the user's profile picture from ID.
    org.springframework.http.ResponseEntity<AuthenticationResponseDTO>
    register(UserLoginDTO userLoginDTO)
    Authenticates a user with login information.
    org.springframework.http.ResponseEntity<Object>
    Registers a new user.
    org.springframework.http.ResponseEntity<Boolean>
    search(Long fridgeId, org.springframework.security.core.Authentication authentication)
    This method checks whether a user with the given fridge id.
    org.springframework.http.ResponseEntity<Object>
    search(String username)
    Searches for a user by username.
    org.springframework.http.ResponseEntity<String>
    update(UserUpdateDTO userUpdateDTO, org.springframework.security.core.Authentication authentication)
    Updates the user's text information.
    org.springframework.http.ResponseEntity<Object>
    updatePassword(UserPasswordUpdateDTO passwordUpdateDTO, org.springframework.security.core.Authentication authentication)
    Updates the user's password.
    org.springframework.http.ResponseEntity<Object>
    updatePicture(org.springframework.web.multipart.MultipartFile picture, org.springframework.security.core.Authentication authentication)
    Updates the user's profile picture.

    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("/register") public org.springframework.http.ResponseEntity<Object> register(@RequestBody UserRegisterDTO user) throws jakarta.mail.MessagingException
      Registers a new user.
      Parameters:
      user - The UserRegisterDTO object containing the user's registration details.
      Returns:
      ResponseEntity containing the generated authentication token upon successful registration.
      Throws:
      jakarta.mail.MessagingException
    • register

      @PostMapping("/login") public org.springframework.http.ResponseEntity<AuthenticationResponseDTO> register(@RequestBody UserLoginDTO userLoginDTO)
      Authenticates a user with login information.
      Parameters:
      userLoginDTO - The UserLoginDTO object containing the user's login details.
      Returns:
      ResponseEntity containing the generated authentication token upon successful authentication.
    • update

      @PutMapping("/update/info") public org.springframework.http.ResponseEntity<String> update(@RequestBody UserUpdateDTO userUpdateDTO, org.springframework.security.core.Authentication authentication)
      Updates the user's text information.
      Parameters:
      userUpdateDTO - The UserUpdateDTO object containing the user's updated information.
      Returns:
      ResponseEntity indicating the success of the update operation.
    • updatePicture

      @PutMapping("/update/picture") public org.springframework.http.ResponseEntity<Object> updatePicture(@RequestParam("picture") org.springframework.web.multipart.MultipartFile picture, org.springframework.security.core.Authentication authentication) throws IOException
      Updates the user's profile picture.
      Parameters:
      picture - The MultipartFile containing the user's new profile picture.
      authentication - The authentication object containing the user's authentication details.
      Returns:
      ResponseEntity indicating the success of the update operation.
      Throws:
      IOException
    • updatePassword

      @PutMapping("/update/password") public org.springframework.http.ResponseEntity<Object> updatePassword(@RequestBody UserPasswordUpdateDTO passwordUpdateDTO, org.springframework.security.core.Authentication authentication)
      Updates the user's password.
      Parameters:
      passwordUpdateDTO - The UserPasswordUpdateDTO object containing the user's new password.
      authentication - The authentication object containing the user's authentication details.
      Returns:
      ResponseEntity indicating the success of the update operation.
    • getPicture

      @GetMapping("/get/picture") public org.springframework.http.ResponseEntity<Object> getPicture(org.springframework.security.core.Authentication authentication) throws IOException
      Retrieves the user's profile picture.
      Parameters:
      authentication - The authentication object containing the user's authentication details.
      Returns:
      ResponseEntity containing the user's profile picture as a byte array.
      Throws:
      IOException
    • getPictureFromId

      @GetMapping("/get/picture/{id}") public org.springframework.http.ResponseEntity<Object> getPictureFromId(@PathVariable Long id) throws IOException
      Retrieves the user's profile picture from ID.
      Returns:
      ResponseEntity containing the user's profile picture as a byte array.
      Throws:
      IOException
    • getInfo

      @GetMapping("/get/info") public org.springframework.http.ResponseEntity<Object> getInfo(org.springframework.security.core.Authentication authentication)
      Retrieves the user's text information.
      Parameters:
      authentication - The authentication object containing the user's authentication details.
      Returns:
      ResponseEntity containing the user's text information.
    • deletePicture

      @DeleteMapping("/delete/picture") public org.springframework.http.ResponseEntity<Object> deletePicture(org.springframework.security.core.Authentication authentication) throws IOException
      Deletes the user's profile picture.
      Parameters:
      authentication - The authentication object containing the user's authentication details.
      Returns:
      ResponseEntity indicating the success of the delete operation.
      Throws:
      IOException
    • search

      @GetMapping("/search/{username}") public org.springframework.http.ResponseEntity<Object> search(@PathVariable String username)
      Searches for a user by username.
      Parameters:
      username - The username of the user to be searched for.
      Returns:
      ResponseEntity containing the user's text information.
    • search

      @GetMapping("/superuser") public org.springframework.http.ResponseEntity<Boolean> search(@RequestParam(name="fridgeId") Long fridgeId, org.springframework.security.core.Authentication authentication)
      This method checks whether a user with the given fridge id.
      Parameters:
      fridgeId - The id of the fridge to be checked
      authentication - The authentication of the user.
      Returns:
      ResponseEntity containing the user's superuser status.