Package org.powertac.visualizer.web.rest
Class AccountResource
- java.lang.Object
-
- org.powertac.visualizer.web.rest.AccountResource
-
@RestController @RequestMapping("/api") public class AccountResource extends Object
REST controller for managing the current user's account.
-
-
Constructor Summary
Constructors Constructor Description AccountResource(UserRepository userRepository, UserService userService, PersistentTokenRepository persistentTokenRepository)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description org.springframework.http.ResponseEntity<String>
changePassword(String password)
POST /account/change_password : changes the current user's passwordorg.springframework.http.ResponseEntity<UserDTO>
getAccount()
GET /account : get the current user.org.springframework.http.ResponseEntity<List<PersistentToken>>
getCurrentSessions()
GET /account/sessions : get the current open sessions.void
invalidateSession(String series)
DELETE /account/sessions?series={series} : invalidate an existing session.String
isAuthenticated(javax.servlet.http.HttpServletRequest request)
GET /authenticate : check if the user is authenticated, and return its login.org.springframework.http.ResponseEntity<String>
registerAccount(@Valid ManagedUserVM managedUserVM)
POST /register : register the user.org.springframework.http.ResponseEntity<String>
saveAccount(@Valid UserDTO userDTO)
POST /account : update the current user information.
-
-
-
Constructor Detail
-
AccountResource
public AccountResource(UserRepository userRepository, UserService userService, PersistentTokenRepository persistentTokenRepository)
-
-
Method Detail
-
registerAccount
@PostMapping(path="/register", produces={"application/json","text/plain"}) @Timed public org.springframework.http.ResponseEntity<String> registerAccount(@Valid @RequestBody @Valid ManagedUserVM managedUserVM)
POST /register : register the user.- Parameters:
managedUserVM
- the managed user View Model- Returns:
- the ResponseEntity with status 201 (Created) if the user is registered or 400 (Bad Request) if the login or e-mail is already in use
-
isAuthenticated
@GetMapping("/authenticate") @Timed public String isAuthenticated(javax.servlet.http.HttpServletRequest request)
GET /authenticate : check if the user is authenticated, and return its login.- Parameters:
request
- the HTTP request- Returns:
- the login if the user is authenticated
-
getAccount
@GetMapping("/account") @Timed public org.springframework.http.ResponseEntity<UserDTO> getAccount()
GET /account : get the current user.- Returns:
- the ResponseEntity with status 200 (OK) and the current user in body, or status 500 (Internal Server Error) if the user couldn't be returned
-
saveAccount
@PostMapping("/account") @Timed public org.springframework.http.ResponseEntity<String> saveAccount(@Valid @RequestBody @Valid UserDTO userDTO)
POST /account : update the current user information.- Parameters:
userDTO
- the current user information- Returns:
- the ResponseEntity with status 200 (OK), or status 400 (Bad Request) or 500 (Internal Server Error) if the user couldn't be updated
-
changePassword
@PostMapping(path="/account/change_password", produces="text/plain") @Timed public org.springframework.http.ResponseEntity<String> changePassword(@RequestBody String password)
POST /account/change_password : changes the current user's password- Parameters:
password
- the new password- Returns:
- the ResponseEntity with status 200 (OK), or status 400 (Bad Request) if the new password is not strong enough
-
getCurrentSessions
@GetMapping("/account/sessions") @Timed public org.springframework.http.ResponseEntity<List<PersistentToken>> getCurrentSessions()
GET /account/sessions : get the current open sessions.- Returns:
- the ResponseEntity with status 200 (OK) and the current open sessions in body, or status 500 (Internal Server Error) if the current open sessions couldn't be retrieved
-
invalidateSession
@DeleteMapping("/account/sessions/{series}") @Timed public void invalidateSession(@PathVariable String series) throws UnsupportedEncodingException
DELETE /account/sessions?series={series} : invalidate an existing session. - You can only delete your own sessions, not any other user's session - If you delete one of your existing sessions, and that you are currently logged in on that session, you will still be able to use that session, until you quit your browser: it does not work in real time (there is no API for that), it only removes the "remember me" cookie - This is also true if you invalidate your current session: you will still be able to use it until you close your browser or that the session times out. But automatic login (the "remember me" cookie) will not work anymore. There is an API to invalidate the current session, but there is no API to check which session uses which cookie.- Parameters:
series
- the series of an existing session- Throws:
UnsupportedEncodingException
- if the series couldnt be URL decoded
-
-