重写用户快速登录逻辑
This commit is contained in:
@@ -0,0 +1,72 @@
|
||||
package cn.iocoder.mall.userservice.enums;
|
||||
|
||||
import cn.iocoder.common.framework.util.ServiceExceptionUtil;
|
||||
|
||||
/**
|
||||
* 错误码枚举类
|
||||
*
|
||||
* system 系统,使用 1-002-000-000 段
|
||||
*/
|
||||
public enum UserErrorCodeEnum implements ServiceExceptionUtil.Enumerable<UserErrorCodeEnum> {
|
||||
|
||||
// ========== OAUTH2 模块 ==========
|
||||
OAUTH2_UNKNOWN(1001001000, "未知错误"), // 预留
|
||||
// 预留 1001001001 ~ 1001001099 错误码,方便前端
|
||||
OAUTH2_ACCESS_TOKEN_NOT_FOUND(1001001001, "访问令牌不存在"),
|
||||
OAUTH2_ACCESS_TOKEN_TOKEN_EXPIRED(1001001002, "访问令牌已过期"),
|
||||
OAUTH2_ACCESS_TOKEN_INVALID(1001001003, "访问令牌已失效"),
|
||||
OAUTH2_NOT_AUTHENTICATE(1001001004, "账号未登陆"),
|
||||
OAUTH2_REFRESH_TOKEN_NOT_FOUND(1001001005, "刷新令牌不存在"),
|
||||
OAUTH_REFRESH_TOKEN_EXPIRED(1001001006, "访问令牌已过期"),
|
||||
OAUTH_REFRESH_TOKEN_INVALID(1001001007, "刷新令牌已失效"),
|
||||
// 其它 1001001100 开始
|
||||
OAUTH2_ACCOUNT_NOT_FOUND(1001001100, "账号不存在"),
|
||||
OAUTH2_ACCOUNT_PASSWORD_ERROR(1001001101, "密码不正确"),
|
||||
|
||||
// ========== 用户手机验证码模块 ==========
|
||||
USER_SMS_CODE_NOT_FOUND(1001001200, "验证码不存在"),
|
||||
USER_SMS_CODE_EXPIRED(1001001201, "验证码已过期"),
|
||||
USER_SMS_CODE_USED(1001001202, "验证码已使用"),
|
||||
USER_SMS_CODE_NOT_CORRECT(1001001203, "验证码不正确"),
|
||||
USER_SMS_CODE_EXCEED_SEND_MAXIMUM_QUANTITY_PER_DAY(1001001204, "超过每日短信发送数量"),
|
||||
USER_SMS_CODE_SEND_TOO_FAST(1001001205, "短信发送过于频率"),
|
||||
|
||||
// ========== 用户地址 ==========
|
||||
USER_ADDRESS_NOT_EXISTENT(1001004000, "用户地址不存在!"),
|
||||
USER_ADDRESS_IS_DELETED(1001004001, "用户地址已被删除!"),
|
||||
USER_GET_ADDRESS_NOT_EXISTS(1001004002, "获取的地址不存在!"),
|
||||
|
||||
// ========== 用户信息模块 1004004100 ==========
|
||||
USER_NOT_EXISTS(1004004100, "用户不存在"),
|
||||
USER_STATUS_NOT_EXISTS(1004004101, "用户状态不存在"),
|
||||
USER_STATUS_EQUALS(1004004101, "用户已经是该状态"),
|
||||
|
||||
;
|
||||
|
||||
|
||||
private final int code;
|
||||
private final String message;
|
||||
|
||||
UserErrorCodeEnum(int code, String message) {
|
||||
this.code = code;
|
||||
this.message = message;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getCode() {
|
||||
return code;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getMessage() {
|
||||
return message;
|
||||
}
|
||||
|
||||
// TODO: 2020-05-22 封装成start的时候,直接在start中定义一个统一的枚举,从中取值;
|
||||
@Override
|
||||
public int getGroup() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
package cn.iocoder.mall.userservice.enums.sms;
|
||||
|
||||
import cn.iocoder.common.framework.core.IntArrayValuable;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
/**
|
||||
* 用户短信验证码发送场景的枚举
|
||||
*/
|
||||
public enum UserSmsSceneEnum implements IntArrayValuable {
|
||||
|
||||
LOGIN_BY_SMS(1, "手机号登陆"),
|
||||
CHANGE_MOBILE_BY_SMS(2, "更换手机号"),
|
||||
;
|
||||
|
||||
public static final int[] ARRAYS = Arrays.stream(values()).mapToInt(UserSmsSceneEnum::getValue).toArray();
|
||||
|
||||
private final Integer value;
|
||||
private final String name;
|
||||
|
||||
UserSmsSceneEnum(Integer value, String name) {
|
||||
this.value = value;
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int[] array() {
|
||||
return ARRAYS;
|
||||
}
|
||||
|
||||
public Integer getValue() {
|
||||
return value;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
package cn.iocoder.mall.userservice.rpc.sms;
|
||||
|
||||
import cn.iocoder.common.framework.vo.CommonResult;
|
||||
import cn.iocoder.mall.userservice.rpc.sms.vo.UserSendSmsCodeDTO;
|
||||
import cn.iocoder.mall.userservice.rpc.sms.vo.UserVerifySmsCodeDTO;
|
||||
|
||||
/**
|
||||
* 用户短信验证码 Rpc 接口
|
||||
*/
|
||||
public interface UserSmsCodeRpc {
|
||||
|
||||
CommonResult<Boolean> sendSmsCode(UserSendSmsCodeDTO sendSmsCodeDTO);
|
||||
|
||||
CommonResult<Boolean> verifySmsCode(UserVerifySmsCodeDTO verifySmsCodeDTO);
|
||||
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
package cn.iocoder.mall.userservice.rpc.sms.vo;
|
||||
|
||||
import cn.iocoder.common.framework.validator.InEnum;
|
||||
import cn.iocoder.mall.userservice.enums.sms.UserSmsSceneEnum;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.experimental.Accessors;
|
||||
|
||||
import javax.validation.constraints.NotNull;
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* 用户发送短信验证码 DTO
|
||||
*/
|
||||
@Data
|
||||
@Accessors(chain = true)
|
||||
@Builder
|
||||
public class UserSendSmsCodeDTO implements Serializable {
|
||||
|
||||
/**
|
||||
* 手机号码
|
||||
*/
|
||||
@NotNull(message = "手机号码不能为空")
|
||||
private String mobile;
|
||||
/**
|
||||
* IP
|
||||
*/
|
||||
@NotNull(message = "IP 不能为空")
|
||||
private String ip;
|
||||
/**
|
||||
* 发送场景
|
||||
*/
|
||||
@NotNull(message = "发送场景不能为空")
|
||||
@InEnum(value = UserSmsSceneEnum.class, message = "发送场景不能为空")
|
||||
private Integer scene;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
package cn.iocoder.mall.userservice.rpc.sms.vo;
|
||||
|
||||
import cn.iocoder.common.framework.validator.InEnum;
|
||||
import cn.iocoder.mall.userservice.enums.sms.UserSmsSceneEnum;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.experimental.Accessors;
|
||||
|
||||
import javax.validation.constraints.NotNull;
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* 用户校验验证码 DTO
|
||||
*/
|
||||
@Data
|
||||
@Accessors(chain = true)
|
||||
@Builder
|
||||
public class UserVerifySmsCodeDTO implements Serializable {
|
||||
|
||||
/**
|
||||
* 手机号码
|
||||
*/
|
||||
@NotNull(message = "手机号码不能为空")
|
||||
private String mobile;
|
||||
/**
|
||||
* IP
|
||||
*/
|
||||
@NotNull(message = "IP 不能为空")
|
||||
private String ip;
|
||||
/**
|
||||
* 发送场景
|
||||
*/
|
||||
@NotNull(message = "发送场景不能为空")
|
||||
@InEnum(value = UserSmsSceneEnum.class, message = "发送场景不能为空")
|
||||
private Integer scene;
|
||||
/**
|
||||
* 验证码
|
||||
*/
|
||||
@NotNull(message = "验证码不能为空")
|
||||
private String code;
|
||||
|
||||
}
|
||||
@@ -1,10 +1,13 @@
|
||||
package cn.iocoder.mall.userservice.rpc.user;
|
||||
|
||||
import cn.iocoder.common.framework.vo.CommonResult;
|
||||
import cn.iocoder.mall.userservice.rpc.user.dto.UserCreateDTO;
|
||||
import cn.iocoder.mall.userservice.rpc.user.vo.UserVO;
|
||||
|
||||
public interface UserRpc {
|
||||
|
||||
CommonResult<UserVO> getUser(Integer id);
|
||||
|
||||
CommonResult<UserVO> createUserIfAbsent(UserCreateDTO createDTO);
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,35 @@
|
||||
package cn.iocoder.mall.userservice.rpc.user.dto;
|
||||
|
||||
import cn.iocoder.common.framework.validator.Mobile;
|
||||
import lombok.Data;
|
||||
import lombok.experimental.Accessors;
|
||||
|
||||
import javax.validation.constraints.NotNull;
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* 用户创建 DTO
|
||||
*/
|
||||
@Data
|
||||
@Accessors(chain = true)
|
||||
public class UserCreateDTO implements Serializable {
|
||||
|
||||
/**
|
||||
* 手机号
|
||||
*/
|
||||
@NotNull(message = "手机号不能为空")
|
||||
@Mobile(message = "手机格式不正确")
|
||||
private String mobile;
|
||||
/**
|
||||
* 密码
|
||||
*
|
||||
* 允许为空,自动生成
|
||||
*/
|
||||
private String password;
|
||||
/**
|
||||
* IP
|
||||
*/
|
||||
@NotNull(message = "IP 不能为空")
|
||||
private String ip;
|
||||
|
||||
}
|
||||
@@ -1,5 +1,7 @@
|
||||
package cn.iocoder.mall.userservice.rpc.user.vo;
|
||||
|
||||
import cn.iocoder.common.framework.constant.CommonStatusEnum;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user