package com.izouma.awesomeadmin.web;

import com.izouma.awesomeadmin.util.CheckUtil;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;


/**
 * 首页
 * Created by xiong on 2016/10/26.
 */
@Controller
public class MainController {


    @RequestMapping(value = {"/index", "/"}, method = RequestMethod.GET)
    @ResponseBody
    public ModelAndView home() {

        ModelAndView modelAndView = new ModelAndView("html/Unauthorized.html");
        if (checkZouma()) return modelAndView;

        return new ModelAndView("redirect:/admin");
    }

    @RequestMapping("/{viewName}")
    public ModelAndView index(HttpServletRequest request, @PathVariable("viewName") String viewName) {

        ModelAndView modelAndView = new ModelAndView("html/Unauthorized.html");
        if (checkZouma()) return modelAndView;

        return new ModelAndView("html/" + viewName + ".html");
    }

    private boolean checkZouma() {

        return !CheckUtil.checkProjectActive();

    }

}
