|
|
@@ -4,12 +4,16 @@ import cn.reghao.jutil.jdk.result.Result;
|
|
|
import cn.reghao.jutil.jdk.security.RandomString;
|
|
|
import cn.reghao.tnb.account.api.constant.VerifyChannel;
|
|
|
import cn.reghao.tnb.account.app.db.mapper.UserAccountMapper;
|
|
|
+import cn.reghao.tnb.account.app.db.repository.AccountRepository;
|
|
|
import cn.reghao.tnb.account.app.model.dto.*;
|
|
|
import cn.reghao.tnb.account.app.model.po.UserAccount;
|
|
|
import cn.reghao.tnb.account.app.security.form.AccountAuthToken;
|
|
|
+import cn.reghao.tnb.common.auth.AccountRole;
|
|
|
import org.springframework.security.crypto.password.PasswordEncoder;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
+import java.util.Set;
|
|
|
+
|
|
|
/**
|
|
|
* @author reghao
|
|
|
* @date 2023-02-18 14:42:57
|
|
|
@@ -17,15 +21,17 @@ import org.springframework.stereotype.Service;
|
|
|
@Service
|
|
|
public class AccountProfileService {
|
|
|
private final UserAccountMapper userAccountMapper;
|
|
|
+ private final AccountRepository accountRepository;
|
|
|
private final PubkeyService pubkeyService;
|
|
|
private final CodeService codeService;
|
|
|
private final AccountTokenService accountTokenService;
|
|
|
private final PasswordEncoder passwordEncoder;
|
|
|
|
|
|
- public AccountProfileService(UserAccountMapper userAccountMapper, CodeService codeService,
|
|
|
- AccountTokenService accountTokenService, PubkeyService pubkeyService,
|
|
|
- PasswordEncoder passwordEncoder) {
|
|
|
+ public AccountProfileService(UserAccountMapper userAccountMapper, AccountRepository accountRepository,
|
|
|
+ CodeService codeService, AccountTokenService accountTokenService,
|
|
|
+ PubkeyService pubkeyService, PasswordEncoder passwordEncoder) {
|
|
|
this.userAccountMapper = userAccountMapper;
|
|
|
+ this.accountRepository = accountRepository;
|
|
|
this.accountTokenService = accountTokenService;
|
|
|
this.pubkeyService = pubkeyService;
|
|
|
this.codeService = codeService;
|
|
|
@@ -35,7 +41,7 @@ public class AccountProfileService {
|
|
|
public Result updateUserScreenName(String screenName) {
|
|
|
AccountAuthToken authToken = accountTokenService.getAuthToken();
|
|
|
long userId = authToken.getUserId();
|
|
|
- userAccountMapper.updateUserScreenName(userId, screenName);
|
|
|
+ accountRepository.updateUserScreenName(userId, screenName);
|
|
|
return Result.success();
|
|
|
}
|
|
|
|
|
|
@@ -77,7 +83,7 @@ public class AccountProfileService {
|
|
|
AccountAuthToken authToken = accountTokenService.getAuthToken();
|
|
|
long userId = authToken.getUserId();
|
|
|
|
|
|
- UserAccount userAccount = userAccountMapper.findByUserId(userId);
|
|
|
+ UserAccount userAccount = accountRepository.getUserAccountByUserId(userId);
|
|
|
String oldPassword = passwordUpdateDto.getOldPassword();
|
|
|
String newPassword = passwordUpdateDto.getNewPassword();
|
|
|
try {
|
|
|
@@ -126,7 +132,7 @@ public class AccountProfileService {
|
|
|
return Result.fail("短信验证码不正确, 请重新获取");
|
|
|
}
|
|
|
|
|
|
- UserAccount userAccount = userAccountMapper.findByEmail(email);
|
|
|
+ UserAccount userAccount = accountRepository.getUserAccountByEmail(email);
|
|
|
if (userAccount == null) {
|
|
|
return Result.fail("帐号不存在");
|
|
|
}
|
|
|
@@ -142,4 +148,12 @@ public class AccountProfileService {
|
|
|
|
|
|
return Result.success();
|
|
|
}
|
|
|
+
|
|
|
+ public void setUserAdmin(long userId) {
|
|
|
+ String adminRole = AccountRole.admin.getValue();
|
|
|
+ Set<String> userRoles = accountRepository.getUserRoles(userId);
|
|
|
+ if (!userRoles.contains(adminRole)) {
|
|
|
+ accountRepository.addUserRole(userId, adminRole);
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|