Parcourir la source

UserRegistry 添加一个 domain 字段, 用于指定 gateway 的域名, 便于指定创建帐号时头像的具体 url

reghao il y a 1 an
Parent
commit
31c62b1ff7

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

@@ -52,7 +52,7 @@ public class UserAccount extends BaseObject<Integer> {
     private String signature;
     private Integer gender;
 
-    public UserAccount(long userId, String email, String mobile) {
+    public UserAccount(long userId, String email, String mobile, String avatarUrl) {
         this.userId = userId;
         this.accountType = AccountType.tnb.getValue();
         this.username = String.format("tnb_%s", userId);
@@ -66,11 +66,11 @@ public class UserAccount extends BaseObject<Integer> {
         this.enabled = true;
         this.locked = false;
         this.screenName = this.username;
-        this.avatarUrl = "/dist/images/face.jpg";
+        this.avatarUrl = avatarUrl;
         this.gender = 2;
     }
 
-    public UserAccount(long userId, String email, String mobile, String encodedPassword, String salt) {
+    public UserAccount(long userId, String email, String mobile, String encodedPassword, String salt, String avatarUrl) {
         this.userId = userId;
         this.accountType = AccountType.tnb.getValue();
         this.username = String.format("tnb_%s", userId);
@@ -84,16 +84,16 @@ public class UserAccount extends BaseObject<Integer> {
         this.enabled = true;
         this.locked = false;
         this.screenName = this.username;
-        this.avatarUrl = "/dist/images/face.jpg";
+        this.avatarUrl = avatarUrl;
         this.gender = 2;
     }
 
     @Deprecated
-    public UserAccount(long userId, String username, String screenName, String avatarUrl) {
+    public UserAccount(long userId, String email, String username, String screenName, String avatarUrl) {
         this.userId = userId;
         this.accountType = AccountType.bilibili.getValue();
         this.username = username;
-        this.email = String.format("%s@tnb.cn", userId);;
+        this.email = email;
         this.createAt = LocalDateTime.now();
         this.role = AccountRole.user.getValue();
         this.enabled = true;

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

@@ -18,6 +18,7 @@ public class UserRegistry extends BaseObject<Integer> {
     private String captchaCode;
     private String verifyCode;
     private Boolean enableCode;
+    private String domain;
 
     public UserRegistry() {
         this.enabled = true;

+ 2 - 1
account/account-service/src/main/java/cn/reghao/tnb/account/app/rpc/AccountQueryImpl.java

@@ -97,7 +97,8 @@ public class AccountQueryImpl implements AccountQuery {
             userId = accountRegistryService.getNextUserId();
         }
 
-        UserAccount userAccount = new UserAccount(userId, username, screenName, avatarUrl);
+        String email = String.format("%s@tnb.cn", userId);
+        UserAccount userAccount = new UserAccount(userId, email, username, screenName, avatarUrl);
         accountRepository.saveAccount(userAccount);
         return userId;
     }

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

@@ -17,6 +17,7 @@ import lombok.extern.slf4j.Slf4j;
 import org.springframework.security.crypto.password.PasswordEncoder;
 import org.springframework.stereotype.Service;
 
+import javax.annotation.PostConstruct;
 import java.time.LocalDateTime;
 
 /**
@@ -30,6 +31,7 @@ public class AccountRegistryServiceImpl implements AccountRegistryService {
     private final PasswordEncoder passwordEncoder;
     private final AccountRepository accountRepository;
     private final PubkeyService pubkeyService;
+    private String avatarUrl;
 
     public AccountRegistryServiceImpl(CodeService codeService, PasswordEncoder passwordEncoder,
                                       AccountRepository accountRepository, PubkeyService pubkeyService) {
@@ -39,6 +41,12 @@ public class AccountRegistryServiceImpl implements AccountRegistryService {
         this.pubkeyService = pubkeyService;
     }
 
+    @PostConstruct
+    public void setAvatarUrl() {
+        String domain = accountRepository.getUserRegistry().getDomain();
+        this.avatarUrl = String.format("//%s/dist/images/face.jpg", domain);
+    }
+
     @Override
     public synchronized Result createAccount(UserRegisterDto userRegisterDto) {
         String captchaCode = userRegisterDto.getCaptchaCode();
@@ -77,7 +85,7 @@ public class AccountRegistryServiceImpl implements AccountRegistryService {
         long userId = getNextUserId();
         String salt = RandomString.getSalt(64);
         String encodedPassword = passwordEncoder.encode(decryptCredential + salt);
-        UserAccount userAccount = new UserAccount(userId, email, mobile, encodedPassword, salt);
+        UserAccount userAccount = new UserAccount(userId, email, mobile, encodedPassword, salt, avatarUrl);
         accountRepository.saveAccount(userAccount);
         return Result.result(ResultStatus.SUCCESS, "帐号已创建");
     }
@@ -105,7 +113,7 @@ public class AccountRegistryServiceImpl implements AccountRegistryService {
         }
 
         long userId = getNextUserId();
-        UserAccount userAccount = new UserAccount(userId, email, mobile);
+        UserAccount userAccount = new UserAccount(userId, email, mobile, avatarUrl);
         accountRepository.saveAccount(userAccount);
         return accountRepository.getUserDetailByMobile(mobile);
     }

+ 2 - 2
account/account-service/src/main/resources/mapper/UserRegistryMapper.xml

@@ -4,9 +4,9 @@
 <mapper namespace="cn.reghao.tnb.account.app.db.mapper.UserRegistryMapper">
     <insert id="save">
         insert into user_registry
-        (`enabled`,`rule`,`captcha_code`,`verify_code`,`enable_code`)
+        (`enabled`,`rule`,`captcha_code`,`verify_code`,`enable_code`,`domain`)
         values
-        (#{enabled},#{rule},#{captchaCode},#{verifyCode},#{enableCode})
+        (#{enabled},#{rule},#{captchaCode},#{verifyCode},#{enableCode},#{domain})
     </insert>
     
     <update id="update">