package com.chenyang.nse.bussiness.controller.core;

import com.chenyang.nse.bussiness.engine.infa.powercenter961.pubtool.StringUtil;
import com.chenyang.nse.bussiness.entity.cache.LoginUser;
import com.chenyang.nse.bussiness.entity.orm.table.console.TConsoleSystemSetting;
import java.util.List;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

@Controller
@RequestMapping({"/core/modifypassword"})
public class ModifyPasswordController {
   @RequestMapping
   public String index(HttpServletRequest request, HttpServletResponse response, Model model) {
      Object obj = request.getSession().getAttribute("loginUser");
      LoginUser loginUser = null;
      if (obj != null) {
         loginUser = (LoginUser)obj;
         Boolean sysChpwdFlg = false;
         String pwdLevel = "1";
         List<TConsoleSystemSetting> tcssLst = loginUser.getTcssLst();
         if (null != tcssLst && tcssLst.size() > 0) {
            for(TConsoleSystemSetting tcss : tcssLst) {
               if (tcss.getId().equals("1") && "1".equals(tcss.getValue())) {
                  sysChpwdFlg = true;
               }

               if (tcss.getId().equals("2")) {
                  pwdLevel = tcss.getValue();
               }
            }
         }

         if (StringUtil.isBlank(loginUser.getTsysUser().getChpwdflg()) && sysChpwdFlg) {
            model.addAttribute("chpwdflg", "1");
         }

         model.addAttribute("pwdLevel", pwdLevel);
      }

      return "core/modifypassword/modifypassword";
   }
}
