예제 #1
0
  /** 设置用户组织机构. */
  @RequestMapping(value = {"updateUserOrgan"})
  @ResponseBody
  public Result updateUserOrgan(
      @ModelAttribute("model") User user,
      @RequestParam(value = "organIds", required = false) List<Long> organIds,
      String defaultOrganId)
      throws Exception {
    Result result = null;
    // 绑定组织机构
    user.setOrgans(null);
    List<Organ> organs = Lists.newArrayList();
    if (Collections3.isNotEmpty(organIds)) {
      for (Long organId : organIds) {
        Organ organ = organManager.loadById(organId);
        organs.add(organ);
      }
    }

    user.setOrgans(organs);

    // 绑定默认组织机构
    user.setDefaultOrgan(null);
    Organ defaultOrgan = null;
    if (defaultOrganId != null) {
      defaultOrgan = organManager.loadById(user.getDefaultOrganId());
    }
    user.setDefaultOrgan(defaultOrgan);

    userManager.saveEntity(user);
    result = Result.successResult();
    return result;
  }
예제 #2
0
 /** 设置组织机构页面. */
 @RequestMapping(value = {"organ"})
 public String organ(@ModelAttribute("model") User user, Model model) throws Exception {
   // 设置默认组织机构初始值
   List<Combobox> defaultOrganCombobox = Lists.newArrayList();
   if (user.getId() != null) {
     List<Organ> organs = user.getOrgans();
     Combobox combobox;
     if (!Collections3.isEmpty(organs)) {
       for (Organ organ : organs) {
         combobox = new Combobox(organ.getId().toString(), organ.getName());
         defaultOrganCombobox.add(combobox);
       }
     }
   }
   String defaultOrganComboboxData = JsonMapper.nonDefaultMapper().toJson(defaultOrganCombobox);
   logger.debug(defaultOrganComboboxData);
   model.addAttribute("defaultOrganComboboxData", defaultOrganComboboxData);
   return "modules/sys/user-organ";
 }
예제 #3
0
 /**
  * 修改用户密码. <br>
  * 参数upateOperate 需要密码"1" 不需要密码"0".
  */
 @RequestMapping(value = {"updateUserPassword"})
 @ResponseBody
 public Result updateUserPassword(
     @ModelAttribute("model") User user, String upateOperate, String newPassword)
     throws Exception {
   Result result;
   if (!StringUtils.isEmpty(upateOperate)) {
     User u = userManager.loadById(user.getId());
     if (u != null) {
       boolean isCheck = true;
       // 需要输入原始密码
       if (AppConstants.USER_UPDATE_PASSWORD_YES.equals(upateOperate)) {
         String originalPassword = u.getPassword(); // 数据库存储的原始密码
         String pagePassword = u.getPassword(); // 页面输入的原始密码(未加密)
         if (!originalPassword.equals(Encrypt.e(pagePassword))) {
           isCheck = false;
         }
       }
       // 不需要输入原始密码
       if (AppConstants.USER_UPDATE_PASSWORD_NO.equals(upateOperate)) {
         isCheck = true;
       }
       if (isCheck) {
         u.setPassword(Encrypt.e(newPassword));
         userManager.saveEntity(u);
         result = Result.successResult();
       } else {
         result = new Result(Result.WARN, "原始密码输入错误.", "password");
       }
     } else {
       result = new Result(Result.ERROR, "修改的用户不存在或已被删除.", null);
     }
   } else {
     result = Result.errorResult();
     logger.warn("请求参数错误,未设置参数[upateOperate].");
   }
   logger.debug(result.toString());
   return result;
 }
예제 #4
0
  /** 修改用户资源. */
  @RequestMapping(value = {"updateUserResource"})
  @ResponseBody
  public Result updateUserResource(
      @ModelAttribute("model") User user,
      @RequestParam(value = "resourceIds", required = false) List<Long> resourceIds)
      throws Exception {
    Result result = null;
    List<Resource> rs = Lists.newArrayList();
    if (Collections3.isNotEmpty(resourceIds)) {
      for (Long id : resourceIds) {
        Resource resource = resourceManager.loadById(id);
        rs.add(resource);
      }
    }

    user.setResources(rs);
    userManager.saveEntity(user);
    result = Result.successResult();
    return result;
  }
예제 #5
0
  /** 保存. */
  @RequestMapping(value = {"save"})
  @ResponseBody
  public Result save(@ModelAttribute("model") User user) {
    Result result = null;
    // 名称重复校验
    User nameCheckUser = userManager.getUserByLoginName(user.getLoginName());
    if (nameCheckUser != null && !nameCheckUser.getId().equals(user.getId())) {
      result = new Result(Result.WARN, "登录名为[" + user.getLoginName() + "]已存在,请修正!", "loginName");
      logger.debug(result.toString());
      return result;
    }

    if (user.getId() == null) { // 新增
      user.setPassword(Encrypt.e(user.getPassword()));
    } else { // 修改
      User superUser = userManager.getSuperUser();
      User sessionUser = userManager.getCurrentUser();
      if (!sessionUser.getId().equals(superUser.getId())) {
        result = new Result(Result.ERROR, "超级用户信息仅允许自己修改!", null);
        logger.debug(result.toString());
        return result;
      }
    }
    userManager.saveEntity(user);
    result = Result.successResult();
    logger.debug(result.toString());
    return result;
  }