Explorar el Código

feat(auth): 新增切换保护密码设置接口 set-switch-password

iwt hace 2 semanas
padre
commit
bb7b2b5053

+ 13 - 2
cfc-backend/src/main/java/com/etotem/cfc/controller/auth/AuthController.java

@@ -189,11 +189,22 @@ public class AuthController {
     @PostMapping("/set-password")
     public Result<Boolean> setPassword(@RequestBody SetPasswordDTO dto,
                                        @RequestAttribute("userId") Long userId) {
-        boolean success = userService.setPassword(userId, dto.getPassword());
+        boolean success = userService.setPassword(userId, dto.getPassword());
         return Result.success(success);
     }
 
-    /**
+    @Operation(summary = "设置切换保护密码")
+    @PostMapping("/set-switch-password")
+    public Result<Boolean> setSwitchPassword(@RequestBody SetPasswordDTO dto,
+                                             @RequestAttribute("userId") Long userId) {
+        if (userId == null) {
+            return Result.error("请先登录");
+        }
+        boolean success = userService.setSwitchPassword(userId, dto.getPassword());
+        return Result.success(success);
+    }
+
+    /**
      * JWT Token 验证
      * 从 Authorization header 提取 Bearer token,验证并返回用户信息
      */

+ 8 - 0
cfc-backend/src/main/java/com/etotem/cfc/service/UserService.java

@@ -347,6 +347,14 @@ private FamilyInvitationService familyInvitationService;
         return true;
     }
 
+    /**
+     * 设置切换保护密码(切换前由原用户设置,退出切换时校验)
+     * 复用 users.password 字段(用户决策:未单独设置时默认用登录密码)
+     */
+    public boolean setSwitchPassword(Long userId, String password) {
+        return setPassword(userId, password);
+    }
+
     public boolean verifyPassword(Long userId, String password) {
         User user = userMapper.selectById(userId);
         if (user == null || user.getPassword() == null || user.getPassword().isEmpty()) {

+ 1 - 0
cfc-backend/src/main/java/com/etotem/cfc/service/api/UserServiceInterface.java

@@ -11,6 +11,7 @@ public interface UserServiceInterface {
     LoginResultDTO silentLogin(String code);
     LoginResultDTO autoLoginByOpenid(String openid);
     boolean setPassword(Long userId, String password);
+    boolean setSwitchPassword(Long userId, String password);
     boolean verifyPassword(Long userId, String password);
     User getUserInfo(Long userId);
     boolean isPhoneRegistered(String phone);