mirror of
				https://gitee.com/hhyykk/ipms-sjy.git
				synced 2025-10-31 10:18:42 +08:00 
			
		
		
		
	完成 user-admin-server 的用户手机 + 密码登录
This commit is contained in:
		| @@ -9,9 +9,4 @@ import cn.iocoder.yudao.framework.common.exception.ErrorCode; | ||||
|  */ | ||||
| public interface MbrErrorCodeConstants { | ||||
|  | ||||
|     // ========== AUTH 模块 1004000000 ========== | ||||
|     ErrorCode AUTH_LOGIN_BAD_CREDENTIALS = new ErrorCode(1004000000, "登录失败,账号密码不正确"); | ||||
|     ErrorCode AUTH_LOGIN_USER_DISABLED = new ErrorCode(1004000001, "登录失败,账号被禁用"); | ||||
|     ErrorCode AUTH_LOGIN_FAIL_UNKNOWN = new ErrorCode(1004000002, "登录失败"); // 登录失败的兜底,未知原因 | ||||
|  | ||||
| } | ||||
|   | ||||
| @@ -0,0 +1 @@ | ||||
| package cn.iocoder.yudao.userserver.modules.member.service; | ||||
| @@ -0,0 +1,8 @@ | ||||
| ### 请求 /login 接口 => 成功 | ||||
| POST {{userServerUrl}}/login | ||||
| Content-Type: application/json | ||||
|  | ||||
| { | ||||
|   "mobile": "15601691300", | ||||
|   "password": "admin123" | ||||
| } | ||||
| @@ -1,8 +1,8 @@ | ||||
| package cn.iocoder.yudao.userserver.modules.member.controller.auth; | ||||
| package cn.iocoder.yudao.userserver.modules.system.controller.auth; | ||||
| 
 | ||||
