Esempio n. 1
0
  @Log(message = "{0}用户{1}")
  @RequiresPermissions("User:reset")
  @RequestMapping(value = "/reset/{type}/{userId}", method = RequestMethod.POST)
  public @ResponseBody String reset(@PathVariable String type, @PathVariable Long userId) {
    User user = userService.get(userId);
    AjaxObject ajaxObject = new AjaxObject();
    ajaxObject.setCallbackType("");

    if (type.equals("password")) {
      user.setPlainPassword("123456");

      ajaxObject.setMessage("重置密码成功,默认为123456!");
    } else if (type.equals("status")) {
      if (user.getStatus().equals("enabled")) {
        user.setStatus("disabled");
      } else {
        user.setStatus("enabled");
      }

      ajaxObject.setMessage("更新状态成功,当前为" + (user.getStatus().equals("enabled") ? "可用" : "不可用"));
    }

    userService.update(user);

    LogUitl.putArgs(
        LogMessageObject.newWrite()
            .setObjects(new Object[] {user.getUsername(), ajaxObject.getMessage()}));
    return ajaxObject.toString();
  }
Esempio n. 2
0
  @Log(message = "修改了{0}用户的信息。")
  @RequiresPermissions("User:edit")
  @RequestMapping(value = "/update", method = RequestMethod.POST)
  public @ResponseBody String update(@ModelAttribute("preloadUser") User user) {
    BeanValidators.validateWithException(validator, user);
    userService.update(user);

    LogUitl.putArgs(LogMessageObject.newWrite().setObjects(new Object[] {user.getUsername()}));
    return AjaxObject.newOk("修改用户成功!").toString();
  }
Esempio n. 3
0
  @Log(message = "向{0}用户分配了{1}的角色。")
  @RequiresPermissions("User:assign")
  @RequestMapping(
      value = "/create/userRole",
      method = {RequestMethod.POST})
  public @ResponseBody void assignRole(UserRole userRole) {
    userRoleService.save(userRole);

    User user = userService.get(userRole.getUser().getId());
    Role role = roleService.get(userRole.getRole().getId());
    LogUitl.putArgs(
        LogMessageObject.newWrite().setObjects(new Object[] {user.getUsername(), role.getName()}));
  }
Esempio n. 4
0
  @Log(message = "撤销了{0}用户的{1}角色。")
  @RequiresPermissions("User:assign")
  @RequestMapping(
      value = "/delete/userRole/{userRoleId}",
      method = {RequestMethod.POST})
  public @ResponseBody void deleteUserRole(@PathVariable Long userRoleId) {
    UserRole userRole = userRoleService.get(userRoleId);
    LogUitl.putArgs(
        LogMessageObject.newWrite()
            .setObjects(
                new Object[] {userRole.getUser().getUsername(), userRole.getRole().getName()}));

    userRoleService.delete(userRoleId);
  }
Esempio n. 5
0
  @Log(message = "删除了{0}用户。")
  @RequiresPermissions("User:delete")
  @RequestMapping(value = "/delete/{id}", method = RequestMethod.POST)
  public @ResponseBody String delete(@PathVariable Long id) {
    User user = null;
    try {
      user = userService.get(id);
      userService.delete(user.getId());
    } catch (ServiceException e) {
      return AjaxObject.newError(e.getMessage()).setCallbackType("").toString();
    }

    LogUitl.putArgs(LogMessageObject.newWrite().setObjects(new Object[] {user.getUsername()}));
    return AjaxObject.newOk("删除用户成功!").setCallbackType("").toString();
  }
Esempio n. 6
0
  @Log(message = "添加了{0}用户。")
  @RequiresPermissions("User:save")
  @RequestMapping(value = "/create", method = RequestMethod.POST)
  public @ResponseBody String create(User user) {
    BeanValidators.validateWithException(validator, user);

    user.setCreateTime(new Date());
    try {
      userService.save(user);
    } catch (ExistedException e) {
      return AjaxObject.newError(e.getMessage()).setCallbackType("").toString();
    }

    LogUitl.putArgs(LogMessageObject.newWrite().setObjects(new Object[] {user.getUsername()}));
    return AjaxObject.newOk("添加用户成功!").toString();
  }
Esempio n. 7
0
  @Log(message = "删除了{0}用户。")
  @RequiresPermissions("User:delete")
  @RequestMapping(value = "/delete", method = RequestMethod.POST)
  public @ResponseBody String deleteMany(Long[] ids) {
    String[] usernames = new String[ids.length];
    try {
      for (int i = 0; i < ids.length; i++) {
        User user = userService.get(ids[i]);
        userService.delete(user.getId());

        usernames[i] = user.getUsername();
      }
    } catch (ServiceException e) {
      return AjaxObject.newError(e.getMessage()).setCallbackType("").toString();
    }

    LogUitl.putArgs(
        LogMessageObject.newWrite().setObjects(new Object[] {Arrays.toString(usernames)}));
    return AjaxObject.newOk("删除用户成功!").setCallbackType("").toString();
  }