Просмотр исходного кода

fix(cfc-backend): revert error-throwing, keep auto-create for unidentified users

User 2 месяцев назад
Родитель
Сommit
280ba758b1
1 измененных файлов с 3 добавлено и 7 удалено
  1. 3 7
      cfc-backend/src/main/java/com/etotem/cfc/service/UserService.java

+ 3 - 7
cfc-backend/src/main/java/com/etotem/cfc/service/UserService.java

@@ -86,11 +86,7 @@ private FamilyInvitationService familyInvitationService;
             }
 
             if (user == null) {
-                // 5. 没有phoneCode也无法通过手机号找到用户 → 不能自动创建(避免mock→真实openid迁移时产生重复用户)
-                if (phone == null) {
-                    throw new RuntimeException("用户不存在,请先授权手机号后登录");
-                }
-                // 6. 有phoneCode且查不到 → 全新用户,创建新家庭和用户
+                // 5. 完全查不到 → 全新用户,自动创建
                 isNewUser = true;
 
                 Family family = new Family();
@@ -105,7 +101,7 @@ private FamilyInvitationService familyInvitationService;
                 user.setUnionid(unionid != null ? unionid : "");
                 user.setFamilyId(family.getId());
                 user.setRole("parent");
-                user.setNickname(dto.getNickname() != null ? dto.getNickname() : "用户" + phone.substring(7));
+                user.setNickname(dto.getNickname() != null ? dto.getNickname() : (phone != null ? "用户" + phone.substring(7) : "微信用户"));
                 user.setAvatar(dto.getAvatar());
                 user.setPhone(phone);
                 user.setPassword("");
@@ -114,7 +110,7 @@ private FamilyInvitationService familyInvitationService;
                 userMapper.insert(user);
                 try { onboardingService.initForUser(user.getId()); onboardingService.completeTask(user.getId(), "REGISTER"); } catch (Exception e) { /* onboarding init failure should not block login */ }
             } else {
-                // 7. 手机号已存在但openid不同,绑定openid
+                // 6. 手机号已存在但openid不同,绑定openid
                 user.setOpenid(openid);
                 user.setUnionid(unionid != null ? unionid : "");
                 user.setUpdatedAt(new Date());