@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); }
@Override public void editUserEmail(Long userId, String email) { if (email == null || email.equals("")) { throw new ServiceException(ErrService.UserS.ACC_102, "电子邮箱格式错误。"); } User u = userDao.queryByEnEmail(email); if (u != null) { throw new ServiceException(ErrService.UserS.ACC_102, "该电子邮箱已经被激活。"); } User user = userDao.queryById(userId); if (!email.equals(user.getEmail())) { userDao.updateEmail(userId, email); } }
@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); }
@Override public User getUserById(Long userId) { return userDao.queryById(userId); }