From f0cffe3e126511ef897538a6263a195ba7020696 Mon Sep 17 00:00:00 2001 From: tongtongstudio Date: Thu, 21 Aug 2025 19:05:20 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E6=89=8B=E6=9C=BA=E9=AA=8C?= =?UTF-8?q?=E8=AF=81=E7=A0=81=E6=B3=A8=E5=86=8C=20user=5Fid=E5=BC=82?= =?UTF-8?q?=E5=B8=B8=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/UserController.java | 2 + .../controller/UserPasswordController.java | 44 +++++++++++++++++++ .../videotablet/service/UserService.java | 11 ++++- 3 files changed, 56 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/onekeycall/videotablet/controller/UserController.java b/src/main/java/com/onekeycall/videotablet/controller/UserController.java index 88f1ae5..94f5bfe 100644 --- a/src/main/java/com/onekeycall/videotablet/controller/UserController.java +++ b/src/main/java/com/onekeycall/videotablet/controller/UserController.java @@ -64,6 +64,8 @@ public class UserController { } } + + @GetMapping("/get_user_info") public Result getUserInfo( @RequestHeader("Authorization") String authHeader, @RequestHeader("Device-ID") String deviceId, diff --git a/src/main/java/com/onekeycall/videotablet/controller/UserPasswordController.java b/src/main/java/com/onekeycall/videotablet/controller/UserPasswordController.java index f851468..5547af8 100644 --- a/src/main/java/com/onekeycall/videotablet/controller/UserPasswordController.java +++ b/src/main/java/com/onekeycall/videotablet/controller/UserPasswordController.java @@ -4,6 +4,7 @@ import com.onekeycall.videotablet.entity.User; import com.onekeycall.videotablet.result.Result; import com.onekeycall.videotablet.service.UserService; import com.onekeycall.videotablet.utils.JwtUtil; +import com.onekeycall.videotablet.utils.TextUtils; import jakarta.servlet.http.HttpServletRequest; import org.apache.commons.lang3.StringUtils; import org.springframework.beans.factory.annotation.Autowired; @@ -99,4 +100,47 @@ public class UserPasswordController { return Result.error().message("token is not same"); } } + +// @PostMapping("/set_info") +// public Result newUserSetInfo( +// @RequestHeader(value = "Authorization", required = false) String authHeader, @RequestHeader("Device-ID") String deviceId, +// @RequestParam(value = "user_id") String userId, @RequestParam(value = "nick_name", required = false) String nickName, +// @RequestParam(value = "avatar", required = false) String avatar, +// @RequestParam String password, @RequestParam(value = "verify_password") String verifyPassword) { +// +// if (authHeader == null || !authHeader.startsWith("Bearer ")) { +// return Result.error().message("Authorization header is incorrect"); +// } +// +// String token = authHeader.substring(7); +// if (!jwtUtil.validateAccessToken(userId, token, deviceId)) { +// return Result.error().message("Invalid token"); +// } +// +// User user = userService.getUserByUserId(userId); +// if (user == null) { +// return Result.error().message("user not found"); +// } +// +// if (!TextUtils.isEmpty(user.getPassword())) { +// return Result.error().message("user is not new user"); +// } +// +// if (!StringUtils.equals(password, verifyPassword)) { +// return Result.error().message("password is not same"); +// } +// +// user.setPassword(password); +// if (!TextUtils.isEmpty(nickName)) { +// user.setNickname(nickName); +// } +// if (!TextUtils.isEmpty(avatar)) { +// user.setAvatar(avatar); +// } +// if (userService.updateUser(user)) { +// return Result.ok().message("set info success"); +// } else { +// return Result.error().message("set info fail"); +// } +// } } diff --git a/src/main/java/com/onekeycall/videotablet/service/UserService.java b/src/main/java/com/onekeycall/videotablet/service/UserService.java index 70e0520..dcc6601 100644 --- a/src/main/java/com/onekeycall/videotablet/service/UserService.java +++ b/src/main/java/com/onekeycall/videotablet/service/UserService.java @@ -56,8 +56,10 @@ public class UserService implements UserDetailsService { // 2. 检查手机号是否已注册 if (userRepository.existsByPhone(phone)) { User user = userRepository.findByPhone(phone).get(); - user.setUserId(deviceId); user.setNewUser(false); + user.setDeviceId(deviceId); + user.setLastLoginTime(createTime); + user.setUpdateTime(createTime); return user; } else { // 3. 创建新用户 @@ -116,4 +118,11 @@ public class UserService implements UserDetailsService { return userRepository.findUserByUserId(userId). orElseThrow(() -> new UsernameNotFoundException("User not found with userId: " + userId)); } + +// public boolean updateUser(User user) { +// if (!userRepository.existsByUserId(user.getUserId())) { +// return false; +// } +// return userRepository.updateUser(user); +// } } \ No newline at end of file