package cn.com.qmth.stmms.admin.interceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import cn.com.qmth.stmms.common.domain.WebUser;
import cn.com.qmth.stmms.common.enums.Role;
import cn.com.qmth.stmms.common.interceptor.SessionInterceptor;
import cn.com.qmth.stmms.common.utils.RequestUtils;

/**
 * Admin模块操作拦截器
 *
 * @author LS
 */
public class SysAdminInterceptor extends SessionInterceptor {

    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        return validateSysAdminUser(request, response);
    }

    private boolean validateSysAdminUser(HttpServletRequest request, HttpServletResponse response) throws Exception {
        WebUser wu = RequestUtils.getWebUser(request);
        if (wu != null && wu.getRole() == Role.SYS_ADMIN) {
            return true;
        }
        return sessionExpire(request, response, "/login");
    }

}
