@Override public UserResult register(UserEntity user) { UserResult ur = new UserResult(); try { if (user != null) { String loginName = user.getLoginname(); // 检查登录名是否重复 boolean res = chekLoginName(loginName); if (!res) { User usr = new User(); String pwd = ""; if (user.getPwd() != null) { pwd = MD5Util.md5(user.getPwd()); usr.setPlainPassword(user.getPwd()); } usr.setCreateDate(new Date()); usr.setLoginname(loginName); usr.setPwd(pwd); usr.setName(user.getName()); usr.setPhone(user.getPhone()); usr.setStatus(3); usr.setLat(user.getLat()); usr.setLon(user.getLon()); usr.setParseaddress(user.getParseaddress()); usr.setUsertype(user.getUsertype()); this.saveOrUpdate(usr); User userinfo = userService.findByLoginName(loginName); if (userinfo != null) { user.setId(userinfo.getId().toString()); } user.setPwd(""); user.setState(Constants.DEFAULT_STATE); user.setCity(Constants.DEFAULT_CITY); user.setSex(Constants.DEFAULT_SEX_VALUE); ur.setUser(user); ur.setErrorCode(0); ur.setErrorMessage(""); } else { ValidationError ve = ValidationError.LOGINNAMEREPEAT; int errorCode = ve.getErrorCode(); String message = Utils.getErrorMessage(ve); ur.setErrorCode(errorCode); ur.setErrorMessage(message); } } } catch (Exception ex) { ValidationError er = ValidationError.SYSTEM_ERROR; int errorCode = er.getErrorCode(); ur.setErrorCode(errorCode); ur.setErrorMessage("系统错误"); logger.error(ex.getMessage()); } return ur; }
/** 登录服务 return UserResult */ @Override public UserResult login(UserEntity user) { UserResult ur = new UserResult(); try { String username = user.getLoginname(); String password = MD5Util.md5(user.getPwd()); User u = null; u = userService.findByLoginNameAndPwd(username, password); if (u == null) { ValidationError er = ValidationError.LOGINFAILE; int errorCode = er.getErrorCode(); String errorMessage = er.getErrorMessage(); ur.setErrorCode(errorCode); ur.setErrorMessage(errorMessage); } else { if (u.getUsertype() == 2) { BusinessUserDetail businessUserdetail = businessUserDetailService.findByUserId(u.getId()); BusinessUserEntity businessUserVO = ConvertHelper.toBusinessUserEntity(u, businessUserdetail); ur.setBusinessUser(businessUserVO); } else { UserDetail userdetail = userDetailService.findByUserId(u.getId()); UserEntity userVO = ConvertHelper.toUserEntity(u, userdetail); ur.setUser(userVO); } ur.setErrorCode(0); ur.setErrorMessage(""); } } catch (Exception ex) { ValidationError er = ValidationError.SYSTEM_ERROR; ur.setErrorCode(er.getErrorCode()); ur.setErrorMessage("系统错误"); logger.error(ex.getMessage()); } return ur; }