reghao 6 місяців тому
батько
коміт
f0aee5e7ec

+ 0 - 28
account/account-service/src/main/java/cn/reghao/tnb/account/app/model/constant/AccountType.java

@@ -1,28 +0,0 @@
-package cn.reghao.tnb.account.app.model.constant;
-
-/**
- * 账号类型
- *
- * @author reghao
- * @date 2021-11-17 16:54:00
- */
-@Deprecated
-public enum AccountType {
-    // 本系统注册用户
-    tnb(1),
-    yirentv(2),
-    bilibili(3);
-
-    private final int value;
-    AccountType(int value) {
-        this.value = value;
-    }
-
-    public String getName() {
-        return this.name();
-    }
-
-    public Integer getValue() {
-        return value;
-    }
-}

+ 0 - 3
account/account-service/src/main/java/cn/reghao/tnb/account/app/model/dto/UserRegisterDto.java

@@ -1,6 +1,5 @@
 package cn.reghao.tnb.account.app.model.dto;
 
-import cn.reghao.tnb.account.app.model.constant.AccountType;
 import cn.reghao.tnb.account.app.model.constant.LoginPlat;
 import lombok.Getter;
 import lombok.Setter;
@@ -20,7 +19,6 @@ import java.io.Serializable;
 public class UserRegisterDto implements Serializable {
     private static final long serialVersionUID = 1L;
 
-    private Integer accountType;
     private String principal;
     @NotBlank(message = "密码不能为空")
     private String credential;
@@ -31,7 +29,6 @@ public class UserRegisterDto implements Serializable {
     private String plat;
 
     public UserRegisterDto() {
-        this.accountType = AccountType.tnb.getValue();
         this.plat = LoginPlat.web.getName();
     }
 }

+ 21 - 2
account/account-service/src/main/java/cn/reghao/tnb/account/app/model/po/UserAccount.java

@@ -23,7 +23,6 @@ import java.util.Set;
  */
 @NoArgsConstructor
 @EqualsAndHashCode(callSuper = true)
-@Data
 public class UserAccount extends BaseObject<Integer> implements UserDetails {
     @NotNull
     private Long userId;
@@ -38,9 +37,9 @@ public class UserAccount extends BaseObject<Integer> implements UserDetails {
     private LocalDateTime createAt;
     private String screenName;
     private String avatarUrl;
-
     private transient int loginType;
     private transient int plat;
+
     // Spring Security 使用的字段
     private transient Set<UserAuthority> authorities;
     private Boolean enabled;
@@ -89,6 +88,26 @@ public class UserAccount extends BaseObject<Integer> implements UserDetails {
         this.authorities = Set.of(new UserAuthority());
     }
 
+    public Long getUserId() {
+        return userId;
+    }
+
+    public String getEncodedPassword() {
+        return encodedPassword;
+    }
+
+    public String getSalt() {
+        return salt;
+    }
+
+    public void setAuthorities(Set<UserAuthority> authorities) {
+        this.authorities = authorities;
+    }
+
+    public void setLoginType(int loginType) {
+        this.loginType = loginType;
+    }
+
     @Override
     public String getUsername() {
         return this.username;

+ 2 - 0
account/account-service/src/main/java/cn/reghao/tnb/account/app/model/po/UserAccountRole.java

@@ -5,6 +5,8 @@ import lombok.Getter;
 import lombok.NoArgsConstructor;
 
 /**
+ * 持久化到数据库版本的 UserAuthority
+ *
  * @author reghao
  * @date 2025-08-13 16:32:07
  */

+ 1 - 0
account/account-service/src/main/java/cn/reghao/tnb/account/app/service/impl/AccountRegistryServiceImpl.java

@@ -8,6 +8,7 @@ import cn.reghao.tnb.account.api.constant.VerifyChannel;
 import cn.reghao.tnb.account.api.dto.AdminCreateAccount;
 import cn.reghao.tnb.account.app.model.dto.UserRegisterDto;
 import cn.reghao.tnb.account.app.db.repository.AccountRepository;
+import cn.reghao.tnb.account.app.model.po.UserAccountRole;
 import cn.reghao.tnb.account.app.model.po.UserRegistry;
 import cn.reghao.tnb.account.app.service.CodeService;
 import cn.reghao.tnb.account.app.model.po.UserAccount;

+ 2 - 2
account/account-service/src/main/java/cn/reghao/tnb/account/app/service/impl/AccountTokenServiceImpl.java

@@ -169,7 +169,6 @@ public class AccountTokenServiceImpl implements AccountTokenService {
 
     @Override
     public void logout(String loginId) {
-        String currentLoginId = getAuthToken().getLoginId();
         List<LoginAttempts> loginAttemptsList = loginAttemptsMapper.findByLoginIds(List.of(loginId));
         if (!loginAttemptsList.isEmpty() && !loginAttemptsList.get(0).getRememberMe()) {
             LoginAttempts loginAttempts = loginAttemptsList.get(0);
@@ -182,7 +181,8 @@ public class AccountTokenServiceImpl implements AccountTokenService {
                 deleteSession(loginId);
             }
 
-            if (loginId.equals(currentLoginId)) {
+            AccountAuthToken authToken = getAuthToken();
+            if (authToken != null && loginId.equals(authToken.getLoginId())) {
                 clearSecurityContext();
             }
         }

+ 5 - 9
account/account-service/src/main/resources/mapper/LoginAttemptsMapper.xml

@@ -3,25 +3,21 @@
 
 <mapper namespace="cn.reghao.tnb.account.app.db.mapper.LoginAttemptsMapper">
     <insert id="save">
-        insert into msg_login_attempts
+        insert into user_login_attempts
         (`login_id`,`user_id`,`login_type`,`user_agent`,`login_ip`,`login_at`,`plat`,`remember_me`,`success`)
         values
-        (#{loginId},#{userId},#{loginType},#{userAgent},#{loginIp},#{loginAt},#{plat},#{rememberMe},`success`)
+        (#{loginId},#{userId},#{loginType},#{userAgent},#{loginIp},#{loginAt},#{plat},#{rememberMe},#{success})
     </insert>
 
     <update id="updateSetFailed">
-        update msg_login_attempts
+        update user_login_attempts
         set update_time=now(),`success`=0
         where login_id=#{loginId}
     </update>
 
-    <select id="findAll" resultType="cn.reghao.tnb.account.app.model.po.LoginAttempts">
-        select *
-        from msg_login_attempts
-    </select>
     <select id="findByLoginIds" resultType="cn.reghao.tnb.account.app.model.po.LoginAttempts">
         select *
-        from msg_login_attempts
+        from user_login_attempts
         where login_id in
         <foreach collection="list" item="id" index="index" open="(" close=")" separator=",">
             #{id}
@@ -29,7 +25,7 @@
     </select>
     <select id="findByUserId" resultType="cn.reghao.tnb.account.app.model.po.LoginAttempts">
         select *
-        from msg_login_attempts
+        from user_login_attempts
         where user_id=#{userId}
         limit #{pageSize}
     </select>