This commit is contained in:
arefiev1997 2019-05-11 22:06:31 +04:00
parent 09aa0bd4d6
commit ed8855272f
5 changed files with 109 additions and 17 deletions

View File

@ -3,15 +3,9 @@ package ru.ulstu.user.controller;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.springframework.security.access.annotation.Secured; import org.springframework.security.access.annotation.Secured;
import org.springframework.web.bind.annotation.DeleteMapping; import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping; import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.*;
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 ru.ulstu.configuration.Constants; import ru.ulstu.configuration.Constants;
import ru.ulstu.core.model.response.PageableItems; import ru.ulstu.core.model.response.PageableItems;
import ru.ulstu.core.model.response.Response; 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.OdinMetadata;
import ru.ulstu.odin.model.OdinVoid; import ru.ulstu.odin.model.OdinVoid;
import ru.ulstu.odin.service.OdinService; import ru.ulstu.odin.service.OdinService;
import ru.ulstu.user.model.UserDto; import ru.ulstu.user.model.*;
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.service.UserService; import ru.ulstu.user.service.UserService;
import ru.ulstu.user.service.UserSessionService; import ru.ulstu.user.service.UserSessionService;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import javax.validation.Valid; import javax.validation.Valid;
import static ru.ulstu.user.controller.UserController.URL; import static ru.ulstu.user.controller.UserController.URL;

View File

@ -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);
}
}

View File

@ -14,6 +14,8 @@ import ru.ulstu.user.model.UserSession;
import ru.ulstu.user.model.UserSessionListDto; import ru.ulstu.user.model.UserSessionListDto;
import ru.ulstu.user.repository.UserSessionRepository; import ru.ulstu.user.repository.UserSessionRepository;
import javax.mail.Session;
import static ru.ulstu.core.util.StreamApiUtils.convert; import static ru.ulstu.core.util.StreamApiUtils.convert;
@Service @Service
@ -54,4 +56,8 @@ public class UserSessionService {
userSessionRepository.save(userSession); userSessionRepository.save(userSession);
log.debug("User session {} closed", sessionId); log.debug("User session {} closed", sessionId);
} }
public User getUserBySessionId(String sessionId) {
return userSessionRepository.findOneBySessionId(sessionId).getUser();
}
} }

View File

@ -60,8 +60,14 @@
<li class="nav-item"> <li class="nav-item">
<a class="nav-link js-scroll-trigger" target="_blank" href="https://kias.rfbr.ru/">КИАС РФФИ</a> <a class="nav-link js-scroll-trigger" target="_blank" href="https://kias.rfbr.ru/">КИАС РФФИ</a>
</li> </li>
<li class="nav-item"> <li class="nav-item dropdown">
<a class="nav-link js-scroll-trigger" href="/logout">Выход</a> <a class="nav-link dropdown-toggle" href="#" id="navbarDropdown" role="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
Профиль
</a>
<div class="dropdown-menu" aria-labelledby="navbarDropdown">
<a class="dropdown-item" href="/profile/profile">Личный кабинет</a>
<a class="dropdown-item" href="/logout">Выход</a>
</div>
</li> </li>
</ul> </ul>
</div> </div>

View File

@ -0,0 +1,55 @@
<!DOCTYPE html>
<html lang="en"
xmlns:layout="http://www.ultraq.net.nz/thymeleaf/layout"
layout:decorate="~{default}" xmlns:th="http://www.w3.org/1999/xhtml" xmlns="http://www.w3.org/1999/html">
<body>
<div class="container" layout:fragment="content">
<section id="ewrq">
<div class="container">
<div class="row">
<div class="col-lg-12 text-center">
<h2 class="section-heading text-uppercase">Личный кабинет</h2>
</div>
</div>
<hr/>
<div class="row">
<div class="col-lg-12">
<form id="profile-form" method="post" th:action="@{'/profile/profile'}"
th:object="${user}">
<input type="hidden" name="id" th:field="*{id}"/>
<div class="form-group">
<label for="firstName">Имя:</label>
<input class="form-control" id="firstName" type="text"
placeholder="Имя"
th:field="*{firstName}"/>
<p th:if="${#fields.hasErrors('firstName')}" th:errors="*{title}"
class="alert alert-danger">Incorrect firstName</p>
<p class="help-block text-danger"></p>
</div>
<div class="form-group">
<label for="lastName">Фамилия:</label>
<input class="form-control" id="lastName" type="text"
placeholder="lastName"
th:field="*{lastName}"/>
<p th:if="${#fields.hasErrors('lastName')}" th:errors="*{title}"
class="alert alert-danger">Incorrect lastName</p>
<p class="help-block text-danger"></p>
</div>
<div class="form-group">
<label for="patronymic">Отчество:</label>
<input class="form-control" id="patronymic" type="text"
placeholder="Имя"
th:field="*{patronymic}"/>
<p th:if="${#fields.hasErrors('patronymic')}" th:errors="*{title}"
class="alert alert-danger">Incorrect patronymic</p>
<p class="help-block text-danger"></p>
</div>
</form>
</div>
</div>
</div>
</section>
</div>
</body>
</html>