Compare commits
6 Commits
dev/dev
...
318309c770
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
318309c770 | ||
|
|
4f149263a5 | ||
| fecf9bcb61 | |||
|
|
190a57c855 | ||
| 278510aa21 | |||
| 91eb21aa84 |
@@ -4,6 +4,9 @@ services:
|
||||
build: .
|
||||
volumes:
|
||||
# 日志目录映射
|
||||
- ./log:/log
|
||||
- ./log:/app/log
|
||||
ports:
|
||||
- '10095:8080'
|
||||
- '10095:8080'
|
||||
networks:
|
||||
back_default:
|
||||
driver: bridge
|
||||
@@ -2,7 +2,6 @@ package com.aida.lanecarford.common.security;
|
||||
|
||||
import com.aida.lanecarford.common.security.config.JwtProperties;
|
||||
import com.aida.lanecarford.common.security.context.UserContext;
|
||||
import com.aida.lanecarford.exception.BusinessException;
|
||||
import com.aida.lanecarford.util.CacheUtil;
|
||||
import com.aida.lanecarford.vo.AuthPrincipalVO;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
@@ -25,7 +24,7 @@ public class JwtInterceptor implements HandlerInterceptor {
|
||||
private final JwtProperties jwtProperties;
|
||||
|
||||
@Override
|
||||
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
|
||||
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) {
|
||||
if ("OPTIONS".equalsIgnoreCase(request.getMethod())) {
|
||||
return true;
|
||||
}
|
||||
@@ -41,7 +40,8 @@ public class JwtInterceptor implements HandlerInterceptor {
|
||||
String extracted = jwtUtil.extractUserinfo(jwtToken);
|
||||
if (StringUtil.isNullOrEmpty(extracted)) {
|
||||
log.warn("TOKEN已过期,请重新登录!(token without userInfo)");
|
||||
throw new BusinessException("Token has expired, please log in again.");
|
||||
response.setStatus(HttpServletResponse.SC_UNAUTHORIZED);
|
||||
// throw new BusinessException("Token has expired, please log in again.");
|
||||
}
|
||||
|
||||
AuthPrincipalVO authPrincipalVO = JSONObject.parseObject(extracted, AuthPrincipalVO.class);
|
||||
@@ -54,10 +54,12 @@ public class JwtInterceptor implements HandlerInterceptor {
|
||||
|
||||
if (Objects.isNull(token)) {
|
||||
log.warn("TOKEN已过期,请重新登录!(local cache empty)");
|
||||
throw new BusinessException("Token has expired, please log in again.");
|
||||
response.setStatus(HttpServletResponse.SC_UNAUTHORIZED);
|
||||
// throw new BusinessException("Token has expired, please log in again.");
|
||||
} else if (!token.toString().equals(jwtToken)) {
|
||||
log.warn("TOKEN已过期,请重新登录!(token not match local cache)");
|
||||
throw new BusinessException("Token has expired, please log in again.");
|
||||
response.setStatus(HttpServletResponse.SC_UNAUTHORIZED);
|
||||
// throw new BusinessException("Token has expired, please log in again.");
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -121,4 +121,12 @@ public class LoginController {
|
||||
return ApiResponse.success(loginService.parseGoogleAccessToken(accessToken));
|
||||
}
|
||||
|
||||
//修改用户信息
|
||||
@Operation(summary = "修改用户信息",
|
||||
description = "传username,email,password三个值,password要加密")
|
||||
@PostMapping("/updateUserInfo")
|
||||
public ApiResponse<String> updateUserInfo(@RequestBody User user) {
|
||||
return ApiResponse.success(loginService.updateUserInfo(user));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -36,4 +36,6 @@ public interface LoginService extends IService<User> {
|
||||
LoginVO parseGoogleCredential(String credential) throws ParseException, JOSEException, IOException;
|
||||
|
||||
LoginVO parseGoogleAccessToken(String accessToken);
|
||||
|
||||
String updateUserInfo(User user);
|
||||
}
|
||||
|
||||
@@ -108,6 +108,8 @@ public class CustomerServiceImpl extends ServiceImpl<CustomerMapper, Customer> i
|
||||
customer.setCreatedTime(LocalDateTime.now());
|
||||
|
||||
save(customer);
|
||||
} else {
|
||||
throw new BusinessException("VIP ID'" + vipId + "' already exists.Please proceed directly to check-in.");
|
||||
}
|
||||
|
||||
return customer;
|
||||
|
||||
@@ -353,6 +353,66 @@ public class LoginServiceImpl extends ServiceImpl<UserMapper, User> implements L
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String updateUserInfo(User user) {
|
||||
// 1. 获取当前登录用户ID
|
||||
AuthPrincipalVO userHolder = UserContext.getUserHolder();
|
||||
if (Objects.isNull(userHolder)) {
|
||||
throw new BusinessException("User not logged in", "用户未登录", ResultEnum.ERROR.getCode());
|
||||
}
|
||||
|
||||
Long userId = userHolder.getId();
|
||||
|
||||
// 2. 验证用户是否存在
|
||||
User existingUser = getById(userId);
|
||||
if (Objects.isNull(existingUser)) {
|
||||
throw new BusinessException("User not found", "用户不存在", ResultEnum.ERROR.getCode());
|
||||
}
|
||||
|
||||
// 3. 构建更新条件,只更新有值的字段
|
||||
UpdateWrapper<User> updateWrapper = new UpdateWrapper<>();
|
||||
updateWrapper.lambda().eq(User::getId, userId);
|
||||
|
||||
boolean hasUpdate = false;
|
||||
|
||||
// 如果username有值,则更新
|
||||
if (!StringUtil.isNullOrEmpty(user.getUsername())) {
|
||||
updateWrapper.lambda().set(User::getUsername, user.getUsername());
|
||||
hasUpdate = true;
|
||||
}
|
||||
|
||||
// 如果email有值,则更新
|
||||
if (!StringUtil.isNullOrEmpty(user.getEmail())) {
|
||||
updateWrapper.lambda().set(User::getEmail, user.getEmail());
|
||||
hasUpdate = true;
|
||||
}
|
||||
|
||||
// 如果password有值,则更新
|
||||
if (!StringUtil.isNullOrEmpty(user.getPassword())) {
|
||||
updateWrapper.lambda().set(User::getPassword, user.getPassword());
|
||||
hasUpdate = true;
|
||||
}
|
||||
|
||||
// 4. 如果没有需要更新的字段,返回提示信息
|
||||
if (!hasUpdate) {
|
||||
return "No fields to update";
|
||||
}
|
||||
|
||||
// 5. 执行更新
|
||||
boolean updated = update(updateWrapper);
|
||||
|
||||
if (updated) {
|
||||
log.info("用户信息更新成功 userId={}, updatedFields=username:{}, email:{}, password:{}",
|
||||
userId,
|
||||
!StringUtil.isNullOrEmpty(user.getUsername()),
|
||||
!StringUtil.isNullOrEmpty(user.getEmail()),
|
||||
!StringUtil.isNullOrEmpty(user.getPassword()));
|
||||
return "User information updated successfully";
|
||||
} else {
|
||||
throw new BusinessException("Failed to update user information", "更新用户信息失败", ResultEnum.ERROR.getCode());
|
||||
}
|
||||
}
|
||||
|
||||
private static final String TOKEN_URL = "https://oauth2.googleapis.com/token";
|
||||
|
||||
public GoogleUser getGoogleUserFromCode(String code) {
|
||||
|
||||
Reference in New Issue
Block a user