From ed8855272f86509e97b5684b377a7d2c87dd0526 Mon Sep 17 00:00:00 2001 From: arefiev1997 Date: Sat, 11 May 2019 22:06:31 +0400 Subject: [PATCH] lk base --- .../ulstu/user/controller/UserController.java | 21 ++----- .../controller/UserProfileController.java | 34 ++++++++++++ .../user/service/UserSessionService.java | 6 ++ src/main/resources/templates/default.html | 10 +++- .../resources/templates/profile/profile.html | 55 +++++++++++++++++++ 5 files changed, 109 insertions(+), 17 deletions(-) create mode 100644 src/main/java/ru/ulstu/user/controller/UserProfileController.java create mode 100644 src/main/resources/templates/profile/profile.html diff --git a/src/main/java/ru/ulstu/user/controller/UserController.java b/src/main/java/ru/ulstu/user/controller/UserController.java index d7db909..05b5e9c 100644 --- a/src/main/java/ru/ulstu/user/controller/UserController.java +++ b/src/main/java/ru/ulstu/user/controller/UserController.java @@ -3,15 +3,9 @@ package ru.ulstu.user.controller; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.security.access.annotation.Secured; -import org.springframework.web.bind.annotation.DeleteMapping; -import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.PathVariable; -import org.springframework.web.bind.annotation.PostMapping; -import org.springframework.web.bind.annotation.PutMapping; -import org.springframework.web.bind.annotation.RequestBody; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RequestParam; -import org.springframework.web.bind.annotation.RestController; +import org.springframework.stereotype.Controller; +import org.springframework.ui.ModelMap; +import org.springframework.web.bind.annotation.*; import ru.ulstu.configuration.Constants; import ru.ulstu.core.model.response.PageableItems; import ru.ulstu.core.model.response.Response; @@ -19,15 +13,12 @@ import ru.ulstu.odin.controller.OdinController; import ru.ulstu.odin.model.OdinMetadata; import ru.ulstu.odin.model.OdinVoid; import ru.ulstu.odin.service.OdinService; -import ru.ulstu.user.model.UserDto; -import ru.ulstu.user.model.UserListDto; -import ru.ulstu.user.model.UserResetPasswordDto; -import ru.ulstu.user.model.UserRoleConstants; -import ru.ulstu.user.model.UserRoleDto; -import ru.ulstu.user.model.UserSessionListDto; +import ru.ulstu.user.model.*; import ru.ulstu.user.service.UserService; import ru.ulstu.user.service.UserSessionService; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpSession; import javax.validation.Valid; import static ru.ulstu.user.controller.UserController.URL; diff --git a/src/main/java/ru/ulstu/user/controller/UserProfileController.java b/src/main/java/ru/ulstu/user/controller/UserProfileController.java new file mode 100644 index 0000000..a5e00c5 --- /dev/null +++ b/src/main/java/ru/ulstu/user/controller/UserProfileController.java @@ -0,0 +1,34 @@ +package ru.ulstu.user.controller; + +import org.springframework.stereotype.Controller; +import org.springframework.ui.ModelMap; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import ru.ulstu.configuration.Constants; +import ru.ulstu.user.model.User; +import ru.ulstu.user.service.UserSessionService; +import springfox.documentation.annotations.ApiIgnore; + +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpSession; + +@Controller +@RequestMapping(value = "/profile") +@ApiIgnore +public class UserProfileController { + + private final UserSessionService userSessionService; + + public UserProfileController(UserSessionService userSessionService) + { + this.userSessionService = userSessionService; + } + + @GetMapping("/profile") + public void getUserProfile(ModelMap modelMap, HttpServletRequest request) { + HttpSession session = request.getSession(false); + final String sessionId = session.getAttribute(Constants.SESSION_ID_ATTR).toString(); + User user = userSessionService.getUserBySessionId(sessionId); + modelMap.addAttribute("user", user); + } +} diff --git a/src/main/java/ru/ulstu/user/service/UserSessionService.java b/src/main/java/ru/ulstu/user/service/UserSessionService.java index 0d985cd..13b18be 100644 --- a/src/main/java/ru/ulstu/user/service/UserSessionService.java +++ b/src/main/java/ru/ulstu/user/service/UserSessionService.java @@ -14,6 +14,8 @@ import ru.ulstu.user.model.UserSession; import ru.ulstu.user.model.UserSessionListDto; import ru.ulstu.user.repository.UserSessionRepository; +import javax.mail.Session; + import static ru.ulstu.core.util.StreamApiUtils.convert; @Service @@ -54,4 +56,8 @@ public class UserSessionService { userSessionRepository.save(userSession); log.debug("User session {} closed", sessionId); } + + public User getUserBySessionId(String sessionId) { + return userSessionRepository.findOneBySessionId(sessionId).getUser(); + } } diff --git a/src/main/resources/templates/default.html b/src/main/resources/templates/default.html index 00e2c0f..9605631 100644 --- a/src/main/resources/templates/default.html +++ b/src/main/resources/templates/default.html @@ -60,8 +60,14 @@ - diff --git a/src/main/resources/templates/profile/profile.html b/src/main/resources/templates/profile/profile.html new file mode 100644 index 0000000..b74e3db --- /dev/null +++ b/src/main/resources/templates/profile/profile.html @@ -0,0 +1,55 @@ + + + + +
+
+
+
+
+

Личный кабинет

+
+
+
+
+
+
+ +
+ + +

Incorrect firstName

+

+
+
+ + +

Incorrect lastName

+

+
+
+ + +

Incorrect patronymic

+

+
+
+
+
+
+
+
+ +