package bj.pranie.controller;

import bj.pranie.util.TimeUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.servlet.ModelAndView;

import java.util.Calendar;

/**
 * Created by Sebastian Sokolowski on 12.10.16.
 */

@Controller
public class IndexController {
    private final Logger log = LoggerFactory.getLogger(this.getClass());

    @RequestMapping(value = "/", method = RequestMethod.GET)
    public ModelAndView index(Model model) {
        ModelAndView modelAndView = new ModelAndView("index");
        modelAndView.addObject("time", TimeUtil.getTime());
        log.debug("time" + Calendar.getInstance().getTime().toString());

        return modelAndView;
    }
}

@@ -45,21 +45,19 @@
 nie.
-util.TimeUtil
+entity.User
 ;%0Aim
@@ -70,51 +70,123 @@
 rg.s
-lf4j.Logger;%0Aimport org.slf4j.LoggerFactory
+pringframework.security.core.Authentication;%0Aimport org.springframework.security.core.context.SecurityContextHolder
 ;%0Aim
@@ -237,45 +237,8 @@
 er;%0A
-import org.springframework.ui.Model;%0A
 impo
@@ -361,89 +361,8 @@
 hod;
-%0Aimport org.springframework.web.servlet.ModelAndView;%0A%0Aimport java.util.Calendar;
 %0A%0A/*
@@ -463,384 +463,448 @@
 r %7B%0A
-    private final Logger log = LoggerFactory.getLogger(this.getClass());%0A%0A    @RequestMapping(value = %22/%22, method = RequestMethod.GET)%0A    public ModelAndView index(Model model) %7B%0A        ModelAndView modelAndView = new ModelAndView(
+%0A    @RequestMapping(value = %22/%22, method = RequestMethod.GET)%0A    public String index() %7B%0A        if (isAuthenticatedUser()) %7B%0A            return %22redirect:/week%22;%0A        %7D%0A        return 
 %22index%22
-)
 ;%0A    
+%7D%0A%0A
     
-modelAndView.addObject(%22time%22, TimeUtil.getTime());%0A        log.debug(%22time%22 + Calendar.getInstance().getTime().toString());%0A
+private boolean isAuthenticatedUser() %7B%0A        Authentication authentication = SecurityContextHolder.getContext().getAuthentication();%0A        if (authentication.getPrincipal() instanceof User) %7B%0A            return true;%0A        %7D
 %0A   
@@ -919,20 +919,13 @@
 urn 
-modelAndView
+false
 ;%0A  

Implement auto redirect authenticated user to week page.