コード例 #1
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;
  }
コード例 #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;
 }