/**
 * FPT University Capstone Project 2015.
 * Program: HSTS.
 * Program manager: Kieu Trong Khanh.
 * Author: dangquantran.
 * Date: 9/23/2015.
 */
package vn.edu.fpt.hsts.web;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;
import vn.edu.fpt.hsts.common.IConsts;

/**
 * Home controller, for processing common mapping, redirect, etc.
 */
@Controller
public class HomeController {

    private static final Logger LOGGER = LoggerFactory.getLogger(HomeController.class);

    @RequestMapping(value = "/")
    public ModelAndView home() {
        LOGGER.info(IConsts.BEGIN_METHOD);
        try {
            ModelAndView modelAndView = new ModelAndView();
            modelAndView.setViewName("home");
            return modelAndView;
        } finally {
            LOGGER.info(IConsts.END_METHOD);
        }
    }

    @RequestMapping(value = "home")
    public ModelAndView homePage() {
        LOGGER.info(IConsts.BEGIN_METHOD);
        try {
            ModelAndView modelAndView = new ModelAndView();
            modelAndView.setViewName("home");
            return modelAndView;
        } finally {
            LOGGER.info(IConsts.END_METHOD);
        }
    }

    @RequestMapping(value = "/500")
    public ModelAndView internalServerError() {
        LOGGER.info(IConsts.BEGIN_METHOD);
        try {
            ModelAndView modelAndView = new ModelAndView();
            modelAndView.setViewName("500");
            return modelAndView;
        } finally {
            LOGGER.info(IConsts.END_METHOD);
        }
    }

    @RequestMapping(value = "/404")
    public ModelAndView pageNotFound() {
        LOGGER.info(IConsts.BEGIN_METHOD);
        try {
            ModelAndView modelAndView = new ModelAndView();
            modelAndView.setViewName("404");
            return modelAndView;
        } finally {
            LOGGER.info(IConsts.END_METHOD);
        }
    }
}

@@ -230,16 +230,79 @@
 actory;%0A
+import org.springframework.beans.factory.annotation.Autowired;%0A
 import o
@@ -497,16 +497,112 @@
 IConsts;
+%0Aimport vn.edu.fpt.hsts.common.util.StringUtils;%0Aimport vn.edu.fpt.hsts.web.session.UserSession;
 %0A%0A/**%0A *
@@ -801,16 +801,116 @@
 lass);%0A%0A
+    /**%0A     * The %7B@link UserSession%7D%0A     */%0A    @Autowired%0A    private UserSession userSession;%0A%0A
     @Req
@@ -941,36 +941,30 @@
 %0A    public 
-ModelAndView
+String
  home() %7B%0A  
@@ -1034,133 +1034,142 @@
     
-ModelAndView modelAndView = new ModelAndView();%0A            modelAndView.setViewName(%22home%22);%0A            return modelAndView
+if (StringUtils.isEmpty(userSession.getUsername())) %7B%0A               return %22redirect:/login%22;%0A            %7D%0A            return %22home%22
 ;%0A  
@@ -1295,28 +1295,22 @@
  public 
-ModelAndView
+String
  homePag
@@ -1388,114 +1388,126 @@
     
-ModelAndView modelAndView = new ModelAndView();%0A            modelAndView.setViewName(%22home%22)
+if (StringUtils.isEmpty(userSession.getUsername())) %7B%0A                return %22redirect:/login%22
 ;%0A    
+ 
+       %7D%0A
         
 retu
@@ -1502,35 +1502,33 @@
         
+    
 return 
-modelAndView
+%22home%22
 ;%0A      

update HomeController