예제 #1
0
  // 负责菜单的加载
  @RequestMapping(value = "/menus")
  public String getMenus(HttpServletRequest request, HttpServletResponse response, Model model) {
    // 从session中获取所有的角色信息
    AdminUserDTO userDTO = (AdminUserDTO) request.getSession().getAttribute(ADMIN_USER_SESSION);
    Map<String, MenuManagerDTO> menusMap = userDTO.getMenuList();
    if (menusMap != null) {
      List<MenuManagerDTO> menus = null;

      String godPhone = request.getSession().getServletContext().getInitParameter("godPhone");
      if (userDTO.getPhone() != null && userDTO.getPhone().equals(godPhone)) {
        menus = menuManagerService.getNavMenu(); // 获取所有的菜单组或者页面菜单,
      } else {
        menus = new ArrayList<MenuManagerDTO>();
        menus.addAll(menusMap.values());
      }
      // 根据ID排序
      Collections.sort(
          menus,
          new Comparator<MenuManagerDTO>() {
            @Override
            public int compare(MenuManagerDTO menu1, MenuManagerDTO menu2) {
              return menu1.getMenuId() - menu2.getMenuId();
            }
          });

      model.addAttribute("pageMenus", menus);
    }
    return "admin/menu";
  }
예제 #2
0
 // 更改密码
 // 登陆后跳转的页面
 @RequestMapping(value = "/updatePsw")
 public String updatePsw(HttpServletRequest request, HttpServletResponse response, Model model) {
   AdminUserDTO loginUser = (AdminUserDTO) request.getSession().getAttribute(ADMIN_USER_SESSION);
   String oldPsw = request.getParameter("oldPsw");
   String newPsw = request.getParameter("newPsw");
   JsonDTO json = new JsonDTO();
   if (oldPsw != null && newPsw != null && oldPsw.length() <= 50 && newPsw.length() <= 50) {
     AdminUser adminUser = new AdminUser();
     adminUser.setAdminUserId(loginUser.getAdminUserId());
     adminUser.setPassword(PasswordUtil.MD5(oldPsw));
     loginUser = adminUserService.getUserByParam(adminUser);
     if (loginUser != null) { // 验证成功,修改密码
       adminUser.setPassword(PasswordUtil.MD5(newPsw));
       try {
         adminUserService.updateUserAndRole(adminUser, null);
         json.setStatus(1).setMessage("密码更新成功!");
       } catch (Exception e) {
         e.printStackTrace();
         json.setStatus(0).setMessage("密码更新失败!:" + e.getMessage());
       }
       model.addAttribute("json", JSONUtil.object2json(json));
       return JSON;
     }
   }
   json.setStatus(0).setMessage("密码错误!");
   model.addAttribute("json", JSONUtil.object2json(json));
   return "json";
 }