コード例 #1
0
  public JSONObject resetPwd(Map map) throws Exception {
    boolean isSuccess = true;
    String message = "";

    String userId = (String) map.get("userId");

    String email = (String) map.get("email");

    String verifyCode = (String) map.get("verifyCode");
    String verifyCodeInSession = (String) map.get("verifyCodeInSession");

    if (!verifyCode.equals(verifyCodeInSession)) {
      isSuccess = false;
      message = "验证码错误.";
    }

    List userList = null;
    if ((StringUtils.isNotEmpty(userId)) && (StringUtils.isNotEmpty(email))) {
      User paramUser = new User();
      paramUser.setUserId(userId);
      paramUser.setEmail(email);
      userList = selectByCriteria(paramUser);
    }
    if ((userList == null) || (userList.size() != 1)) {
      isSuccess = false;
      message = "用户名或邮箱错误.";
    }

    if (isSuccess) {
      User user = (User) userList.get(0);

      String newPassword = RandomStringUtils.random(6, true, true);

      String title = "密码重置";
      String content = user.getUserId() + ",您好:<br/>您的新密码是:" + newPassword;
      boolean rs = ServletHelp.sendEmail(email, title, content);
      if (rs) {
        User paramUser = new User();
        paramUser.setUserId(userId);
        paramUser.setPassword(MD5Utils.getMD5String(newPassword));
        update(paramUser);
      } else {
        isSuccess = false;
        message = "邮件发送失败.";
      }
    }

    JSONObject res = new JSONObject();
    res.put("success", Boolean.valueOf(isSuccess));
    res.put("message", message);
    return res;
  }
コード例 #2
0
  public JSONObject register(Map map) throws Exception {
    boolean isSuccess = true;
    String errorMsg = "";

    User paramUser = new User();
    BeanUtils.populate(paramUser, map);
    paramUser.setBirthday(DateUtils.formatStr2Date(paramUser.getBirthdayStr(), "yyyy-MM-dd"));
    paramUser.setStatus("1");
    if ((StringUtils.isEmpty(SessionUtils.getUserRole()))
        || ("3".equals(SessionUtils.getUserRole()))) {
      paramUser.setRole("3");
    }

    String userId = map.get("userId").toString();

    String password = map.get("password").toString();

    String repassword = map.get("repassword").toString();

    String verifyCode = map.get("verifyCode").toString();
    String verifyCodeInSession = map.get("verifyCodeInSession").toString();

    if ("1".equals(SessionUtils.getUserRole())) {
      if ((!"2".equals(paramUser.getRole())) && (!"3".equals(paramUser.getRole()))) {
        isSuccess = false;
        errorMsg = "角色设置错误.";
      }
    } else if (!"3".equals(paramUser.getRole())) {
      isSuccess = false;
      errorMsg = "角色设置错误.";
    }

    if (!password.equals(repassword)) {
      isSuccess = false;
      errorMsg = "两次输入的密码不一致.";
    }

    if (!verifyCode.equals(verifyCodeInSession)) {
      isSuccess = false;
      errorMsg = "验证码错误.";
    }

    List<User> userList = selectByCriteria(new User());
    if (userList != null) {
      for (User user : userList) {
        if (userId.equals(user.getUserId())) {
          isSuccess = false;
          errorMsg = "账号已存在.";
          break;
        }
        if (paramUser.getEmail().equals(user.getEmail())) {
          isSuccess = false;
          errorMsg = "邮箱已被使用.";
          break;
        }
      }
    }

    if (isSuccess) {
      insert(paramUser);

      Map userMetaMap = new HashMap();
      userMetaMap.put("theme", (String) map.get("theme"));
      userMetaMap.put("homePage", (String) map.get("homePage"));
      userMetaMap.put("showTodo", (String) map.get("showTodo"));
      userMetaMap.put("showNote", (String) map.get("showNote"));
      userMetaMap.put("showPicture", (String) map.get("showPicture"));
      userMetaMap.put("showAccount", (String) map.get("showAccount"));
      userMetaMap.put("showFeed", (String) map.get("showFeed"));
      userMetaMap.put("showDocument", (String) map.get("showDocument"));
      if ("3".equals(paramUser.getRole())) userMetaMap.put("showSystem", "off");
      else {
        userMetaMap.put("showSystem", "on");
      }
      this.userMetaService.insert(userId, userMetaMap);

      String uploadFilePath =
          ServletHelp.getRealPath(
              (HttpServletRequest) map.get("request"),
              MessageUtils.setParamMessage("/websrc/file/{0}/document", new String[] {userId}));
      FileUtils.createDirs(uploadFilePath);

      String uploadPicturePath =
          ServletHelp.getRealPath(
              (HttpServletRequest) map.get("request"),
              MessageUtils.setParamMessage("/websrc/file/{0}/picture", new String[] {userId}));
      FileUtils.createDirs(uploadPicturePath);

      FileUtils.createDirs(uploadPicturePath + "/" + "thumbnail");

      String feedFilePath =
          ServletHelp.getRealPath(
              (HttpServletRequest) map.get("request"),
              MessageUtils.setParamMessage("/websrc/file/{0}/feed", new String[] {userId}));
      FileUtils.createDirs(feedFilePath);
    }

    JSONObject res = new JSONObject();
    res.put("success", Boolean.valueOf(isSuccess));
    res.put("message", errorMsg);
    return res;
  }