Пример #1
0
  /**
   * 修改密码Action
   *
   * @return
   */
  public String changePassword() {
    log.debug("===> invoke changePassword Action");
    // 判断用户名是否为空
    if (this.user.getUsername() == null || "".equals(this.user.getUsername())) {
      msg = "用户名不能为空!";
      ActionContext.getContext().getSession().put("msg", msg);
      return INPUT;
    }

    // 判断密码是否为空
    if (this.user.getPassword() == null || "".equals(this.user.getPassword())) {
      msg = "密码不能为空!";
      ActionContext.getContext().getSession().put("msg", msg);
      return INPUT;
    }

    // 判断确认密码是否为空
    if (this.repassword == null || "".equals(this.repassword)) {
      msg = "请确认密码!";
      ActionContext.getContext().getSession().put("msg", msg);
      return INPUT;
    }

    // 判断两次输入密码是否一致
    if (!this.repassword.equals(this.user.getPassword())) {
      msg = "两次输入密码不一致!";
      ActionContext.getContext().getSession().put("msg", msg);
      return INPUT;
    }

    this.user = userService.findUserByName(user.getUsername()); // 通过用户名查找到用户信息
    if (user != null) {
      user.setPassword(this.repassword);
      // 修改用户密码
      this.user = this.userService.changePassword(user);
      if (this.user != null) {
        msg = "修改密码成功";
        ServletActionContext.getRequest().getSession().setAttribute("msg", msg);
        ServletActionContext.getRequest().getSession().setAttribute("user", user);
        return SUCCESS;
      } else {
        msg = "修改密码失败";
        ServletActionContext.getRequest().getSession().setAttribute("msg", msg);
        return INPUT;
      }
    } else {
      return INPUT;
    }
  }
Пример #2
0
 private boolean checkUser() {
   boolean result = true;
   if (user.getUsername() == null || "".equals(user.getUsername().trim())) {
     msg = "用户名不能为空!";
     result = false;
   } else if (user.getPassword() == null || "".equals(user.getPassword().trim())) {
     msg = "密码不能为空!";
     result = false;
   } else if (this.repassword == null || "".equals(this.repassword)) {
     msg = "请确认密码!";
     result = false;
   } else if (this.repassword.trim().equals(user.getPassword().trim())) {
     msg = "两次输入密码不一致";
     result = false;
   }
   return result;
 }
Пример #3
0
  /**
   * 用户管理Action
   *
   * @return
   */
  @SuppressWarnings({"unchecked", "rawtypes"})
  public String allUser() {
    List<User> allUsers = userService.search(this.searchUsername, this.searchEnabled);
    Map session = ActionContext.getContext().getSession();
    this.showUsers = (List<User>) session.get("showUsers"); // 从session中取出当前正在显示的用户信息
    if (showUsers == null) { // 当显示用户信息列表为空时,新建对象
      showUsers = new ArrayList<User>();
    } else { // 当当前显示用户信息列表不为空时,清空用户信息列表,以便放入待显示用户信息,避免冲突
      showUsers.clear();
    }

    if (allUsers == null || allUsers.size() == 0) { // 当所有用户信息为空时,设置页脚导航处的值
      this.totalPage = 1;
      this.currentPage = 1;
    } else {
      int userSize = allUsers.size();
      this.totalPage = userSize % pageSize == 0 ? userSize / pageSize : userSize / pageSize + 1;
      int start = (currentPage - 1) * pageSize;
      int end = start + pageSize;
      for (int i = start; i < end; i++) {
        if (i >= userSize) {
          break;
        } else {
          User user = allUsers.get(i);
          Set<UserRole> userRoles =
              new HashSet<UserRole>(userService.findInStatusUserRoleById(user.getId()));
          user.setUserRoles(userRoles);
          showUsers.add(user);
        }
      }
    }
    session.put("showUsers", showUsers);
    this.msg = (String) session.get("msg");
    Integer userAction = (Integer) session.get("userAction");
    if (userAction == null || userAction == 0) {
      session.put("msg", "");
    } else {
      session.remove("userAction");
    }

    return SUCCESS;
  }
Пример #4
0
  public String update() {
    ActionContext.getContext().getSession().remove("updateUser");
    if (!checkUser()) {
      this.user = userService.findUserByName(user.getUsername()); // 通过用户名查找用户
      if (user != null) {
        user.setEnabled(this.enabled); // 设置查找出来用户的激活性
        user.setDescription(this.description); // 设置查找出来的用户的描述信息
        user.setPassword(this.repassword); // 设置查找出来的用户的密码

        user = userService.changePassword(user); // 修改用户信息
        if (user != null) {
          msg = "修改成功!";
        } else {
          msg = "修改失败!";
        }
      }
    }

    ActionContext.getContext().getSession().put("msg", msg);
    ActionContext.getContext().getSession().put("userAction", 2); // userAction:2 表示修改用户信息
    return SUCCESS;
  }