Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package ru.itmo.wp.web.page;
- import ru.itmo.wp.model.domain.User;
- import ru.itmo.wp.model.service.ArticleService;
- import ru.itmo.wp.model.service.UserService;
- import javax.servlet.http.HttpServletRequest;
- import java.util.Map;
- public class Page {
- static final String USER_ID_SESSION_KEY = "userId";
- private UserService userService = new UserService();
- private ArticleService articleService = new ArticleService();
- private User user;
- protected UserService getUserService() {
- return userService;
- }
- public ArticleService getArticleService() {
- return articleService;
- }
- public User getUser() {
- return user;
- }
- protected boolean isEmptyUser() {
- return user == null;
- }
- protected void login(HttpServletRequest request, User user) {
- request.getSession(true).setAttribute(USER_ID_SESSION_KEY, user.getId());
- }
- protected void logout(HttpServletRequest request) {
- request.getSession().removeAttribute(USER_ID_SESSION_KEY);
- }
- public void before(HttpServletRequest request, Map<String, Object> view) {
- Long userId = (Long) request.getSession().getAttribute(USER_ID_SESSION_KEY);
- if (userId != null) {
- user = userService.find(userId);
- view.put("user", user);
- }
- }
- public void after(HttpServletRequest request, Map<String, Object> view) {
- // No operations.
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement