2021-11-05 09:19:44 +01:00
|
|
|
package eu.dnetlib.loginservice.controllers;
|
|
|
|
|
|
|
|
import eu.dnetlib.loginservice.entities.User;
|
2023-04-04 21:19:15 +02:00
|
|
|
import eu.dnetlib.loginservice.properties.Properties;
|
2021-11-24 23:20:57 +01:00
|
|
|
import eu.dnetlib.loginservice.services.UserInfoService;
|
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
2021-11-05 09:19:44 +01:00
|
|
|
import org.springframework.http.ResponseEntity;
|
|
|
|
import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
|
import org.springframework.web.bind.annotation.RequestMethod;
|
|
|
|
import org.springframework.web.bind.annotation.RestController;
|
|
|
|
|
2023-04-04 21:19:15 +02:00
|
|
|
import javax.servlet.http.HttpServletRequest;
|
|
|
|
import javax.servlet.http.HttpServletResponse;
|
|
|
|
import javax.servlet.http.HttpSession;
|
|
|
|
import java.io.IOException;
|
|
|
|
|
2021-11-05 09:19:44 +01:00
|
|
|
@RestController
|
|
|
|
public class UserController {
|
2021-11-24 23:20:57 +01:00
|
|
|
|
|
|
|
private final UserInfoService userInfoService;
|
2023-04-04 21:19:15 +02:00
|
|
|
private final Properties properties;
|
2021-11-24 23:20:57 +01:00
|
|
|
|
|
|
|
@Autowired
|
2023-04-04 21:19:15 +02:00
|
|
|
public UserController(UserInfoService userInfoService, Properties properties) {
|
2021-11-24 23:20:57 +01:00
|
|
|
this.userInfoService = userInfoService;
|
2023-04-04 21:19:15 +02:00
|
|
|
this.properties = properties;
|
2021-11-24 23:20:57 +01:00
|
|
|
}
|
2021-11-05 09:19:44 +01:00
|
|
|
|
|
|
|
@RequestMapping(value = "/userInfo", method = RequestMethod.GET)
|
2021-11-24 23:20:57 +01:00
|
|
|
public ResponseEntity<User> getUserInfo() {
|
|
|
|
return ResponseEntity.ok(userInfoService.getUserInfo());
|
2021-11-05 09:19:44 +01:00
|
|
|
}
|
2023-04-04 21:19:15 +02:00
|
|
|
|
|
|
|
@RequestMapping(value = "/redirect",method = RequestMethod.GET)
|
|
|
|
public void redirect(HttpServletRequest request, HttpServletResponse response) throws IOException {
|
|
|
|
HttpSession session = request.getSession();
|
|
|
|
String redirect = (String) session.getAttribute("redirect");
|
|
|
|
session.removeAttribute("redirect");
|
|
|
|
if(redirect == null) {
|
|
|
|
redirect = properties.getRedirect();
|
|
|
|
}
|
|
|
|
session.invalidate();
|
|
|
|
response.sendRedirect(redirect);
|
|
|
|
}
|
2021-11-05 09:19:44 +01:00
|
|
|
}
|