feat(oss): 增加对象存储模块并支持多种存储策略

- 新增对象存储服务模块 `han-note-oss`,集成 Rustfs、阿里云 OSS 及腾讯云 Cos 存储
- 提供统一的 `FileStrategy` 接口及 `FileStrategyFactory` 工厂类,根据存储类型动态选择存储策略
- 实现阿里云 OSS、腾讯云 Cos 和 Rustfs 具体存储逻辑
- 增加文件上传接口 `FileController`,支持接收文件并返回访问路径
- 完成用户密码更新接口,使用`spring.security`对密码进行加密
This commit is contained in:
Hanserwei
2025-10-03 17:52:25 +08:00
parent 5c406b48f9
commit 0d71d8e209
33 changed files with 974 additions and 1 deletions

View File

@@ -3,6 +3,7 @@ package com.hanserwei.hannote.auth.service;
import com.baomidou.mybatisplus.extension.service.IService;
import com.hanserwei.framework.common.response.Response;
import com.hanserwei.hannote.auth.domain.dataobject.UserDO;
import com.hanserwei.hannote.auth.model.vo.user.UpdatePasswordReqVO;
import com.hanserwei.hannote.auth.model.vo.user.UserLoginReqVO;
public interface UserService extends IService<UserDO> {
@@ -20,4 +21,11 @@ public interface UserService extends IService<UserDO> {
* @return 响应结果
*/
Response<?> logout();
/**
* 修改密码
* @param updatePasswordReqVO 请求参数
* @return 响应结果
*/
Response<?> updatePassword(UpdatePasswordReqVO updatePasswordReqVO);
}

View File

@@ -22,6 +22,7 @@ import com.hanserwei.hannote.auth.domain.mapper.UserDOMapper;
import com.hanserwei.hannote.auth.domain.mapper.UserRoleDOMapper;
import com.hanserwei.hannote.auth.enums.LoginTypeEnum;
import com.hanserwei.hannote.auth.enums.ResponseCodeEnum;
import com.hanserwei.hannote.auth.model.vo.user.UpdatePasswordReqVO;
import com.hanserwei.hannote.auth.model.vo.user.UserLoginReqVO;
import com.hanserwei.hannote.auth.service.UserService;
import jakarta.annotation.Resource;
@@ -30,6 +31,7 @@ import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
import org.springframework.security.crypto.password.PasswordEncoder;
import org.springframework.stereotype.Service;
import org.springframework.transaction.support.TransactionTemplate;
@@ -50,6 +52,7 @@ public class UserServiceImpl extends ServiceImpl<UserDOMapper, UserDO> implement
private final RoleDOMapper roleDOMapper;
@Resource(name = "authTaskExecutor")
private ThreadPoolTaskExecutor authTaskExecutor;
private final PasswordEncoder passwordEncoder;
@Override
public Response<String> loginAndRegister(UserLoginReqVO reqVO) {
@@ -87,6 +90,19 @@ public class UserServiceImpl extends ServiceImpl<UserDOMapper, UserDO> implement
}
break;
case PASSWORD:
String password = reqVO.getPassword();
// 根据邮箱号查询
UserDO userDO1 = this.getOne(new QueryWrapper<UserDO>().eq("email", email));
if (Objects.isNull(userDO1)){
throw new ApiException(ResponseCodeEnum.USER_NOT_FOUND);
}
// 拿到密文密码
String encodePassword = userDO1.getPassword();
boolean isPasswordCorrect = passwordEncoder.matches(password, encodePassword);
if (!isPasswordCorrect) {
throw new ApiException(ResponseCodeEnum.MAIL_OR_PASSWORD_ERROR);
}
userId = userDO1.getId();
break;
default:
break;
@@ -158,4 +174,23 @@ public class UserServiceImpl extends ServiceImpl<UserDOMapper, UserDO> implement
StpUtil.logout(userId);
return Response.success();
}
@Override
public Response<?> updatePassword(UpdatePasswordReqVO updatePasswordReqVO) {
// 新密码
String newPassword = updatePasswordReqVO.getNewPassword();
// 加密后的密码
String encodePassword = passwordEncoder.encode(newPassword);
// 获取用户ID
Long userId = LoginUserContextHolder.getUserId();
UserDO userDO = UserDO.builder()
.id(userId)
.password(encodePassword)
.updateTime(LocalDateTime.now())
.build();
// 更新用户密码
this.updateById(userDO);
return Response.success();
}
}