文件生成补充
This commit is contained in:
+62
@@ -0,0 +1,62 @@
|
||||
package fun.nojava.module.system.controller;
|
||||
|
||||
import fun.nojava.common.annotation.RateLimit;
|
||||
import fun.nojava.common.model.ApiResult;
|
||||
import fun.nojava.framework.util.WebUtils;
|
||||
import fun.nojava.module.system.dto.LoginDTO;
|
||||
import fun.nojava.module.system.dto.LoginVO;
|
||||
import fun.nojava.module.system.dto.RegisterDTO;
|
||||
import fun.nojava.module.system.service.AuthService;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import jakarta.validation.Valid;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
@Tag(name = "认证接口")
|
||||
@RestController
|
||||
@RequestMapping("/api/auth")
|
||||
@RequiredArgsConstructor
|
||||
public class AuthController {
|
||||
|
||||
private final AuthService authService;
|
||||
|
||||
@Operation(summary = "用户登录")
|
||||
@PostMapping("/login")
|
||||
@RateLimit(key = "login", maxCount = 5, duration = 60)
|
||||
public ApiResult<LoginVO> login(@Valid @RequestBody LoginDTO dto) {
|
||||
LoginVO vo = authService.login(dto, WebUtils.getClientIp(), WebUtils.getUserAgent());
|
||||
return ApiResult.success(vo);
|
||||
}
|
||||
|
||||
@Operation(summary = "管理员登录")
|
||||
@PostMapping("/admin/login")
|
||||
@RateLimit(key = "admin_login", maxCount = 5, duration = 60)
|
||||
public ApiResult<LoginVO> adminLogin(@Valid @RequestBody LoginDTO dto) {
|
||||
LoginVO vo = authService.adminLogin(dto, WebUtils.getClientIp(), WebUtils.getUserAgent());
|
||||
return ApiResult.success(vo);
|
||||
}
|
||||
|
||||
@Operation(summary = "用户注册")
|
||||
@PostMapping("/register")
|
||||
@RateLimit(key = "register", maxCount = 3, duration = 3600)
|
||||
public ApiResult<Void> register(@Valid @RequestBody RegisterDTO dto) {
|
||||
authService.register(dto);
|
||||
return ApiResult.success();
|
||||
}
|
||||
|
||||
@Operation(summary = "刷新Token")
|
||||
@PostMapping("/refresh")
|
||||
public ApiResult<LoginVO> refreshToken(@RequestHeader("Refresh-Token") String refreshToken) {
|
||||
LoginVO vo = authService.refreshToken(refreshToken);
|
||||
return ApiResult.success(vo);
|
||||
}
|
||||
|
||||
@Operation(summary = "退出登录")
|
||||
@PostMapping("/logout")
|
||||
public ApiResult<Void> logout(@RequestHeader("Authorization") String authHeader) {
|
||||
String token = authHeader.replace("Bearer ", "");
|
||||
authService.logout(token);
|
||||
return ApiResult.success();
|
||||
}
|
||||
}
|
||||
+64
@@ -0,0 +1,64 @@
|
||||
package fun.nojava.module.system.controller;
|
||||
|
||||
import fun.nojava.common.model.ApiResult;
|
||||
import fun.nojava.common.model.PageResult;
|
||||
import fun.nojava.module.system.dto.UserInfoVO;
|
||||
import fun.nojava.module.system.service.UserService;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.security.core.annotation.AuthenticationPrincipal;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
@Tag(name = "用户接口")
|
||||
@RestController
|
||||
@RequestMapping("/api/user")
|
||||
@RequiredArgsConstructor
|
||||
public class UserController {
|
||||
|
||||
private final UserService userService;
|
||||
|
||||
@Operation(summary = "获取当前用户信息")
|
||||
@GetMapping("/info")
|
||||
public ApiResult<UserInfoVO> getCurrentUser(@AuthenticationPrincipal Long userId) {
|
||||
return ApiResult.success(userService.getUserInfo(userId));
|
||||
}
|
||||
|
||||
@Operation(summary = "获取用户信息")
|
||||
@GetMapping("/{id}")
|
||||
public ApiResult<UserInfoVO> getUserInfo(@PathVariable Long id) {
|
||||
return ApiResult.success(userService.getUserInfo(id));
|
||||
}
|
||||
}
|
||||
|
||||
@Tag(name = "管理员-用户管理")
|
||||
@RestController
|
||||
@RequestMapping("/api/admin/user")
|
||||
@RequiredArgsConstructor
|
||||
class AdminUserController {
|
||||
|
||||
private final UserService userService;
|
||||
|
||||
@Operation(summary = "用户列表")
|
||||
@GetMapping("/list")
|
||||
public ApiResult<PageResult<UserInfoVO>> listUsers(
|
||||
@RequestParam(defaultValue = "1") int page,
|
||||
@RequestParam(defaultValue = "15") int pageSize,
|
||||
@RequestParam(required = false) String keyword) {
|
||||
return ApiResult.success(userService.listUsers(page, pageSize, keyword));
|
||||
}
|
||||
|
||||
@Operation(summary = "重置密码")
|
||||
@PostMapping("/{id}/reset-password")
|
||||
public ApiResult<Void> resetPassword(@PathVariable Long id, @RequestParam String newPassword) {
|
||||
userService.resetPassword(id, newPassword);
|
||||
return ApiResult.success();
|
||||
}
|
||||
|
||||
@Operation(summary = "更新状态")
|
||||
@PostMapping("/{id}/status")
|
||||
public ApiResult<Void> updateStatus(@PathVariable Long id, @RequestParam int status) {
|
||||
userService.updateUserStatus(id, status);
|
||||
return ApiResult.success();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
package fun.nojava.module.system.dto;
|
||||
|
||||
import jakarta.validation.constraints.Email;
|
||||
import jakarta.validation.constraints.NotBlank;
|
||||
import jakarta.validation.constraints.Size;
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
public class LoginDTO {
|
||||
|
||||
@NotBlank(message = "邮箱不能为空")
|
||||
@Email(message = "邮箱格式不正确")
|
||||
private String email;
|
||||
|
||||
@NotBlank(message = "密码不能为空")
|
||||
@Size(min = 6, max = 20, message = "密码长度6-20位")
|
||||
private String password;
|
||||
|
||||
private Boolean rememberMe = false;
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
package fun.nojava.module.system.dto;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
@Data
|
||||
@Builder
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
public class LoginVO {
|
||||
|
||||
private Long userId;
|
||||
|
||||
private String email;
|
||||
|
||||
private String nickname;
|
||||
|
||||
private String avatar;
|
||||
|
||||
private Integer type;
|
||||
|
||||
private String accessToken;
|
||||
|
||||
private String refreshToken;
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
package fun.nojava.module.system.dto;
|
||||
|
||||
import jakarta.validation.constraints.Email;
|
||||
import jakarta.validation.constraints.NotBlank;
|
||||
import jakarta.validation.constraints.Size;
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
public class RegisterDTO {
|
||||
|
||||
@NotBlank(message = "邮箱不能为空")
|
||||
@Email(message = "邮箱格式不正确")
|
||||
private String email;
|
||||
|
||||
@NotBlank(message = "密码不能为空")
|
||||
@Size(min = 6, max = 20, message = "密码长度6-20位")
|
||||
private String password;
|
||||
|
||||
@NotBlank(message = "昵称不能为空")
|
||||
@Size(max = 50, message = "昵称最长50字符")
|
||||
private String nickname;
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
package fun.nojava.module.system.dto;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
@Data
|
||||
@Builder
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
public class UserInfoVO {
|
||||
|
||||
private Long id;
|
||||
|
||||
private String email;
|
||||
|
||||
private String nickname;
|
||||
|
||||
private String avatar;
|
||||
|
||||
private String bio;
|
||||
|
||||
private Integer type;
|
||||
|
||||
private Integer status;
|
||||
|
||||
private Integer articleCount;
|
||||
|
||||
private Integer followerCount;
|
||||
|
||||
private Integer followingCount;
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
package fun.nojava.module.system.entity;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.*;
|
||||
import lombok.Data;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
@Data
|
||||
@TableName("login_log")
|
||||
public class LoginLog {
|
||||
|
||||
@TableId(type = IdType.AUTO)
|
||||
private Long id;
|
||||
|
||||
private Long userId;
|
||||
|
||||
private String email;
|
||||
|
||||
private Integer loginType;
|
||||
|
||||
private String ipAddress;
|
||||
|
||||
private String userAgent;
|
||||
|
||||
private Integer status;
|
||||
|
||||
private String failReason;
|
||||
|
||||
@TableField(fill = FieldFill.INSERT)
|
||||
private LocalDateTime createdAt;
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
package fun.nojava.module.system.entity;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.*;
|
||||
import lombok.Data;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
@Data
|
||||
@TableName("user")
|
||||
public class User {
|
||||
|
||||
@TableId(type = IdType.AUTO)
|
||||
private Long id;
|
||||
|
||||
private String email;
|
||||
|
||||
private String password;
|
||||
|
||||
private String nickname;
|
||||
|
||||
private String avatar;
|
||||
|
||||
private String bio;
|
||||
|
||||
private Integer type;
|
||||
|
||||
private Integer status;
|
||||
|
||||
@TableField(fill = FieldFill.INSERT)
|
||||
private LocalDateTime createdAt;
|
||||
|
||||
@TableField(fill = FieldFill.INSERT_UPDATE)
|
||||
private LocalDateTime updatedAt;
|
||||
|
||||
@TableLogic
|
||||
private Integer deleted;
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
package fun.nojava.module.system.entity;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.*;
|
||||
import lombok.Data;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
@Data
|
||||
@TableName("user_session")
|
||||
public class UserSession {
|
||||
|
||||
@TableId(type = IdType.AUTO)
|
||||
private Long id;
|
||||
|
||||
private Long userId;
|
||||
|
||||
private String refreshToken;
|
||||
|
||||
private String deviceInfo;
|
||||
|
||||
private String ipAddress;
|
||||
|
||||
private LocalDateTime expiresAt;
|
||||
|
||||
@TableField(fill = FieldFill.INSERT)
|
||||
private LocalDateTime createdAt;
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
package fun.nojava.module.system.mapper;
|
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import fun.nojava.module.system.entity.LoginLog;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
|
||||
@Mapper
|
||||
public interface LoginLogMapper extends BaseMapper<LoginLog> {
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
package fun.nojava.module.system.mapper;
|
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import fun.nojava.module.system.entity.User;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
|
||||
@Mapper
|
||||
public interface UserMapper extends BaseMapper<User> {
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
package fun.nojava.module.system.mapper;
|
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import fun.nojava.module.system.entity.UserSession;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
|
||||
@Mapper
|
||||
public interface UserSessionMapper extends BaseMapper<UserSession> {
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
package fun.nojava.module.system.service;
|
||||
|
||||
import fun.nojava.module.system.dto.LoginDTO;
|
||||
import fun.nojava.module.system.dto.LoginVO;
|
||||
import fun.nojava.module.system.dto.RegisterDTO;
|
||||
|
||||
public interface AuthService {
|
||||
|
||||
LoginVO login(LoginDTO dto, String ipAddress, String userAgent);
|
||||
|
||||
LoginVO adminLogin(LoginDTO dto, String ipAddress, String userAgent);
|
||||
|
||||
void register(RegisterDTO dto);
|
||||
|
||||
LoginVO refreshToken(String refreshToken);
|
||||
|
||||
void logout(String accessToken);
|
||||
|
||||
void logoutAll(Long userId);
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
package fun.nojava.module.system.service;
|
||||
|
||||
import fun.nojava.common.model.PageResult;
|
||||
import fun.nojava.module.system.dto.UserInfoVO;
|
||||
import fun.nojava.module.system.entity.User;
|
||||
|
||||
public interface UserService {
|
||||
|
||||
UserInfoVO getUserInfo(Long userId);
|
||||
|
||||
User getById(Long id);
|
||||
|
||||
PageResult<UserInfoVO> listUsers(int page, int pageSize, String keyword);
|
||||
|
||||
void resetPassword(Long userId, String newPassword);
|
||||
|
||||
void updateUserStatus(Long userId, int status);
|
||||
|
||||
boolean isFollowing(Long followerId, Long followeeId);
|
||||
|
||||
void follow(Long followerId, Long followeeId);
|
||||
|
||||
void unfollow(Long followerId, Long followeeId);
|
||||
}
|
||||
+171
@@ -0,0 +1,171 @@
|
||||
package fun.nojava.module.system.service.impl;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import fun.nojava.common.enums.UserStatus;
|
||||
import fun.nojava.common.enums.UserType;
|
||||
import fun.nojava.common.exception.BusinessException;
|
||||
import fun.nojava.common.exception.ErrorCode;
|
||||
import fun.nojava.framework.security.JwtTokenProvider;
|
||||
import fun.nojava.framework.security.TokenBlacklistService;
|
||||
import fun.nojava.module.system.dto.LoginDTO;
|
||||
import fun.nojava.module.system.dto.LoginVO;
|
||||
import fun.nojava.module.system.dto.RegisterDTO;
|
||||
import fun.nojava.module.system.entity.LoginLog;
|
||||
import fun.nojava.module.system.entity.User;
|
||||
import fun.nojava.module.system.entity.UserSession;
|
||||
import fun.nojava.module.system.mapper.LoginLogMapper;
|
||||
import fun.nojava.module.system.mapper.UserMapper;
|
||||
import fun.nojava.module.system.mapper.UserSessionMapper;
|
||||
import fun.nojava.module.system.service.AuthService;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.security.crypto.password.PasswordEncoder;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
@Service
|
||||
@RequiredArgsConstructor
|
||||
public class AuthServiceImpl implements AuthService {
|
||||
|
||||
private final UserMapper userMapper;
|
||||
private final LoginLogMapper loginLogMapper;
|
||||
private final UserSessionMapper userSessionMapper;
|
||||
private final PasswordEncoder passwordEncoder;
|
||||
private final JwtTokenProvider jwtTokenProvider;
|
||||
private final TokenBlacklistService tokenBlacklistService;
|
||||
|
||||
@Override
|
||||
@Transactional
|
||||
public LoginVO login(LoginDTO dto, String ipAddress, String userAgent) {
|
||||
User user = userMapper.selectOne(
|
||||
new LambdaQueryWrapper<User>().eq(User::getEmail, dto.getEmail())
|
||||
);
|
||||
|
||||
if (user == null) {
|
||||
recordLoginLog(null, dto.getEmail(), ipAddress, userAgent, 0, "用户不存在");
|
||||
throw new BusinessException(ErrorCode.USER_NOT_FOUND);
|
||||
}
|
||||
|
||||
if (user.getStatus() == UserStatus.LOCKED.getCode()) {
|
||||
recordLoginLog(user.getId(), dto.getEmail(), ipAddress, userAgent, 0, "账号已锁定");
|
||||
throw new BusinessException(ErrorCode.ACCOUNT_LOCKED);
|
||||
}
|
||||
|
||||
if (!passwordEncoder.matches(dto.getPassword(), user.getPassword())) {
|
||||
recordLoginLog(user.getId(), dto.getEmail(), ipAddress, userAgent, 0, "密码错误");
|
||||
throw new BusinessException(ErrorCode.PASSWORD_ERROR);
|
||||
}
|
||||
|
||||
recordLoginLog(user.getId(), dto.getEmail(), ipAddress, userAgent, 1, null);
|
||||
|
||||
return generateLoginVO(user, dto.getRememberMe());
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional
|
||||
public LoginVO adminLogin(LoginDTO dto, String ipAddress, String userAgent) {
|
||||
LoginVO loginVO = login(dto, ipAddress, userAgent);
|
||||
|
||||
User user = userMapper.selectById(loginVO.getUserId());
|
||||
if (user.getType() != UserType.ADMIN.getCode()) {
|
||||
throw new BusinessException(ErrorCode.PERMISSION_DENIED);
|
||||
}
|
||||
|
||||
return loginVO;
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional
|
||||
public void register(RegisterDTO dto) {
|
||||
Long count = userMapper.selectCount(
|
||||
new LambdaQueryWrapper<User>().eq(User::getEmail, dto.getEmail())
|
||||
);
|
||||
if (count > 0) {
|
||||
throw new BusinessException(ErrorCode.EMAIL_EXISTS);
|
||||
}
|
||||
|
||||
User user = new User();
|
||||
user.setEmail(dto.getEmail());
|
||||
user.setPassword(passwordEncoder.encode(dto.getPassword()));
|
||||
user.setNickname(dto.getNickname());
|
||||
user.setType(UserType.USER.getCode());
|
||||
user.setStatus(UserStatus.NORMAL.getCode());
|
||||
user.setDeleted(0);
|
||||
userMapper.insert(user);
|
||||
}
|
||||
|
||||
@Override
|
||||
public LoginVO refreshToken(String refreshToken) {
|
||||
if (!jwtTokenProvider.validateToken(refreshToken)) {
|
||||
throw new BusinessException(ErrorCode.TOKEN_INVALID);
|
||||
}
|
||||
|
||||
Long userId = jwtTokenProvider.getUserIdFromToken(refreshToken);
|
||||
User user = userMapper.selectById(userId);
|
||||
|
||||
if (user == null) {
|
||||
throw new BusinessException(ErrorCode.USER_NOT_FOUND);
|
||||
}
|
||||
|
||||
String accessToken = jwtTokenProvider.generateAccessToken(userId, user.getType());
|
||||
String newRefreshToken = jwtTokenProvider.generateRefreshToken(userId);
|
||||
|
||||
return LoginVO.builder()
|
||||
.userId(userId)
|
||||
.email(user.getEmail())
|
||||
.nickname(user.getNickname())
|
||||
.avatar(user.getAvatar())
|
||||
.type(user.getType())
|
||||
.accessToken(accessToken)
|
||||
.refreshToken(newRefreshToken)
|
||||
.build();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void logout(String accessToken) {
|
||||
tokenBlacklistService.addToBlacklist(accessToken);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void logoutAll(Long userId) {
|
||||
userSessionMapper.delete(
|
||||
new LambdaQueryWrapper<UserSession>().eq(UserSession::getUserId, userId)
|
||||
);
|
||||
}
|
||||
|
||||
private LoginVO generateLoginVO(User user, Boolean rememberMe) {
|
||||
String accessToken = jwtTokenProvider.generateAccessToken(user.getId(), user.getType());
|
||||
String refreshToken = jwtTokenProvider.generateRefreshToken(user.getId());
|
||||
|
||||
UserSession session = new UserSession();
|
||||
session.setUserId(user.getId());
|
||||
session.setRefreshToken(refreshToken);
|
||||
session.setExpiresAt(LocalDateTime.now().plusSeconds(
|
||||
rememberMe ? 1209600L : 86400L
|
||||
));
|
||||
userSessionMapper.insert(session);
|
||||
|
||||
return LoginVO.builder()
|
||||
.userId(user.getId())
|
||||
.email(user.getEmail())
|
||||
.nickname(user.getNickname())
|
||||
.avatar(user.getAvatar())
|
||||
.type(user.getType())
|
||||
.accessToken(accessToken)
|
||||
.refreshToken(refreshToken)
|
||||
.build();
|
||||
}
|
||||
|
||||
private void recordLoginLog(Long userId, String email, String ip, String ua, int status, String reason) {
|
||||
LoginLog log = new LoginLog();
|
||||
log.setUserId(userId);
|
||||
log.setEmail(email);
|
||||
log.setLoginType(1);
|
||||
log.setIpAddress(ip);
|
||||
log.setUserAgent(ua);
|
||||
log.setStatus(status);
|
||||
log.setFailReason(reason);
|
||||
loginLogMapper.insert(log);
|
||||
}
|
||||
}
|
||||
+106
@@ -0,0 +1,106 @@
|
||||
package fun.nojava.module.system.service.impl;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import fun.nojava.common.exception.BusinessException;
|
||||
import fun.nojava.common.exception.ErrorCode;
|
||||
import fun.nojava.common.model.PageResult;
|
||||
import fun.nojava.module.system.dto.UserInfoVO;
|
||||
import fun.nojava.module.system.entity.User;
|
||||
import fun.nojava.module.system.mapper.UserMapper;
|
||||
import fun.nojava.module.system.service.UserService;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.security.crypto.password.PasswordEncoder;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Service
|
||||
@RequiredArgsConstructor
|
||||
public class UserServiceImpl implements UserService {
|
||||
|
||||
private final UserMapper userMapper;
|
||||
private final PasswordEncoder passwordEncoder;
|
||||
|
||||
@Override
|
||||
public UserInfoVO getUserInfo(Long userId) {
|
||||
User user = userMapper.selectById(userId);
|
||||
if (user == null) {
|
||||
throw new BusinessException(ErrorCode.USER_NOT_FOUND);
|
||||
}
|
||||
|
||||
return UserInfoVO.builder()
|
||||
.id(user.getId())
|
||||
.email(user.getEmail())
|
||||
.nickname(user.getNickname())
|
||||
.avatar(user.getAvatar())
|
||||
.bio(user.getBio())
|
||||
.type(user.getType())
|
||||
.status(user.getStatus())
|
||||
.articleCount(0)
|
||||
.followerCount(0)
|
||||
.followingCount(0)
|
||||
.build();
|
||||
}
|
||||
|
||||
@Override
|
||||
public User getById(Long id) {
|
||||
return userMapper.selectById(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public PageResult<UserInfoVO> listUsers(int page, int pageSize, String keyword) {
|
||||
LambdaQueryWrapper<User> wrapper = new LambdaQueryWrapper<>();
|
||||
if (keyword != null && !keyword.isEmpty()) {
|
||||
wrapper.and(w -> w.like(User::getNickname, keyword).or().like(User::getEmail, keyword));
|
||||
}
|
||||
wrapper.orderByDesc(User::getCreatedAt);
|
||||
|
||||
Page<User> userPage = userMapper.selectPage(new Page<>(page, pageSize), wrapper);
|
||||
List<UserInfoVO> records = userPage.getRecords().stream()
|
||||
.map(u -> UserInfoVO.builder()
|
||||
.id(u.getId())
|
||||
.email(u.getEmail())
|
||||
.nickname(u.getNickname())
|
||||
.avatar(u.getAvatar())
|
||||
.type(u.getType())
|
||||
.status(u.getStatus())
|
||||
.build())
|
||||
.toList();
|
||||
|
||||
return new PageResult<>(records, userPage.getTotal(), page, pageSize);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void resetPassword(Long userId, String newPassword) {
|
||||
User user = userMapper.selectById(userId);
|
||||
if (user == null) {
|
||||
throw new BusinessException(ErrorCode.USER_NOT_FOUND);
|
||||
}
|
||||
user.setPassword(passwordEncoder.encode(newPassword));
|
||||
userMapper.updateById(user);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateUserStatus(Long userId, int status) {
|
||||
User user = userMapper.selectById(userId);
|
||||
if (user == null) {
|
||||
throw new BusinessException(ErrorCode.USER_NOT_FOUND);
|
||||
}
|
||||
user.setStatus(status);
|
||||
userMapper.updateById(user);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isFollowing(Long followerId, Long followeeId) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void follow(Long followerId, Long followeeId) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void unfollow(Long followerId, Long followeeId) {
|
||||
}
|
||||
}
|
||||
BIN
Binary file not shown.
BIN
Binary file not shown.
BIN
Binary file not shown.
Binary file not shown.
BIN
Binary file not shown.
Binary file not shown.
Binary file not shown.
BIN
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
BIN
Binary file not shown.
Binary file not shown.
Binary file not shown.
BIN
Binary file not shown.
BIN
Binary file not shown.
Binary file not shown.
@@ -0,0 +1,3 @@
|
||||
artifactId=jog-module-system
|
||||
groupId=fun.nojava
|
||||
version=1.0.0
|
||||
+19
@@ -0,0 +1,19 @@
|
||||
fun\nojava\module\system\dto\LoginVO$LoginVOBuilder.class
|
||||
fun\nojava\module\system\entity\LoginLog.class
|
||||
fun\nojava\module\system\controller\AdminUserController.class
|
||||
fun\nojava\module\system\service\impl\AuthServiceImpl.class
|
||||
fun\nojava\module\system\service\UserService.class
|
||||
fun\nojava\module\system\mapper\UserSessionMapper.class
|
||||
fun\nojava\module\system\controller\AuthController.class
|
||||
fun\nojava\module\system\dto\LoginDTO.class
|
||||
fun\nojava\module\system\dto\UserInfoVO$UserInfoVOBuilder.class
|
||||
fun\nojava\module\system\dto\UserInfoVO.class
|
||||
fun\nojava\module\system\mapper\UserMapper.class
|
||||
fun\nojava\module\system\dto\RegisterDTO.class
|
||||
fun\nojava\module\system\entity\User.class
|
||||
fun\nojava\module\system\entity\UserSession.class
|
||||
fun\nojava\module\system\service\AuthService.class
|
||||
fun\nojava\module\system\dto\LoginVO.class
|
||||
fun\nojava\module\system\service\impl\UserServiceImpl.class
|
||||
fun\nojava\module\system\controller\UserController.class
|
||||
fun\nojava\module\system\mapper\LoginLogMapper.class
|
||||
+16
@@ -0,0 +1,16 @@
|
||||
E:\person\Jog\jog-module-system\src\main\java\fun\nojava\module\system\controller\AuthController.java
|
||||
E:\person\Jog\jog-module-system\src\main\java\fun\nojava\module\system\controller\UserController.java
|
||||
E:\person\Jog\jog-module-system\src\main\java\fun\nojava\module\system\dto\LoginDTO.java
|
||||
E:\person\Jog\jog-module-system\src\main\java\fun\nojava\module\system\dto\LoginVO.java
|
||||
E:\person\Jog\jog-module-system\src\main\java\fun\nojava\module\system\dto\RegisterDTO.java
|
||||
E:\person\Jog\jog-module-system\src\main\java\fun\nojava\module\system\dto\UserInfoVO.java
|
||||
E:\person\Jog\jog-module-system\src\main\java\fun\nojava\module\system\entity\LoginLog.java
|
||||
E:\person\Jog\jog-module-system\src\main\java\fun\nojava\module\system\entity\User.java
|
||||
E:\person\Jog\jog-module-system\src\main\java\fun\nojava\module\system\entity\UserSession.java
|
||||
E:\person\Jog\jog-module-system\src\main\java\fun\nojava\module\system\mapper\LoginLogMapper.java
|
||||
E:\person\Jog\jog-module-system\src\main\java\fun\nojava\module\system\mapper\UserMapper.java
|
||||
E:\person\Jog\jog-module-system\src\main\java\fun\nojava\module\system\mapper\UserSessionMapper.java
|
||||
E:\person\Jog\jog-module-system\src\main\java\fun\nojava\module\system\service\AuthService.java
|
||||
E:\person\Jog\jog-module-system\src\main\java\fun\nojava\module\system\service\impl\AuthServiceImpl.java
|
||||
E:\person\Jog\jog-module-system\src\main\java\fun\nojava\module\system\service\impl\UserServiceImpl.java
|
||||
E:\person\Jog\jog-module-system\src\main\java\fun\nojava\module\system\service\UserService.java
|
||||
Reference in New Issue
Block a user