| import cn.iocoder.yudao.framework.common.pojo.CommonResult; | ||||
| import cn.iocoder.yudao.userserver.modules.member.controller.auth.vo.*; | ||||
| import cn.iocoder.yudao.userserver.modules.member.service.auth.MbrAuthService; | ||||
| import cn.iocoder.yudao.userserver.modules.system.controller.auth.vo.*; | ||||
| import cn.iocoder.yudao.userserver.modules.system.service.auth.SysAuthService; | ||||
| import io.swagger.annotations.Api; | ||||
| import io.swagger.annotations.ApiImplicitParam; | ||||
| import io.swagger.annotations.ApiImplicitParams; | ||||
| @@ -23,14 +23,14 @@ import static cn.iocoder.yudao.framework.common.util.servlet.ServletUtils.getUse | ||||
| @RequestMapping("/") | ||||
| @Validated | ||||
| @Slf4j | ||||
| public class MbrAuthController { | ||||
| public class SysAuthController { | ||||
| 
 | ||||
|     @Resource | ||||
|     private MbrAuthService authService; | ||||
|     private SysAuthService authService; | ||||
| 
 | ||||
|     @PostMapping("/login") | ||||
|     @ApiOperation("使用手机 + 密码登录") | ||||
|     public CommonResult<MbrAuthLoginRespVO> login(@RequestBody @Valid MbrAuthLoginReqVO reqVO) { | ||||
|     public CommonResult<MbrAuthLoginRespVO> login(@RequestBody @Valid SysAuthLoginReqVO reqVO) { | ||||
|         String token = authService.login(reqVO, getClientIP(), getUserAgent()); | ||||
|         // 返回结果 | ||||
|         return success(MbrAuthLoginRespVO.builder().token(token).build()); | ||||
| @@ -38,7 +38,7 @@ public class MbrAuthController { | ||||
| 
 | ||||
|     @PostMapping("/sms-login") | ||||
|     @ApiOperation("使用手机 + 验证码登录") | ||||
|     public CommonResult<MbrAuthLoginRespVO> smsLogin(@RequestBody @Valid MbrAuthLoginReqVO reqVO) { | ||||
|     public CommonResult<MbrAuthLoginRespVO> smsLogin(@RequestBody @Valid SysAuthLoginReqVO reqVO) { | ||||
|         return null; | ||||
|     } | ||||
| 
 | ||||
| @@ -53,7 +53,7 @@ public class MbrAuthController { | ||||
| 
 | ||||
|     @PostMapping("/reset-password") | ||||
|     @ApiOperation(value = "重置密码", notes = "用户忘记密码时使用") | ||||
|     public CommonResult<Boolean> resetPassword(@RequestBody @Valid MbrAuthResetPasswordReqVO reqVO) { | ||||
|     public CommonResult<Boolean> resetPassword(@RequestBody @Valid SysAuthResetPasswordReqVO reqVO) { | ||||
|         return null; | ||||
|     } | ||||
| 
 | ||||
| @@ -1,4 +1,4 @@ | ||||
| package cn.iocoder.yudao.userserver.modules.member.controller.auth.vo; | ||||
| package cn.iocoder.yudao.userserver.modules.system.controller.auth.vo; | ||||
| 
 | ||||
| import io.swagger.annotations.ApiModel; | ||||
| import io.swagger.annotations.ApiModelProperty; | ||||
| @@ -1,4 +1,4 @@ | ||||
| package cn.iocoder.yudao.userserver.modules.member.controller.auth.vo; | ||||
| package cn.iocoder.yudao.userserver.modules.system.controller.auth.vo; | ||||
| 
 | ||||
| import cn.iocoder.yudao.framework.common.validation.Mobile; | ||||
| import io.swagger.annotations.ApiModel; | ||||
| @@ -21,4 +21,4 @@ public class MbrAuthSendSmsReqVO { | ||||
|     @NotNull(message = "发送场景不能为空") | ||||
|     private Integer scene; | ||||
| 
 | ||||
| } | ||||
| } | ||||
| @@ -1,4 +1,4 @@ | ||||
| package cn.iocoder.yudao.userserver.modules.member.controller.auth.vo; | ||||
| package cn.iocoder.yudao.userserver.modules.system.controller.auth.vo; | ||||
| 
 | ||||
| import cn.iocoder.yudao.framework.common.validation.Mobile; | ||||
| import io.swagger.annotations.ApiModel; | ||||
| @@ -1,4 +1,4 @@ | ||||
| package cn.iocoder.yudao.userserver.modules.member.controller.auth.vo; | ||||
| package cn.iocoder.yudao.userserver.modules.system.controller.auth.vo; | ||||
| 
 | ||||
| import cn.iocoder.yudao.framework.common.validation.InEnum; | ||||
| import cn.iocoder.yudao.userserver.modules.member.enums.social.SysSocialTypeEnum; | ||||
| @@ -1,4 +1,4 @@ | ||||
| package cn.iocoder.yudao.userserver.modules.member.controller.auth.vo; | ||||
| package cn.iocoder.yudao.userserver.modules.system.controller.auth.vo; | ||||
| 
 | ||||
| import cn.iocoder.yudao.framework.common.validation.InEnum; | ||||
| import cn.iocoder.yudao.userserver.modules.member.enums.social.SysSocialTypeEnum; | ||||
| @@ -1,4 +1,4 @@ | ||||
| package cn.iocoder.yudao.userserver.modules.member.controller.auth.vo; | ||||
| package cn.iocoder.yudao.userserver.modules.system.controller.auth.vo; | ||||
| 
 | ||||
| import cn.iocoder.yudao.framework.common.validation.InEnum; | ||||
| import cn.iocoder.yudao.userserver.modules.member.enums.social.SysSocialTypeEnum; | ||||
| @@ -1,4 +1,4 @@ | ||||
| package cn.iocoder.yudao.userserver.modules.member.controller.auth.vo; | ||||
| package cn.iocoder.yudao.userserver.modules.system.controller.auth.vo; | ||||
| 
 | ||||
| import cn.iocoder.yudao.framework.common.validation.InEnum; | ||||
| import cn.iocoder.yudao.userserver.modules.member.enums.social.SysSocialTypeEnum; | ||||
| @@ -1,4 +1,4 @@ | ||||
| package cn.iocoder.yudao.userserver.modules.member.controller.auth.vo; | ||||
| package cn.iocoder.yudao.userserver.modules.system.controller.auth.vo; | ||||
| 
 | ||||
| import cn.iocoder.yudao.framework.common.validation.Mobile; | ||||
| import io.swagger.annotations.ApiModel; | ||||
| @@ -16,7 +16,7 @@ import javax.validation.constraints.NotEmpty; | ||||
| @NoArgsConstructor | ||||
| @AllArgsConstructor | ||||
| @Builder | ||||
| public class MbrAuthLoginReqVO { | ||||
| public class SysAuthLoginReqVO { | ||||
| 
 | ||||
|     @ApiModelProperty(value = "手机号", required = true, example = "15601691300") | ||||
|     @NotEmpty(message = "手机号不能为空") | ||||
| @@ -1,4 +1,4 @@ | ||||
| package cn.iocoder.yudao.userserver.modules.member.controller.auth.vo; | ||||
| package cn.iocoder.yudao.userserver.modules.system.controller.auth.vo; | ||||
| 
 | ||||
| import io.swagger.annotations.ApiModel; | ||||
| import io.swagger.annotations.ApiModelProperty; | ||||
| @@ -16,7 +16,7 @@ import javax.validation.constraints.Pattern; | ||||
| @NoArgsConstructor | ||||
| @AllArgsConstructor | ||||
| @Builder | ||||
| public class MbrAuthResetPasswordReqVO { | ||||
| public class SysAuthResetPasswordReqVO { | ||||
| 
 | ||||
|     @ApiModelProperty(value = "新密码", required = true, example = "buzhidao") | ||||
|     @NotEmpty(message = "新密码不能为空") | ||||
| @@ -0,0 +1,4 @@ | ||||
| /** | ||||
|  * 占位 | ||||
|  */ | ||||
| package cn.iocoder.yudao.userserver.modules.system.controller; | ||||
| @@ -1,9 +1,10 @@ | ||||
| package cn.iocoder.yudao.userserver.modules.member.convert.user; | ||||
| package cn.iocoder.yudao.userserver.modules.system.convert.auth; | ||||
| 
 | ||||
| import cn.iocoder.yudao.framework.common.enums.UserTypeEnum; | ||||
| import cn.iocoder.yudao.framework.security.core.LoginUser; | ||||
| import cn.iocoder.yudao.userserver.modules.member.dal.dataobject.user.MbrUserDO; | ||||
| import org.mapstruct.Mapper; | ||||
| import org.mapstruct.Mapping; | ||||
| import org.mapstruct.factory.Mappers; | ||||
| 
 | ||||
| @Mapper | ||||
| @@ -11,6 +12,7 @@ public interface MbrAuthConvert { | ||||
| 
 | ||||
|     MbrAuthConvert INSTANCE = Mappers.getMapper(MbrAuthConvert.class); | ||||
| 
 | ||||
|     @Mapping(source = "mobile", target = "username") | ||||
|     LoginUser convert0(MbrUserDO bean); | ||||
| 
 | ||||
|     default LoginUser convert(MbrUserDO bean) { | ||||
| @@ -0,0 +1,17 @@ | ||||
| package cn.iocoder.yudao.userserver.modules.system.enums; | ||||
|  | ||||
| import cn.iocoder.yudao.framework.common.exception.ErrorCode; | ||||
|  | ||||
| /** | ||||
|  * System 错误码枚举类 | ||||
|  * | ||||
|  * system 系统,使用 1-005-000-000 段 | ||||
|  */ | ||||
| public interface SysErrorCodeConstants { | ||||
|  | ||||
|     // ========== AUTH 模块 1005000000 ========== | ||||
|     ErrorCode AUTH_LOGIN_BAD_CREDENTIALS = new ErrorCode(1005000000, "登录失败,账号密码不正确"); | ||||
|     ErrorCode AUTH_LOGIN_USER_DISABLED = new ErrorCode(1005000001, "登录失败,账号被禁用"); | ||||
|     ErrorCode AUTH_LOGIN_FAIL_UNKNOWN = new ErrorCode(1005000002, "登录失败"); // 登录失败的兜底,未知原因 | ||||
|  | ||||
| } | ||||
| @@ -1,7 +1,7 @@ | ||||
| package cn.iocoder.yudao.userserver.modules.member.service.auth; | ||||
| package cn.iocoder.yudao.userserver.modules.system.service.auth; | ||||
| 
 | ||||
| import cn.iocoder.yudao.framework.security.core.service.SecurityAuthFrameworkService; | ||||
| import cn.iocoder.yudao.userserver.modules.member.controller.auth.vo.MbrAuthLoginReqVO; | ||||
| import cn.iocoder.yudao.userserver.modules.system.controller.auth.vo.SysAuthLoginReqVO; | ||||
| 
 | ||||
| import javax.validation.Valid; | ||||
| 
 | ||||
| @@ -12,7 +12,7 @@ import javax.validation.Valid; | ||||
|  * | ||||
|  * @author 芋道源码 | ||||
|  */ | ||||
| public interface MbrAuthService extends SecurityAuthFrameworkService { | ||||
| public interface SysAuthService extends SecurityAuthFrameworkService { | ||||
| 
 | ||||
|     /** | ||||
|      * 手机 + 密码登录 | ||||
| @@ -22,6 +22,6 @@ public interface MbrAuthService extends SecurityAuthFrameworkService { | ||||
|      * @param userAgent 用户 UA | ||||
|      * @return 身份令牌,使用 JWT 方式 | ||||
|      */ | ||||
|     String login(@Valid MbrAuthLoginReqVO reqVO, String userIp, String userAgent); | ||||
|     String login(@Valid SysAuthLoginReqVO reqVO, String userIp, String userAgent); | ||||
| 
 | ||||
| } | ||||
| @@ -1,4 +1,4 @@ | ||||
| package cn.iocoder.yudao.userserver.modules.member.service.auth.impl; | ||||
| package cn.iocoder.yudao.userserver.modules.system.service.auth.impl; | ||||
| 
 | ||||
| import cn.iocoder.yudao.coreservice.modules.system.service.auth.SysUserSessionCoreService; | ||||
| import cn.iocoder.yudao.coreservice.modules.system.service.logger.SysLoginLogCoreService; | ||||
| @@ -6,10 +6,10 @@ import cn.iocoder.yudao.coreservice.modules.system.service.logger.dto.SysLoginLo | ||||
| import cn.iocoder.yudao.framework.common.util.monitor.TracerUtils; | ||||
| import cn.iocoder.yudao.framework.common.util.servlet.ServletUtils; | ||||
| import cn.iocoder.yudao.framework.security.core.LoginUser; | ||||
| import cn.iocoder.yudao.userserver.modules.member.controller.auth.vo.MbrAuthLoginReqVO; | ||||
| import cn.iocoder.yudao.userserver.modules.member.convert.user.MbrAuthConvert; | ||||
| import cn.iocoder.yudao.userserver.modules.system.controller.auth.vo.SysAuthLoginReqVO; | ||||
| import cn.iocoder.yudao.userserver.modules.system.convert.auth.MbrAuthConvert; | ||||
| import cn.iocoder.yudao.userserver.modules.member.dal.dataobject.user.MbrUserDO; | ||||
| import cn.iocoder.yudao.userserver.modules.member.service.auth.MbrAuthService; | ||||
| import cn.iocoder.yudao.userserver.modules.system.service.auth.SysAuthService; | ||||
| import cn.iocoder.yudao.userserver.modules.member.service.user.MbrUserService; | ||||
| import cn.iocoder.yudao.coreservice.modules.system.enums.logger.SysLoginLogTypeEnum; | ||||
| import cn.iocoder.yudao.coreservice.modules.system.enums.logger.SysLoginResultEnum; | ||||
| @@ -30,7 +30,7 @@ import javax.annotation.Resource; | ||||
| import java.util.Objects; | ||||
| 
 | ||||
| import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; | ||||
| import static cn.iocoder.yudao.userserver.modules.member.enums.MbrErrorCodeConstants.*; | ||||
| import static cn.iocoder.yudao.userserver.modules.system.enums.SysErrorCodeConstants.*; | ||||
| 
 | ||||
| /** | ||||
|  * Auth Service 实现类 | ||||
| @@ -39,7 +39,7 @@ import static cn.iocoder.yudao.userserver.modules.member.enums.MbrErrorCodeConst | ||||
|  */ | ||||
| @Service | ||||
| @Slf4j | ||||
| public class MbrAuthServiceImpl implements MbrAuthService { | ||||
| public class SysAuthServiceImpl implements SysAuthService { | ||||
| 
 | ||||
|     @Resource | ||||
|     @Lazy // 延迟加载,因为存在相互依赖的问题 | ||||
| @@ -64,7 +64,7 @@ public class MbrAuthServiceImpl implements MbrAuthService { | ||||
|     } | ||||
| 
 | ||||
|     @Override | ||||
|     public String login(MbrAuthLoginReqVO reqVO, String userIp, String userAgent) { | ||||
|     public String login(SysAuthLoginReqVO reqVO, String userIp, String userAgent) { | ||||
|         // 使用手机 + 密码,进行登录。 | ||||
|         LoginUser loginUser = this.login0(reqVO.getMobile(), reqVO.getPassword()); | ||||
| 
 | ||||
| @@ -0,0 +1 @@ | ||||
| package cn.iocoder.yudao.userserver.modules.system.service; | ||||
		Reference in New Issue
	
	Block a user
	 YunaiV
					YunaiV