コード例 #1
0
  @Override
  public void editUserBasic(
      Long userId,
      String nickName,
      String userName,
      Integer sex,
      int birthdayYear,
      int birthdayMonth,
      int birthdayDay,
      String summary,
      String qqId,
      String wangwangId) {
    // 数据不能为空
    if (userId <= 0 || nickName.trim().equals("") || userName.trim().equals("")) {
      throw new IllegalArgumentException();
    }
    // 验证昵称格式
    if (!StringUtil.match(nickName, "^.{1,12}$")) {
      throw new ServiceException(ErrService.UserS.ACC_106, "昵称:“" + nickName + "”格式错误。");
    }
    // 验证生日格式
    Calendar calendar = Calendar.getInstance();
    try {
      calendar.set(birthdayYear, birthdayMonth - 1, birthdayDay);
    } catch (Exception e) {
      throw new ServiceException(
          ErrService.UserS.ACC_104,
          "生日:“" + birthdayYear + "年" + birthdayMonth + "月" + birthdayDay + "日”,格式错误。",
          e);
    }
    // 验证昵称
    User user = userDao.queryById(userId);
    if (!user.getNickName().equals(nickName)) {
      if (this.verifyNickRep(nickName)) {
        throw new ServiceException(ErrService.UserS.ACC_102, "昵称:“" + nickName + "”已经被使用。");
      }
    }

    JSONObject eaddress = new JSONObject();
    if (!StringUtil.isEmptyOrNull(qqId)) {
      eaddress.put("qqId", qqId);
    }
    if (!StringUtil.isEmptyOrNull(wangwangId)) {
      eaddress.put("wangwangId", wangwangId);
    }

    userDao.update(
        userId,
        nickName,
        userName,
        sex,
        birthdayYear,
        birthdayMonth,
        birthdayDay,
        eaddress.toString(),
        summary);
  }
コード例 #2
0
  @Override
  public User register(String account, String password, String nick) throws ServiceException {
    if (StringUtil.isEmptyOrNull(password) || StringUtil.isEmptyOrNull(nick)) {
      throw new IllegalArgumentException();
    }

    if (!StringUtil.isEmptyOrNull(account)) {
      // 验证账号格式
      if (!StringUtil.match(account, "^\\w{5,50}$")) {
        throw new ServiceException(ErrService.UserS.ACC_105, "账号:“" + account + "”格式错误。");
      }
      account = account.toLowerCase();
      // 验证账号是否重复
      if (this.verifyAccountRep(account)) {
        throw new ServiceException(ErrService.UserS.ACC_101, "账号:“" + account + "”已经被使用。");
      }
    }

    // 验证昵称格式
    if (!StringUtil.match(nick, "^.{1,12}$")) {
      throw new ServiceException(ErrService.UserS.ACC_106, "昵称:“" + nick + "”格式错误。");
    }
    // 验证密码格式
    if (!StringUtil.match(password, "^.{6,20}$")) {
      throw new ServiceException(ErrService.UserS.ACC_107, "密码:“" + password + "”格式错误。");
    }
    // 验证昵称是否重复
    if (this.verifyNickRep(nick)) {
      throw new ServiceException(ErrService.UserS.ACC_102, "昵称:“" + nick + "”已经被使用。");
    }

    User user = new User();
    user.setAccount(account);
    // 加密处理
    password = PasswordMD.md5(password);
    user.setPassword(password);
    user.setNickName(nick);
    user.setAddTime(new Date());
    return this.addUser(user);
  }
コード例 #3
0
  @Override
  public void editUserPasswore(Long userId, String oldPsw, String newPsw) {
    // 验证密码格式
    if (!StringUtil.match(newPsw, "^.{6,20}$")) {
      throw new ServiceException(ErrService.UserS.ACC_107, "密码:“" + newPsw + "”格式错误。");
    }

    // 密码MD5加密
    oldPsw = PasswordMD.md5(oldPsw);
    User user = userDao.queryById(userId);
    if (!user.getPassword().equals(oldPsw)) {
      throw new ServiceException(ErrService.UserS.ACC_103, "用户:“" + userId + "”原始密码错误。");
    }

    newPsw = PasswordMD.md5(newPsw);
    userDao.updatePsw(userId, newPsw);
  }