mirror of
https://gitee.com/dromara/RuoYi-Vue-Plus.git
synced 2026-03-19 03:58:50 +08:00
update 优化 统一补全代码注释
This commit is contained in:
@@ -47,7 +47,7 @@ import java.util.concurrent.ScheduledExecutorService;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
/**
|
||||
* 认证
|
||||
* 认证控制器,提供登录、注册、社交绑定和退出能力。
|
||||
*
|
||||
* @author Lion Li
|
||||
*/
|
||||
@@ -103,10 +103,10 @@ public class AuthController {
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取跳转URL
|
||||
* 获取第三方绑定跳转地址。
|
||||
*
|
||||
* @param source 登录来源
|
||||
* @return 结果
|
||||
* @return 跳转地址
|
||||
*/
|
||||
@GetMapping("/binding/{source}")
|
||||
public R<String> authBinding(@PathVariable("source") String source) {
|
||||
@@ -120,10 +120,10 @@ public class AuthController {
|
||||
}
|
||||
|
||||
/**
|
||||
* 前端回调绑定授权(需要token)
|
||||
* 处理前端回调后的社交账号绑定。
|
||||
*
|
||||
* @param loginBody 请求体
|
||||
* @return 结果
|
||||
* @return 操作结果
|
||||
*/
|
||||
@PostMapping("/social/callback")
|
||||
public R<Void> socialCallback(@RequestBody SocialLoginBody loginBody) {
|
||||
@@ -144,9 +144,10 @@ public class AuthController {
|
||||
|
||||
|
||||
/**
|
||||
* 取消授权(需要token)
|
||||
* 取消当前用户的社交账号授权。
|
||||
*
|
||||
* @param socialId socialId
|
||||
* @return 操作结果
|
||||
*/
|
||||
@DeleteMapping(value = "/unlock/{socialId}")
|
||||
public R<Void> unlockSocial(@PathVariable Long socialId) {
|
||||
@@ -167,7 +168,10 @@ public class AuthController {
|
||||
}
|
||||
|
||||
/**
|
||||
* 用户注册
|
||||
* 用户注册。
|
||||
*
|
||||
* @param user 注册信息
|
||||
* @return 操作结果
|
||||
*/
|
||||
@ApiEncrypt
|
||||
@PostMapping("/register")
|
||||
@@ -180,9 +184,11 @@ public class AuthController {
|
||||
}
|
||||
|
||||
/**
|
||||
* 登录页面租户下拉框
|
||||
* 获取登录页租户下拉框数据,当前仅预留返回结构。
|
||||
*
|
||||
* @param request 当前请求
|
||||
* @return 租户列表
|
||||
* @throws Exception 异常
|
||||
*/
|
||||
@RateLimiter(time = 60, count = 20, limitType = LimitType.IP)
|
||||
@GetMapping("/tenant/list")
|
||||
|
||||
@@ -53,9 +53,10 @@ public class CaptchaController {
|
||||
private final MailProperties mailProperties;
|
||||
|
||||
/**
|
||||
* 短信验证码
|
||||
* 发送短信验证码。
|
||||
*
|
||||
* @param phonenumber 用户手机号
|
||||
* @return 操作结果
|
||||
*/
|
||||
@RateLimiter(key = "#phonenumber", time = 60, count = 1)
|
||||
@GetMapping("/resource/sms/code")
|
||||
@@ -77,9 +78,10 @@ public class CaptchaController {
|
||||
}
|
||||
|
||||
/**
|
||||
* 邮箱验证码
|
||||
* 发送邮箱验证码。
|
||||
*
|
||||
* @param email 邮箱
|
||||
* @return 操作结果
|
||||
*/
|
||||
@GetMapping("/resource/email/code")
|
||||
public R<Void> emailCode(@NotBlank(message = "{user.email.not.blank}") String email) {
|
||||
@@ -91,8 +93,9 @@ public class CaptchaController {
|
||||
}
|
||||
|
||||
/**
|
||||
* 邮箱验证码
|
||||
* 独立方法避免验证码关闭之后仍然走限流
|
||||
* 发送邮箱验证码的实际执行方法,拆分出来避免开关关闭时仍触发限流。
|
||||
*
|
||||
* @param email 邮箱
|
||||
*/
|
||||
@RateLimiter(key = "#email", time = 60, count = 1)
|
||||
public void emailCodeImpl(String email) {
|
||||
@@ -108,7 +111,9 @@ public class CaptchaController {
|
||||
}
|
||||
|
||||
/**
|
||||
* 生成验证码
|
||||
* 获取图片验证码。
|
||||
*
|
||||
* @return 验证码信息
|
||||
*/
|
||||
@GetMapping("/auth/code")
|
||||
public R<CaptchaVo> getCode() {
|
||||
@@ -122,8 +127,9 @@ public class CaptchaController {
|
||||
}
|
||||
|
||||
/**
|
||||
* 生成验证码
|
||||
* 独立方法避免验证码关闭之后仍然走限流
|
||||
* 实际生成图片验证码并缓存结果。
|
||||
*
|
||||
* @return 验证码信息
|
||||
*/
|
||||
@RateLimiter(time = 60, count = 10, limitType = LimitType.IP)
|
||||
public CaptchaVo getCodeImpl() {
|
||||
|
||||
@@ -18,7 +18,9 @@ import org.springframework.web.bind.annotation.RestController;
|
||||
public class IndexController {
|
||||
|
||||
/**
|
||||
* 访问首页,提示语
|
||||
* 访问首页时返回引导提示。
|
||||
*
|
||||
* @return 首页提示语
|
||||
*/
|
||||
@GetMapping("/")
|
||||
public String index() {
|
||||
|
||||
@@ -15,6 +15,9 @@ public class CaptchaVo {
|
||||
*/
|
||||
private Boolean captchaEnabled = true;
|
||||
|
||||
/**
|
||||
* 验证码唯一标识。
|
||||
*/
|
||||
private String uuid;
|
||||
|
||||
/**
|
||||
|
||||
@@ -3,7 +3,7 @@ package org.dromara.web.domain.vo;
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* 登录租户对象
|
||||
* 登录页租户信息返回对象。
|
||||
*
|
||||
* @author Michelle.Chung
|
||||
*/
|
||||
|
||||
@@ -4,7 +4,7 @@ import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* 登录验证信息
|
||||
* 登录成功后的令牌信息返回对象。
|
||||
*
|
||||
* @author Michelle.Chung
|
||||
*/
|
||||
|
||||
@@ -22,7 +22,7 @@ import org.springframework.stereotype.Component;
|
||||
import java.time.Duration;
|
||||
|
||||
/**
|
||||
* 用户行为 侦听器的实现
|
||||
* 用户行为监听器,用于同步在线状态和登录日志。
|
||||
*
|
||||
* @author Lion Li
|
||||
*/
|
||||
@@ -34,7 +34,7 @@ public class UserActionListener implements SaTokenListener {
|
||||
private final SysLoginService loginService;
|
||||
|
||||
/**
|
||||
* 每次登录时触发
|
||||
* 登录成功后记录在线信息并写入登录日志。
|
||||
*/
|
||||
@Override
|
||||
public void doLogin(String loginType, Object loginId, String tokenValue, SaLoginParameter loginParameter) {
|
||||
@@ -71,7 +71,7 @@ public class UserActionListener implements SaTokenListener {
|
||||
}
|
||||
|
||||
/**
|
||||
* 每次注销时触发
|
||||
* 注销时清理在线缓存。
|
||||
*/
|
||||
@Override
|
||||
public void doLogout(String loginType, Object loginId, String tokenValue) {
|
||||
@@ -80,7 +80,7 @@ public class UserActionListener implements SaTokenListener {
|
||||
}
|
||||
|
||||
/**
|
||||
* 每次被踢下线时触发
|
||||
* 被踢下线时清理在线缓存。
|
||||
*/
|
||||
@Override
|
||||
public void doKickout(String loginType, Object loginId, String tokenValue) {
|
||||
@@ -89,7 +89,7 @@ public class UserActionListener implements SaTokenListener {
|
||||
}
|
||||
|
||||
/**
|
||||
* 每次被顶下线时触发
|
||||
* 被顶下线时清理在线缓存。
|
||||
*/
|
||||
@Override
|
||||
public void doReplaced(String loginType, Object loginId, String tokenValue) {
|
||||
|
||||
@@ -39,7 +39,7 @@ public interface IAuthStrategy {
|
||||
*
|
||||
* @param body 登录对象
|
||||
* @param client 授权管理视图对象
|
||||
* @return 登录验证信息
|
||||
* @return 当前策略完成认证后的登录结果
|
||||
*/
|
||||
LoginVo login(String body, SysClientVo client);
|
||||
|
||||
|
||||
@@ -136,7 +136,10 @@ public class SysLoginService {
|
||||
}
|
||||
|
||||
/**
|
||||
* 构建登录用户
|
||||
* 根据用户视图对象组装登录态上下文。
|
||||
*
|
||||
* @param user 用户基础信息
|
||||
* @return 包含部门、角色、岗位与权限数据的登录用户
|
||||
*/
|
||||
public LoginUser buildLoginUser(SysUserVo user) {
|
||||
LoginUser loginUser = new LoginUser();
|
||||
@@ -168,9 +171,10 @@ public class SysLoginService {
|
||||
}
|
||||
|
||||
/**
|
||||
* 记录登录信息
|
||||
* 更新用户最近一次登录IP与登录时间。
|
||||
*
|
||||
* @param userId 用户ID
|
||||
* @param ip 登录IP
|
||||
*/
|
||||
public void recordLoginInfo(Long userId, String ip) {
|
||||
SysUser sysUser = new SysUser();
|
||||
@@ -182,7 +186,11 @@ public class SysLoginService {
|
||||
}
|
||||
|
||||
/**
|
||||
* 登录校验
|
||||
* 执行登录失败次数校验,并在成功后清空失败计数。
|
||||
*
|
||||
* @param loginType 登录类型
|
||||
* @param username 登录标识
|
||||
* @param supplier 返回 {@code true} 表示本次认证失败
|
||||
*/
|
||||
public void checkLogin(LoginType loginType, String username, Supplier<Boolean> supplier) {
|
||||
String errorKey = CacheConstants.PWD_ERR_CNT_KEY + username;
|
||||
|
||||
@@ -38,6 +38,8 @@ public class SysRegisterService {
|
||||
|
||||
/**
|
||||
* 注册
|
||||
*
|
||||
* @param registerBody 注册请求参数
|
||||
*/
|
||||
public void register(RegisterBody registerBody) {
|
||||
String username = registerBody.getUsername();
|
||||
@@ -95,7 +97,6 @@ public class SysRegisterService {
|
||||
* @param username 用户名
|
||||
* @param status 状态
|
||||
* @param message 消息内容
|
||||
* @return
|
||||
*/
|
||||
private void recordLoginInfo(String username, String status, String message) {
|
||||
LoginInfoEvent loginInfoEvent = new LoginInfoEvent();
|
||||
|
||||
@@ -42,6 +42,13 @@ public class EmailAuthStrategy implements IAuthStrategy {
|
||||
private final SysLoginService loginService;
|
||||
private final SysUserMapper userMapper;
|
||||
|
||||
/**
|
||||
* 执行邮箱验证码登录,并按客户端配置生成访问令牌。
|
||||
*
|
||||
* @param body 登录请求体
|
||||
* @param client 当前客户端配置
|
||||
* @return 登录结果
|
||||
*/
|
||||
@Override
|
||||
public LoginVo login(String body, SysClientVo client) {
|
||||
EmailLoginBody loginBody = JsonUtils.parseObject(body, EmailLoginBody.class);
|
||||
@@ -72,7 +79,11 @@ public class EmailAuthStrategy implements IAuthStrategy {
|
||||
}
|
||||
|
||||
/**
|
||||
* 校验邮箱验证码
|
||||
* 校验邮箱验证码是否存在且匹配。
|
||||
*
|
||||
* @param email 邮箱地址
|
||||
* @param emailCode 用户输入的邮箱验证码
|
||||
* @return 是否校验通过
|
||||
*/
|
||||
private boolean validateEmailCode(String email, String emailCode) {
|
||||
String code = RedisUtils.getCacheObject(GlobalConstants.CAPTCHA_CODE_KEY + email);
|
||||
@@ -83,6 +94,12 @@ public class EmailAuthStrategy implements IAuthStrategy {
|
||||
return code.equals(emailCode);
|
||||
}
|
||||
|
||||
/**
|
||||
* 按邮箱加载可登录用户,并校验是否存在或被停用。
|
||||
*
|
||||
* @param email 邮箱地址
|
||||
* @return 用户信息
|
||||
*/
|
||||
private SysUserVo loadUserByEmail(String email) {
|
||||
SysUserVo user = userMapper.selectVoOne(new LambdaQueryWrapper<SysUser>().eq(SysUser::getEmail, email));
|
||||
if (ObjectUtil.isNull(user)) {
|
||||
|
||||
@@ -46,6 +46,13 @@ public class PasswordAuthStrategy implements IAuthStrategy {
|
||||
private final SysLoginService loginService;
|
||||
private final SysUserMapper userMapper;
|
||||
|
||||
/**
|
||||
* 执行账号密码登录,并按客户端配置生成访问令牌。
|
||||
*
|
||||
* @param body 登录请求体
|
||||
* @param client 当前客户端配置
|
||||
* @return 登录结果
|
||||
*/
|
||||
@Override
|
||||
public LoginVo login(String body, SysClientVo client) {
|
||||
PasswordLoginBody loginBody = JsonUtils.parseObject(body, PasswordLoginBody.class);
|
||||
@@ -84,11 +91,11 @@ public class PasswordAuthStrategy implements IAuthStrategy {
|
||||
}
|
||||
|
||||
/**
|
||||
* 校验验证码
|
||||
* 校验图形验证码是否有效且匹配。
|
||||
*
|
||||
* @param username 用户名
|
||||
* @param code 验证码
|
||||
* @param uuid 唯一标识
|
||||
* @param code 用户输入的验证码
|
||||
* @param uuid 验证码缓存标识
|
||||
*/
|
||||
private void validateCaptcha(String username, String code, String uuid) {
|
||||
String verifyKey = GlobalConstants.CAPTCHA_CODE_KEY + StringUtils.blankToDefault(uuid, "");
|
||||
@@ -104,6 +111,12 @@ public class PasswordAuthStrategy implements IAuthStrategy {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 按用户名加载可登录用户,并校验是否存在或被停用。
|
||||
*
|
||||
* @param username 用户名
|
||||
* @return 用户信息
|
||||
*/
|
||||
private SysUserVo loadUserByUsername(String username) {
|
||||
SysUserVo user = userMapper.selectVoOne(new LambdaQueryWrapper<SysUser>().eq(SysUser::getUserName, username));
|
||||
if (ObjectUtil.isNull(user)) {
|
||||
|
||||
@@ -42,6 +42,13 @@ public class SmsAuthStrategy implements IAuthStrategy {
|
||||
private final SysLoginService loginService;
|
||||
private final SysUserMapper userMapper;
|
||||
|
||||
/**
|
||||
* 执行短信验证码登录,并按客户端配置生成访问令牌。
|
||||
*
|
||||
* @param body 登录请求体
|
||||
* @param client 当前客户端配置
|
||||
* @return 登录结果
|
||||
*/
|
||||
@Override
|
||||
public LoginVo login(String body, SysClientVo client) {
|
||||
SmsLoginBody loginBody = JsonUtils.parseObject(body, SmsLoginBody.class);
|
||||
@@ -72,7 +79,11 @@ public class SmsAuthStrategy implements IAuthStrategy {
|
||||
}
|
||||
|
||||
/**
|
||||
* 校验短信验证码
|
||||
* 校验短信验证码是否存在且匹配。
|
||||
*
|
||||
* @param phonenumber 手机号
|
||||
* @param smsCode 用户输入的短信验证码
|
||||
* @return 是否校验通过
|
||||
*/
|
||||
private boolean validateSmsCode(String phonenumber, String smsCode) {
|
||||
String code = RedisUtils.getCacheObject(GlobalConstants.CAPTCHA_CODE_KEY + phonenumber);
|
||||
@@ -83,6 +94,12 @@ public class SmsAuthStrategy implements IAuthStrategy {
|
||||
return code.equals(smsCode);
|
||||
}
|
||||
|
||||
/**
|
||||
* 按手机号加载可登录用户,并校验是否存在或被停用。
|
||||
*
|
||||
* @param phonenumber 手机号
|
||||
* @return 用户信息
|
||||
*/
|
||||
private SysUserVo loadUserByPhonenumber(String phonenumber) {
|
||||
SysUserVo user = userMapper.selectVoOne(new LambdaQueryWrapper<SysUser>().eq(SysUser::getPhonenumber, phonenumber));
|
||||
if (ObjectUtil.isNull(user)) {
|
||||
|
||||
@@ -46,10 +46,11 @@ public class SocialAuthStrategy implements IAuthStrategy {
|
||||
private final SysLoginService loginService;
|
||||
|
||||
/**
|
||||
* 登录-第三方授权登录
|
||||
* 执行第三方授权登录,并校验授权账号与系统账号的绑定关系。
|
||||
*
|
||||
* @param body 登录信息
|
||||
* @param client 客户端信息
|
||||
* @return 登录结果
|
||||
*/
|
||||
@Override
|
||||
public LoginVo login(String body, SysClientVo client) {
|
||||
@@ -89,6 +90,12 @@ public class SocialAuthStrategy implements IAuthStrategy {
|
||||
return loginVo;
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据用户ID加载用户,并校验账号状态是否允许登录。
|
||||
*
|
||||
* @param userId 用户ID
|
||||
* @return 用户信息
|
||||
*/
|
||||
private SysUserVo loadUser(Long userId) {
|
||||
SysUserVo user = userMapper.selectVoById(userId);
|
||||
if (ObjectUtil.isNull(user)) {
|
||||
|
||||
@@ -38,6 +38,13 @@ public class XcxAuthStrategy implements IAuthStrategy {
|
||||
|
||||
private final SysLoginService loginService;
|
||||
|
||||
/**
|
||||
* 执行微信小程序登录,并根据 openid 构建小程序用户登录态。
|
||||
*
|
||||
* @param body 登录请求体
|
||||
* @param client 当前客户端配置
|
||||
* @return 登录结果
|
||||
*/
|
||||
@Override
|
||||
public LoginVo login(String body, SysClientVo client) {
|
||||
XcxLoginBody loginBody = JsonUtils.parseObject(body, XcxLoginBody.class);
|
||||
@@ -93,6 +100,12 @@ public class XcxAuthStrategy implements IAuthStrategy {
|
||||
return loginVo;
|
||||
}
|
||||
|
||||
/**
|
||||
* 按 openid 查询小程序绑定用户。
|
||||
*
|
||||
* @param openid 小程序用户唯一标识
|
||||
* @return 绑定的系统用户信息
|
||||
*/
|
||||
private SysUserVo loadUserByOpenid(String openid) {
|
||||
// 使用 openid 查询绑定用户 如未绑定用户 则根据业务自行处理 例如 创建默认用户
|
||||
// todo 自行实现 userService.selectUserByOpenid(openid);
|
||||
|
||||
Reference in New Issue
Block a user