增加是否有密码判断

This commit is contained in:
2025-08-31 13:16:23 +08:00
parent 3d105cf688
commit 7199921255
4 changed files with 43 additions and 5 deletions

View File

@@ -67,7 +67,7 @@ public class DevicesController {
}
@PostMapping("/update_location")
public Result getBindStatus(
public Result updateLocation(
@RequestHeader("Device-Token") String deviceToken, @RequestHeader("Device-ID") String deviceId,
@RequestHeader("Device-Sig") String deviceSig,
@Valid @RequestBody DeviceLocation deviceLocation
@@ -133,4 +133,40 @@ public class DevicesController {
return Result.ok().data("contacts", contacts);
}
@PostMapping("/upload_install_apk")
public Result uploadInstallApk(
@RequestHeader("Device-Token") String deviceToken, @RequestHeader("Device-ID") String deviceId,
@RequestHeader("Device-Sig") String deviceSig,
@Valid @RequestBody DeviceLocation deviceLocation
) {
String sn = deviceLocation.getSn();
if (!jwtUtil.validateDeviceToken(deviceToken, deviceId, sn)) {
return Result.error().message("Invalid token");
}
DeviceInfo deviceInfo = deviceSnService.findBySn(sn);
if (deviceInfo == null) {
return Result.notFound().message("sn not found");
}
if (!deviceInfo.getBindSig().equals(deviceSig)) {
return Result.error().message("device sig not match");
}
if (TextUtils.isEmpty(deviceInfo.getBindPhone())) {
return Result.error().message("sn not bind");
}
if (deviceLocationService.isExist(sn)) {
DeviceLocation deviceLocationDB = deviceLocationService.getDeviceLocation(sn);
deviceLocation.setId(deviceLocationDB.getId());
deviceLocation.setUpdateTime(new Date(System.currentTimeMillis()));
deviceLocationService.save(deviceLocation);
} else {
deviceLocation.setUpdateTime(new Date(System.currentTimeMillis()));
deviceLocation.setCreateTime(new Date(System.currentTimeMillis()));
deviceLocationService.save(deviceLocation);
}
return Result.ok();
}
}

View File

@@ -10,6 +10,7 @@ import com.onekeycall.videotablet.service.DeviceLocationService;
import com.onekeycall.videotablet.service.DeviceSnService;
import com.onekeycall.videotablet.service.UserService;
import com.onekeycall.videotablet.utils.JwtUtil;
import com.onekeycall.videotablet.utils.TextUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
@@ -96,6 +97,7 @@ public class UserController {
userInfo.put("phone", user.getPhone());
userInfo.put("nickname", user.getNickname());
userInfo.put("avatar", user.getAvatar());
userInfo.put("set_password", !TextUtils.isEmpty(user.getPassword()));
return Result.ok().data("user_info", userInfo);
}

View File

@@ -127,9 +127,6 @@ public class UserService implements UserDetailsService {
// }
public boolean saveUser(User user) {
if (userRepository.existsByUserId(user.getUserId())) {
return false;
}
userRepository.save(user);
return true;
}

View File

@@ -86,7 +86,10 @@ public class JwtUtil {
.build()
.parseSignedClaims(token)
.getPayload();
} catch (JwtException | IllegalArgumentException e) {
} catch (JwtException e) {
logger.error("parseToken Token已过期: {}", e.getMessage());
throw new InvalidTokenException("Token解析失败: " + e.getMessage());
} catch (IllegalArgumentException e) {
logger.error("parseToken Token解析失败: {}", e.getMessage());
throw new InvalidTokenException("Token解析失败: " + e.getMessage());
}