优化加密字段
This commit is contained in:
@@ -101,46 +101,48 @@ public class UserPasswordController {
|
||||
}
|
||||
}
|
||||
|
||||
// @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");
|
||||
// }
|
||||
// }
|
||||
@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.saveUser(user)) {
|
||||
return Result.ok().message("set info success");
|
||||
} else {
|
||||
return Result.error().message("set info fail");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,23 +1,26 @@
|
||||
package com.onekeycall.videotablet.entity;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import com.onekeycall.videotablet.converter.AesAttributeConverter;
|
||||
import jakarta.persistence.*;
|
||||
import jakarta.validation.constraints.NotBlank;
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
@Entity
|
||||
@Table(name = "tablet_default_settings")
|
||||
@Table(name = "device_contacts")
|
||||
public class Contact {
|
||||
@Id
|
||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||
@Column(name = "id",unique = true, nullable = false)
|
||||
private Long id;
|
||||
|
||||
@Convert(converter = AesAttributeConverter.class)
|
||||
@NotBlank(message = "姓名不能为空")
|
||||
@Column
|
||||
private String name;
|
||||
|
||||
@Convert(converter = AesAttributeConverter.class)
|
||||
@NotBlank(message = "手机号不能为空")
|
||||
@JsonProperty("phone_number")
|
||||
@Column(name = "phone_number")
|
||||
@@ -29,9 +32,11 @@ public class Contact {
|
||||
@Column
|
||||
private String tag;
|
||||
|
||||
@Convert(converter = AesAttributeConverter.class)
|
||||
@Column
|
||||
private String wxid;
|
||||
|
||||
@Convert(converter = AesAttributeConverter.class)
|
||||
@Column
|
||||
private String qq;
|
||||
|
||||
|
||||
@@ -30,7 +30,6 @@ public class DeviceInfo {
|
||||
@Column(name = "tablet_avatar")
|
||||
private String tabletAvatar;
|
||||
|
||||
@Convert(converter = AesAttributeConverter.class)
|
||||
@Column(name = "user_id")
|
||||
private String userId;
|
||||
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package com.onekeycall.videotablet.entity;
|
||||
|
||||
import com.onekeycall.videotablet.converter.AesAttributeConverter;
|
||||
import jakarta.persistence.*;
|
||||
import lombok.Data;
|
||||
|
||||
@@ -18,9 +19,11 @@ public class DeviceLocation {
|
||||
@Column(name = "sn", unique = true, nullable = false)
|
||||
String sn;
|
||||
|
||||
@Convert(converter = AesAttributeConverter.class)
|
||||
@Column(name = "address", nullable = false)
|
||||
String address;
|
||||
|
||||
@Convert(converter = AesAttributeConverter.class)
|
||||
@Column(name = "location_describe")
|
||||
String location_describe;
|
||||
|
||||
|
||||
@@ -27,14 +27,13 @@ public class User implements UserDetails {
|
||||
@Column(name = "user_id", unique = true, nullable = false)
|
||||
private String userId;
|
||||
|
||||
// 使用@Convert注解指定转换器
|
||||
@Convert(converter = AesAttributeConverter.class)
|
||||
@Column
|
||||
private String nickname;
|
||||
|
||||
@Column()
|
||||
private String password;
|
||||
|
||||
// 使用@Convert注解指定转换器
|
||||
@Convert(converter = AesAttributeConverter.class)
|
||||
@Column(unique = true, nullable = false)
|
||||
private String phone;
|
||||
|
||||
@@ -125,4 +125,12 @@ public class UserService implements UserDetailsService {
|
||||
// }
|
||||
// return userRepository.updateUser(user);
|
||||
// }
|
||||
|
||||
public boolean saveUser(User user) {
|
||||
if (userRepository.existsByUserId(user.getUserId())) {
|
||||
return false;
|
||||
}
|
||||
userRepository.save(user);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user