|
|
@@ -3,6 +3,7 @@ package cn.reghao.tnb.account.app.service.impl;
|
|
|
import cn.reghao.jutil.jdk.web.result.Result;
|
|
|
import cn.reghao.jutil.jdk.web.result.ResultStatus;
|
|
|
import cn.reghao.jutil.jdk.security.RandomString;
|
|
|
+import cn.reghao.tnb.account.api.dto.AccountInfo;
|
|
|
import cn.reghao.tnb.common.util.StringRegexp;
|
|
|
import cn.reghao.tnb.account.app.model.constant.VerifyChannel;
|
|
|
import cn.reghao.tnb.account.app.model.dto.AccountRegisterDto;
|
|
|
@@ -86,13 +87,7 @@ public class AccountRegistryServiceImpl implements AccountRegistryService {
|
|
|
long userId = accountRepository.getNextUserId();
|
|
|
String salt = RandomString.getSalt(64);
|
|
|
String encodedPassword = passwordEncoder.encode(decryptCredential + salt);
|
|
|
- Set<UserAuthority> authorities;
|
|
|
- if (userId == ConstantId.START_USER_ID) {
|
|
|
- authorities = Set.of(new UserAuthority(AccountRole.admin.getValue()));
|
|
|
- } else {
|
|
|
- authorities = Set.of(new UserAuthority());
|
|
|
- }
|
|
|
-
|
|
|
+ Set<UserAuthority> authorities = Set.of(new UserAuthority());
|
|
|
if (StringRegexp.matchMobile(principal)) {
|
|
|
UserAccount userAccount = new UserAccount(principal, userId, encodedPassword, salt, authorities);
|
|
|
accountRepository.saveAccount(userAccount);
|
|
|
@@ -111,4 +106,22 @@ public class AccountRegistryServiceImpl implements AccountRegistryService {
|
|
|
}
|
|
|
throw new UsernameNotFoundException(String.format("%s is not mobile number", principal));
|
|
|
}
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void createAdminAccount() {
|
|
|
+ long userId = accountRepository.getNextUserId();
|
|
|
+ if (userId == ConstantId.START_USER_ID) {
|
|
|
+ String principal = ConstantId.ADMIN_MOBILE;
|
|
|
+ String password = ConstantId.ADMIN_PASSWORD;
|
|
|
+ String salt = RandomString.getSalt(64);
|
|
|
+ String encodedPassword = passwordEncoder.encode(password + salt);
|
|
|
+ Set<UserAuthority> authorities = Set.of(new UserAuthority(AccountRole.admin.getValue()));
|
|
|
+
|
|
|
+ UserAccount userAccount = new UserAccount(principal, userId, encodedPassword, salt, authorities);
|
|
|
+ accountRepository.saveAccount(userAccount);
|
|
|
+ log.info("admin 帐号已创建");
|
|
|
+ } else {
|
|
|
+ log.info("admin 帐号已存在");
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|