完成快速登录功能,以及自测。
This commit is contained in:
parent
3d6bd5e4ee
commit
3cbd872497
@ -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);
|
||||
}
|
||||
|
@ -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));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -11,8 +11,6 @@
|
||||
|
||||
<artifactId>user-service-app</artifactId>
|
||||
<dependencies>
|
||||
|
||||
|
||||
<!-- RPC 相关 -->
|
||||
<dependency>
|
||||
<groupId>com.alibaba.cloud</groupId>
|
||||
|
@ -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()));
|
||||
}
|
||||
|
||||
}
|
@ -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);
|
||||
|
||||
}
|
||||
|
@ -11,6 +11,8 @@ import java.util.Date;
|
||||
|
||||
/**
|
||||
* 手机验证码 DO
|
||||
*
|
||||
* idx_mobile 索引:基于 {@link #mobile} 字段
|
||||
*/
|
||||
@TableName("user_sms_code")
|
||||
@Data
|
||||
|
@ -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 {
|
||||
|
||||
/**
|
||||
* 用户编号
|
||||
|
@ -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);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -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() {
|
||||
|
@ -34,6 +34,6 @@ public class UserCreateBO {
|
||||
/**
|
||||
* IP 地址
|
||||
*/
|
||||
private String ip;
|
||||
private String createIp;
|
||||
|
||||
}
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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,7 +28,7 @@ public class UserPassportController {
|
||||
// @RequiresNone TODO 晚点加上
|
||||
public CommonResult<UserPassportVO> 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")
|
||||
@ -36,7 +38,7 @@ public class UserPassportController {
|
||||
HttpServletRequest request) {
|
||||
userPassportManager.sendSmsCode(sendSmsCodeDTO, HttpUtil.getIp(request));
|
||||
// 返回成功
|
||||
return CommonResult.success(true);
|
||||
return success(true);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -19,6 +19,7 @@ dubbo:
|
||||
subscribed-services: 'user-service' # 设置订阅的应用列表,默认为 * 订阅所有应用
|
||||
# Dubbo 服务消费者的配置
|
||||
consumer:
|
||||
timeout: 10000
|
||||
UserSmsCodeRpc:
|
||||
version: 1.0.0
|
||||
UserRpc:
|
||||
|
Loading…
Reference in New Issue
Block a user