完成快速登录功能,以及自测。

This commit is contained in:
YunaiV 2020-07-03 20:42:35 +08:00
parent 3d6bd5e4ee
commit 3cbd872497
14 changed files with 53 additions and 19 deletions

View File

@ -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);
}

View File

@ -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));
}
/**

View File

@ -11,8 +11,6 @@
<artifactId>user-service-app</artifactId>
<dependencies>
<!-- RPC 相关 -->
<dependency>
<groupId>com.alibaba.cloud</groupId>

View File

@ -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()));
}
}

View File

@ -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);
}

View File

@ -11,6 +11,8 @@ import java.util.Date;
/**
* 手机验证码 DO
*
* idx_mobile 索引基于 {@link #mobile} 字段
*/
@TableName("user_sms_code")
@Data

View File

@ -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 {
/**
* 用户编号

View File

@ -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);
}
}

View File

@ -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() {

View File

@ -34,6 +34,6 @@ public class UserCreateBO {
/**
* IP 地址
*/
private String ip;
private String createIp;
}

View File

@ -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

View File

@ -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

View File

@ -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<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")
@PostMapping("/send_sms_code")
@ApiOperation("发送手机验证码")
// @RequiresNone TODO 晚点加上
public CommonResult<Boolean> sendSmsCode(UserPassportSendSmsCodeDTO sendSmsCodeDTO,
HttpServletRequest request) {
userPassportManager.sendSmsCode(sendSmsCodeDTO, HttpUtil.getIp(request));
// 返回成功
return CommonResult.success(true);
return success(true);
}
}

View File

@ -19,6 +19,7 @@ dubbo:
subscribed-services: 'user-service' # 设置订阅的应用列表,默认为 * 订阅所有应用
# Dubbo 服务消费者的配置
consumer:
timeout: 10000
UserSmsCodeRpc:
version: 1.0.0
UserRpc: