TASK:绑定邮箱、绑定微信;
This commit is contained in:
@@ -7,6 +7,7 @@ import com.ai.da.mapper.primary.entity.TrialOrder;
|
||||
import com.ai.da.model.dto.*;
|
||||
import com.ai.da.model.vo.AccountLoginVO;
|
||||
import com.ai.da.model.vo.AccountPreLoginVO;
|
||||
import com.ai.da.model.vo.BindEmailVO;
|
||||
import com.ai.da.model.vo.PersonalHomepageVO;
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
@@ -49,7 +50,7 @@ public interface AccountService extends IService<Account> {
|
||||
*/
|
||||
Boolean bindEmail(AccountBindEmailDTO accountBindEmailDTO);
|
||||
|
||||
Boolean bindEmail(String email);
|
||||
BindEmailVO bindEmail(String email);
|
||||
|
||||
/**
|
||||
* 忘记密码
|
||||
|
||||
@@ -413,7 +413,14 @@ public class AccountServiceImpl extends ServiceImpl<AccountMapper, Account> impl
|
||||
qw.lambda().eq(Account::getUserEmail, emailSendDTO.getEmail());
|
||||
List<Account> accounts = accountMapper.selectList(qw);
|
||||
if (CollectionUtil.isNotEmpty(accounts)) {
|
||||
throw new BusinessException("This email has been bound");
|
||||
Account account = accounts.get(0);
|
||||
QueryWrapper<AccountExtend> accountExtendQW = new QueryWrapper<>();
|
||||
accountExtendQW.lambda().eq(AccountExtend::getAccountId, account.getId());
|
||||
accountExtendQW.lambda().eq(AccountExtend::getAuth, "WeChat");
|
||||
List<AccountExtend> accountExtends = accountExtendMapper.selectList(accountExtendQW);
|
||||
if (CollectionUtil.isNotEmpty(accountExtends)) {
|
||||
throw new BusinessException("This email account has already been linked to another WeChat account.");
|
||||
}
|
||||
}
|
||||
result = SendEmailUtil.send(emailSendDTO.getEmail(), null,
|
||||
SendEmailUtil.BIND_MAILBOX_TEMPLATE_ID, randomVerifyCode);
|
||||
@@ -2562,6 +2569,7 @@ public class AccountServiceImpl extends ServiceImpl<AccountMapper, Account> impl
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional
|
||||
public AccountExtend bindWeChat(String code) {
|
||||
// 1. 获取 access_token 和 openid
|
||||
JSONObject accessTokenResponse = getAccessTokenFromWeChat(code);
|
||||
@@ -2588,7 +2596,14 @@ public class AccountServiceImpl extends ServiceImpl<AccountMapper, Account> impl
|
||||
List<AccountExtend> accountExtends = accountExtendMapper.selectList(qw);
|
||||
|
||||
if (CollectionUtil.isNotEmpty(accountExtends)) {
|
||||
throw new BusinessException("The WeChat has been bound.");
|
||||
AccountExtend accountExtend = accountExtends.get(0);
|
||||
AuthPrincipalVo authPrincipalVo = UserContext.getUserHolder();
|
||||
|
||||
accountMapper.deleteById(accountExtend.getAccountId());
|
||||
|
||||
accountExtend.setAccountId(authPrincipalVo.getId());
|
||||
accountExtendMapper.updateById(accountExtend);
|
||||
return accountExtend;
|
||||
}
|
||||
|
||||
AccountExtend accountExtendInsert = new AccountExtend();
|
||||
@@ -2625,12 +2640,40 @@ public class AccountServiceImpl extends ServiceImpl<AccountMapper, Account> impl
|
||||
}
|
||||
|
||||
@Override
|
||||
public Boolean bindEmail(String email) {
|
||||
@Transactional
|
||||
public BindEmailVO bindEmail(String email) {
|
||||
AuthPrincipalVo userHolder = UserContext.getUserHolder();
|
||||
|
||||
BindEmailVO result = new BindEmailVO();
|
||||
|
||||
QueryWrapper<Account> qw = new QueryWrapper<>();
|
||||
qw.lambda().eq(Account::getUserEmail, email);
|
||||
List<Account> accounts = accountMapper.selectList(qw);
|
||||
if (CollectionUtil.isNotEmpty(accounts)) {
|
||||
Account account = accounts.get(0);
|
||||
|
||||
QueryWrapper<AccountExtend> accountExtendQW = new QueryWrapper<>();
|
||||
accountExtendQW.lambda().eq(AccountExtend::getAccountId, userHolder.getId());
|
||||
accountExtendQW.lambda().eq(AccountExtend::getAuthType, "Wechat");
|
||||
AccountExtend accountExtend = accountExtendMapper.selectOne(accountExtendQW);
|
||||
accountExtend.setAccountId(account.getId());
|
||||
accountExtendMapper.updateById(accountExtend);
|
||||
|
||||
accountMapper.deleteById(userHolder.getId());
|
||||
|
||||
String token = LocalCacheUtils.getTokenCache(String.valueOf(account.getId()));
|
||||
if (StringUtils.isNotBlank(token)) {
|
||||
//用户已登入
|
||||
result.setToken(token);
|
||||
} else {
|
||||
result.setToken(createAccountToken(account));
|
||||
}
|
||||
return result;
|
||||
}
|
||||
Account account = accountMapper.selectById(userHolder.getId());
|
||||
account.setUserEmail(email);
|
||||
accountMapper.updateById(account);
|
||||
return Boolean.TRUE;
|
||||
return result;
|
||||
}
|
||||
|
||||
public void updateAccountValidity(Long accountId, Long currentPeriodEnd){
|
||||
|
||||
Reference in New Issue
Block a user