mirror of
https://gitee.com/hhyykk/ipms-sjy.git
synced 2025-07-16 12:05:07 +08:00
初始化 c 端的登录逻辑
This commit is contained in:
@ -1,14 +0,0 @@
|
||||
package cn.iocoder.yudao.userserver.modules.infra.service.auth;
|
||||
|
||||
import cn.iocoder.yudao.framework.security.core.service.SecurityAuthFrameworkService;
|
||||
|
||||
/**
|
||||
* 认证 Service 接口
|
||||
*
|
||||
* 提供用户的账号密码登录、token 的校验等认证相关的功能
|
||||
*
|
||||
* @author 芋道源码
|
||||
*/
|
||||
public interface SysAuthService extends SecurityAuthFrameworkService {
|
||||
|
||||
}
|
@ -1,38 +0,0 @@
|
||||
package cn.iocoder.yudao.userserver.modules.infra.service.auth.impl;
|
||||
|
||||
import cn.iocoder.yudao.framework.security.core.LoginUser;
|
||||
import cn.iocoder.yudao.userserver.modules.infra.service.auth.SysAuthService;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.security.core.userdetails.UserDetails;
|
||||
import org.springframework.security.core.userdetails.UsernameNotFoundException;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
/**
|
||||
* Auth Service 实现类
|
||||
*
|
||||
* @author 芋道源码
|
||||
*/
|
||||
@Service
|
||||
@Slf4j
|
||||
public class SysAuthServiceImpl implements SysAuthService {
|
||||
|
||||
@Override
|
||||
public LoginUser verifyTokenAndRefresh(String token) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public LoginUser mockLogin(Long userId) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void logout(String token) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {
|
||||
return null;
|
||||
}
|
||||
}
|
@ -0,0 +1 @@
|
||||
package cn.iocoder.yudao.userserver.modules.infra.service;
|
@ -2,6 +2,7 @@ package cn.iocoder.yudao.userserver.modules.member.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 io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiImplicitParam;
|
||||
import io.swagger.annotations.ApiImplicitParams;
|
||||
@ -10,8 +11,13 @@ import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import javax.validation.Valid;
|
||||
|
||||
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
|
||||
import static cn.iocoder.yudao.framework.common.util.servlet.ServletUtils.getClientIP;
|
||||
import static cn.iocoder.yudao.framework.common.util.servlet.ServletUtils.getUserAgent;
|
||||
|
||||
@Api(tags = "认证")
|
||||
@RestController
|
||||
@RequestMapping("/")
|
||||
@ -19,13 +25,15 @@ import javax.validation.Valid;
|
||||
@Slf4j
|
||||
public class MbrAuthController {
|
||||
|
||||
@Resource
|
||||
private MbrAuthService authService;
|
||||
|
||||
@PostMapping("/login")
|
||||
@ApiOperation("使用手机 + 密码登录")
|
||||
public CommonResult<MbrAuthLoginRespVO> login(@RequestBody @Valid MbrAuthLoginReqVO reqVO) {
|
||||
// String token = authService.login(reqVO, getClientIP(), getUserAgent());
|
||||
// // 返回结果
|
||||
// return success(MbrAuthLoginRespVO.builder().token(token).build());
|
||||
return null;
|
||||
String token = authService.login(reqVO, getClientIP(), getUserAgent());
|
||||
// 返回结果
|
||||
return success(MbrAuthLoginRespVO.builder().token(token).build());
|
||||
}
|
||||
|
||||
@PostMapping("/sms-login")
|
||||
|
@ -0,0 +1 @@
|
||||
package cn.iocoder.yudao.userserver.modules.member.convert;
|
@ -0,0 +1,15 @@
|
||||
package cn.iocoder.yudao.userserver.modules.member.convert.user;
|
||||
|
||||
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.factory.Mappers;
|
||||
|
||||
@Mapper
|
||||
public interface MbrAuthConvert {
|
||||
|
||||
MbrAuthConvert INSTANCE = Mappers.getMapper(MbrAuthConvert.class);
|
||||
|
||||
LoginUser convert(MbrUserDO bean);
|
||||
|
||||
}
|
@ -1,4 +1,4 @@
|
||||
package cn.iocoder.yudao.userserver.modules.member.dal.mysql.user;
|
||||
package cn.iocoder.yudao.userserver.modules.member.dal.dataobject.user;
|
||||
|
||||
import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum;
|
||||
import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO;
|
@ -0,0 +1,19 @@
|
||||
package cn.iocoder.yudao.userserver.modules.member.dal.mysql.user;
|
||||
|
||||
import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
|
||||
import cn.iocoder.yudao.userserver.modules.member.dal.dataobject.user.MbrUserDO;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
|
||||
/**
|
||||
* MbrUserDO Mapper
|
||||
*
|
||||
* @author 芋道源码
|
||||
*/
|
||||
@Mapper
|
||||
public interface MbrUserMapper extends BaseMapperX<MbrUserDO> {
|
||||
|
||||
default MbrUserDO selectByMobile(String mobile) {
|
||||
return selectOne("mobile", mobile);
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,27 @@
|
||||
package cn.iocoder.yudao.userserver.modules.member.service.auth;
|
||||
|
||||
import cn.iocoder.yudao.framework.security.core.service.SecurityAuthFrameworkService;
|
||||
import cn.iocoder.yudao.userserver.modules.member.controller.auth.vo.MbrAuthLoginReqVO;
|
||||
|
||||
import javax.validation.Valid;
|
||||
|
||||
/**
|
||||
* 用户前台的认证 Service 接口
|
||||
*
|
||||
* 提供用户的账号密码登录、token 的校验等认证相关的功能
|
||||
*
|
||||
* @author 芋道源码
|
||||
*/
|
||||
public interface MbrAuthService extends SecurityAuthFrameworkService {
|
||||
|
||||
/**
|
||||
* 手机 + 密码登录
|
||||
*
|
||||
* @param reqVO 登录信息
|
||||
* @param userIp 用户 IP
|
||||
* @param userAgent 用户 UA
|
||||
* @return 身份令牌,使用 JWT 方式
|
||||
*/
|
||||
String login(@Valid MbrAuthLoginReqVO reqVO, String userIp, String userAgent);
|
||||
|
||||
}
|
@ -0,0 +1,65 @@
|
||||
package cn.iocoder.yudao.userserver.modules.member.service.auth.impl;
|
||||
|
||||
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.member.dal.dataobject.user.MbrUserDO;
|
||||
import cn.iocoder.yudao.userserver.modules.member.service.auth.MbrAuthService;
|
||||
import cn.iocoder.yudao.userserver.modules.member.service.user.MbrUserService;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.context.annotation.Lazy;
|
||||
import org.springframework.security.authentication.AuthenticationManager;
|
||||
import org.springframework.security.core.userdetails.UserDetails;
|
||||
import org.springframework.security.core.userdetails.UsernameNotFoundException;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
|
||||
/**
|
||||
* Auth Service 实现类
|
||||
*
|
||||
* @author 芋道源码
|
||||
*/
|
||||
@Service
|
||||
@Slf4j
|
||||
public class MbrAuthServiceImpl implements MbrAuthService {
|
||||
|
||||
@Resource
|
||||
@Lazy // 延迟加载,因为存在相互依赖的问题
|
||||
private AuthenticationManager authenticationManager;
|
||||
|
||||
@Resource
|
||||
private MbrUserService userService;
|
||||
|
||||
@Override
|
||||
public UserDetails loadUserByUsername(String mobile) throws UsernameNotFoundException {
|
||||
// 获取 username 对应的 SysUserDO
|
||||
MbrUserDO user = userService.getUserByMobile(mobile);
|
||||
if (user == null) {
|
||||
throw new UsernameNotFoundException(mobile);
|
||||
}
|
||||
// 创建 LoginUser 对象
|
||||
return MbrAuthConvert.INSTANCE.convert(user);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String login(MbrAuthLoginReqVO reqVO, String userIp, String userAgent) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public LoginUser verifyTokenAndRefresh(String token) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public LoginUser mockLogin(Long userId) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void logout(String token) {
|
||||
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,20 @@
|
||||
package cn.iocoder.yudao.userserver.modules.member.service.user;
|
||||
|
||||
import cn.iocoder.yudao.userserver.modules.member.dal.dataobject.user.MbrUserDO;
|
||||
|
||||
/**
|
||||
* 前台用户 Service 接口
|
||||
*
|
||||
* @author 芋道源码
|
||||
*/
|
||||
public interface MbrUserService {
|
||||
|
||||
/**
|
||||
* 通过手机查询用户
|
||||
*
|
||||
* @param mobile 手机
|
||||
* @return 用户对象
|
||||
*/
|
||||
MbrUserDO getUserByMobile(String mobile);
|
||||
|
||||
}
|
@ -0,0 +1,30 @@
|
||||
package cn.iocoder.yudao.userserver.modules.member.service.user.impl;
|
||||
|
||||
import cn.iocoder.yudao.userserver.modules.member.dal.dataobject.user.MbrUserDO;
|
||||
import cn.iocoder.yudao.userserver.modules.member.dal.mysql.user.MbrUserMapper;
|
||||
import cn.iocoder.yudao.userserver.modules.member.service.user.MbrUserService;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import javax.validation.Valid;
|
||||
|
||||
/**
|
||||
* User Service 实现类
|
||||
*
|
||||
* @author 芋道源码
|
||||
*/
|
||||
@Service
|
||||
@Valid
|
||||
@Slf4j
|
||||
public class MbrUserServiceImpl implements MbrUserService {
|
||||
|
||||
@Resource
|
||||
private MbrUserMapper userMapper;
|
||||
|
||||
@Override
|
||||
public MbrUserDO getUserByMobile(String mobile) {
|
||||
return userMapper.selectByMobile(mobile);
|
||||
}
|
||||
|
||||
}
|
Reference in New Issue
Block a user