优化手机验证码注册 user_id异常的问题

This commit is contained in:
2025-08-21 19:05:20 +08:00
parent 66d039b507
commit f0cffe3e12
3 changed files with 56 additions and 1 deletions

View File

@@ -64,6 +64,8 @@ public class UserController {
}
}
@GetMapping("/get_user_info")
public Result getUserInfo(
@RequestHeader("Authorization") String authHeader, @RequestHeader("Device-ID") String deviceId,

View File

@@ -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");
// }
// }
}

View File

@@ -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);
// }
}