diff --git a/common/common-framework/src/main/java/cn/iocoder/common/framework/util/DigestUtils.java b/common/common-framework/src/main/java/cn/iocoder/common/framework/util/DigestUtils.java
index 63ad9ea00..9180b1ab6 100644
--- a/common/common-framework/src/main/java/cn/iocoder/common/framework/util/DigestUtils.java
+++ b/common/common-framework/src/main/java/cn/iocoder/common/framework/util/DigestUtils.java
@@ -7,6 +7,10 @@ import cn.hutool.crypto.digest.BCrypt;
*/
public class DigestUtils {
+ public static String genBcryptSalt() {
+ return BCrypt.gensalt();
+ }
+
public static String bcrypt(String key, String salt) {
return BCrypt.hashpw(key, salt);
}
diff --git a/common/common-framework/src/main/java/cn/iocoder/common/framework/util/ServiceExceptionUtil.java b/common/common-framework/src/main/java/cn/iocoder/common/framework/util/ServiceExceptionUtil.java
index cc84a8eeb..7fc1fa1c2 100644
--- a/common/common-framework/src/main/java/cn/iocoder/common/framework/util/ServiceExceptionUtil.java
+++ b/common/common-framework/src/main/java/cn/iocoder/common/framework/util/ServiceExceptionUtil.java
@@ -85,7 +85,7 @@ public class ServiceExceptionUtil {
* @return 异常
*/
public static ServiceException exception(Integer code) {
- return exception(code, messages.get(code));
+ return exception0(code, messages.get(code));
}
/**
diff --git a/user-service-project/user-service-app/pom.xml b/user-service-project/user-service-app/pom.xml
index 773f80004..52d13a255 100644
--- a/user-service-project/user-service-app/pom.xml
+++ b/user-service-project/user-service-app/pom.xml
@@ -11,8 +11,6 @@
user-service-app
-
-
com.alibaba.cloud
diff --git a/user-service-project/user-service-app/src/main/java/cn/iocoder/mall/userservice/config/ServiceExceptionConfiguration.java b/user-service-project/user-service-app/src/main/java/cn/iocoder/mall/userservice/config/ServiceExceptionConfiguration.java
new file mode 100644
index 000000000..566dbf356
--- /dev/null
+++ b/user-service-project/user-service-app/src/main/java/cn/iocoder/mall/userservice/config/ServiceExceptionConfiguration.java
@@ -0,0 +1,20 @@
+package cn.iocoder.mall.userservice.config;
+
+import cn.iocoder.common.framework.util.ServiceExceptionUtil;
+import cn.iocoder.mall.userservice.enums.UserErrorCodeEnum;
+import org.springframework.boot.context.event.ApplicationReadyEvent;
+import org.springframework.context.annotation.Configuration;
+import org.springframework.context.event.EventListener;
+
+import java.util.Arrays;
+
+@Configuration
+public class ServiceExceptionConfiguration {
+
+ @EventListener(ApplicationReadyEvent.class)
+ public void initMessages() {
+ Arrays.stream(UserErrorCodeEnum.values()).forEach(
+ item -> ServiceExceptionUtil.put(item.getCode(), item.getMessage()));
+ }
+
+}
diff --git a/user-service-project/user-service-app/src/main/java/cn/iocoder/mall/userservice/convert/user/UserConvert.java b/user-service-project/user-service-app/src/main/java/cn/iocoder/mall/userservice/convert/user/UserConvert.java
index 7b5d028b5..da889d885 100644
--- a/user-service-project/user-service-app/src/main/java/cn/iocoder/mall/userservice/convert/user/UserConvert.java
+++ b/user-service-project/user-service-app/src/main/java/cn/iocoder/mall/userservice/convert/user/UserConvert.java
@@ -1,5 +1,6 @@
package cn.iocoder.mall.userservice.convert.user;
+import cn.iocoder.mall.userservice.rpc.user.dto.UserCreateDTO;
import cn.iocoder.mall.userservice.service.user.bo.UserBO;
import cn.iocoder.mall.userservice.dal.mysql.dataobject.user.UserDO;
import cn.iocoder.mall.userservice.rpc.user.vo.UserVO;
@@ -17,7 +18,9 @@ public interface UserConvert {
UserBO convert(UserDO bean);
- @Mapping(source = "ip", target = "createIp")
UserDO convert(UserCreateBO bean);
+ @Mapping(source = "ip", target = "createIp")
+ UserCreateBO convert(UserCreateDTO createDTO);
+
}
diff --git a/user-service-project/user-service-app/src/main/java/cn/iocoder/mall/userservice/dal/mysql/dataobject/sms/UserSmsCodeDO.java b/user-service-project/user-service-app/src/main/java/cn/iocoder/mall/userservice/dal/mysql/dataobject/sms/UserSmsCodeDO.java
index 1ad03ecbf..d0aaa141e 100644
--- a/user-service-project/user-service-app/src/main/java/cn/iocoder/mall/userservice/dal/mysql/dataobject/sms/UserSmsCodeDO.java
+++ b/user-service-project/user-service-app/src/main/java/cn/iocoder/mall/userservice/dal/mysql/dataobject/sms/UserSmsCodeDO.java
@@ -11,6 +11,8 @@ import java.util.Date;
/**
* 手机验证码 DO
+ *
+ * idx_mobile 索引:基于 {@link #mobile} 字段
*/
@TableName("user_sms_code")
@Data
diff --git a/user-service-project/user-service-app/src/main/java/cn/iocoder/mall/userservice/dal/mysql/dataobject/user/UserDO.java b/user-service-project/user-service-app/src/main/java/cn/iocoder/mall/userservice/dal/mysql/dataobject/user/UserDO.java
index 9156de8f9..13ed10413 100644
--- a/user-service-project/user-service-app/src/main/java/cn/iocoder/mall/userservice/dal/mysql/dataobject/user/UserDO.java
+++ b/user-service-project/user-service-app/src/main/java/cn/iocoder/mall/userservice/dal/mysql/dataobject/user/UserDO.java
@@ -1,7 +1,7 @@
package cn.iocoder.mall.userservice.dal.mysql.dataobject.user;
import cn.iocoder.common.framework.constant.CommonStatusEnum;
-import cn.iocoder.mall.mybatis.dataobject.DeletableDO;
+import cn.iocoder.mall.mybatis.dataobject.BaseDO;
import com.baomidou.mybatisplus.annotation.TableName;
import lombok.Data;
import lombok.EqualsAndHashCode;
@@ -9,12 +9,14 @@ import lombok.experimental.Accessors;
/**
* 用户实体
+ *
+ * uk_mobile 索引:基于 {@link #mobile} 字段
*/
@TableName(value = "users")
@Data
@EqualsAndHashCode(callSuper = true)
@Accessors(chain = true)
-public class UserDO extends DeletableDO {
+public class UserDO extends BaseDO {
/**
* 用户编号
diff --git a/user-service-project/user-service-app/src/main/java/cn/iocoder/mall/userservice/manager/user/UserManager.java b/user-service-project/user-service-app/src/main/java/cn/iocoder/mall/userservice/manager/user/UserManager.java
index 671bbb862..9f0636a6a 100644
--- a/user-service-project/user-service-app/src/main/java/cn/iocoder/mall/userservice/manager/user/UserManager.java
+++ b/user-service-project/user-service-app/src/main/java/cn/iocoder/mall/userservice/manager/user/UserManager.java
@@ -1,10 +1,10 @@
package cn.iocoder.mall.userservice.manager.user;
-import cn.iocoder.mall.userservice.rpc.user.dto.UserCreateDTO;
-import cn.iocoder.mall.userservice.service.user.bo.UserBO;
-import cn.iocoder.mall.userservice.service.user.UserService;
import cn.iocoder.mall.userservice.convert.user.UserConvert;
+import cn.iocoder.mall.userservice.rpc.user.dto.UserCreateDTO;
import cn.iocoder.mall.userservice.rpc.user.vo.UserVO;
+import cn.iocoder.mall.userservice.service.user.UserService;
+import cn.iocoder.mall.userservice.service.user.bo.UserBO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
@@ -26,8 +26,8 @@ public class UserManager {
return UserConvert.INSTANCE.convert(userBO);
}
// 用户不存在,则进行创建
-
- return null;
+ userBO = userService.createUser(UserConvert.INSTANCE.convert(createDTO));
+ return UserConvert.INSTANCE.convert(userBO);
}
}
diff --git a/user-service-project/user-service-app/src/main/java/cn/iocoder/mall/userservice/service/user/UserService.java b/user-service-project/user-service-app/src/main/java/cn/iocoder/mall/userservice/service/user/UserService.java
index f7939a92a..f3b36c02f 100644
--- a/user-service-project/user-service-app/src/main/java/cn/iocoder/mall/userservice/service/user/UserService.java
+++ b/user-service-project/user-service-app/src/main/java/cn/iocoder/mall/userservice/service/user/UserService.java
@@ -1,5 +1,6 @@
package cn.iocoder.mall.userservice.service.user;
+import cn.iocoder.common.framework.constant.CommonStatusEnum;
import cn.iocoder.common.framework.util.DigestUtils;
import cn.iocoder.common.framework.util.StringUtils;
import cn.iocoder.mall.userservice.convert.user.UserConvert;
@@ -27,7 +28,8 @@ public class UserService {
}
public UserBO createUser(UserCreateBO createBO) {
- UserDO userDO = UserConvert.INSTANCE.convert(createBO);
+ UserDO userDO = UserConvert.INSTANCE.convert(createBO)
+ .setStatus(CommonStatusEnum.ENABLE.getValue());
// 加密密码
String passwordSalt = genPasswordSalt();
String password = createBO.getPassword();
@@ -42,7 +44,7 @@ public class UserService {
}
private String genPasswordSalt() {
- return StringUtils.uuid(true);
+ return DigestUtils.genBcryptSalt();
}
private String genPassword() {
diff --git a/user-service-project/user-service-app/src/main/java/cn/iocoder/mall/userservice/service/user/bo/UserCreateBO.java b/user-service-project/user-service-app/src/main/java/cn/iocoder/mall/userservice/service/user/bo/UserCreateBO.java
index fca2d118e..2ad73a31b 100644
--- a/user-service-project/user-service-app/src/main/java/cn/iocoder/mall/userservice/service/user/bo/UserCreateBO.java
+++ b/user-service-project/user-service-app/src/main/java/cn/iocoder/mall/userservice/service/user/bo/UserCreateBO.java
@@ -34,6 +34,6 @@ public class UserCreateBO {
/**
* IP 地址
*/
- private String ip;
+ private String createIp;
}
diff --git a/user-service-project/user-service-app/src/main/resources/application-dev.yaml b/user-service-project/user-service-app/src/main/resources/application-dev.yaml
index cfae12b0d..0b83c020b 100644
--- a/user-service-project/user-service-app/src/main/resources/application-dev.yaml
+++ b/user-service-project/user-service-app/src/main/resources/application-dev.yaml
@@ -1,7 +1,7 @@
spring:
# 数据源配置项
datasource:
- url: jdbc:mysql://400-infra.server.iocoder.cn:3306/mall_system?useSSL=false&useUnicode=true&characterEncoding=UTF-8
+ url: jdbc:mysql://400-infra.server.iocoder.cn:3306/mall_user?useSSL=false&useUnicode=true&characterEncoding=UTF-8
driver-class-name: com.mysql.jdbc.Driver
username: root
password: 3WLiVUBEwTbvAfsh
diff --git a/user-service-project/user-service-app/src/main/resources/application-local.yaml b/user-service-project/user-service-app/src/main/resources/application-local.yaml
index bf97cae95..c64c2a1c0 100644
--- a/user-service-project/user-service-app/src/main/resources/application-local.yaml
+++ b/user-service-project/user-service-app/src/main/resources/application-local.yaml
@@ -1,7 +1,7 @@
spring:
# 数据源配置项
datasource:
- url: jdbc:mysql://400-infra.server.iocoder.cn:3306/mall_system?useSSL=false&useUnicode=true&characterEncoding=UTF-8
+ url: jdbc:mysql://400-infra.server.iocoder.cn:3306/mall_user?useSSL=false&useUnicode=true&characterEncoding=UTF-8
driver-class-name: com.mysql.jdbc.Driver
username: root
password: 3WLiVUBEwTbvAfsh
diff --git a/user-web-app/src/main/java/cn/iocoder/mall/userweb/controller/passport/UserPassportController.java b/user-web-app/src/main/java/cn/iocoder/mall/userweb/controller/passport/UserPassportController.java
index 8c888f71f..cf27edc8b 100644
--- a/user-web-app/src/main/java/cn/iocoder/mall/userweb/controller/passport/UserPassportController.java
+++ b/user-web-app/src/main/java/cn/iocoder/mall/userweb/controller/passport/UserPassportController.java
@@ -14,6 +14,8 @@ import org.springframework.web.bind.annotation.RestController;
import javax.servlet.http.HttpServletRequest;
+import static cn.iocoder.common.framework.vo.CommonResult.success;
+
@RestController
@RequestMapping("/passport")
public class UserPassportController {
@@ -26,17 +28,17 @@ public class UserPassportController {
// @RequiresNone TODO 晚点加上
public CommonResult loginBySms(UserPassportLoginBySmsDTO loginBySmsDTO,
HttpServletRequest request) {
- return CommonResult.success(userPassportManager.loginBySms(loginBySmsDTO, HttpUtil.getIp(request)));
+ return success(userPassportManager.loginBySms(loginBySmsDTO, HttpUtil.getIp(request)));
}
- @PostMapping("/send_sms_code")
+ @PostMapping("/send_sms_code")
@ApiOperation("发送手机验证码")
// @RequiresNone TODO 晚点加上
public CommonResult sendSmsCode(UserPassportSendSmsCodeDTO sendSmsCodeDTO,
HttpServletRequest request) {
userPassportManager.sendSmsCode(sendSmsCodeDTO, HttpUtil.getIp(request));
// 返回成功
- return CommonResult.success(true);
+ return success(true);
}
}
diff --git a/user-web-app/src/main/resources/application.yml b/user-web-app/src/main/resources/application.yml
index 5022b4b3f..2ea3d1561 100644
--- a/user-web-app/src/main/resources/application.yml
+++ b/user-web-app/src/main/resources/application.yml
@@ -19,6 +19,7 @@ dubbo:
subscribed-services: 'user-service' # 设置订阅的应用列表,默认为 * 订阅所有应用
# Dubbo 服务消费者的配置
consumer:
+ timeout: 10000
UserSmsCodeRpc:
version: 1.0.0
UserRpc: