TASK:绑定邮箱、绑定微信;
This commit is contained in:
@@ -9,6 +9,7 @@ import com.ai.da.mapper.primary.entity.TrialOrder;
|
|||||||
import com.ai.da.model.dto.*;
|
import com.ai.da.model.dto.*;
|
||||||
import com.ai.da.model.vo.AccountLoginVO;
|
import com.ai.da.model.vo.AccountLoginVO;
|
||||||
import com.ai.da.model.vo.AccountPreLoginVO;
|
import com.ai.da.model.vo.AccountPreLoginVO;
|
||||||
|
import com.ai.da.model.vo.BindEmailVO;
|
||||||
import com.ai.da.model.vo.PersonalHomepageVO;
|
import com.ai.da.model.vo.PersonalHomepageVO;
|
||||||
import com.ai.da.service.AccountService;
|
import com.ai.da.service.AccountService;
|
||||||
import io.swagger.annotations.Api;
|
import io.swagger.annotations.Api;
|
||||||
@@ -326,7 +327,7 @@ public class AccountController {
|
|||||||
|
|
||||||
@GetMapping("/bindEmail")
|
@GetMapping("/bindEmail")
|
||||||
@ApiOperation(value = "绑定邮箱")
|
@ApiOperation(value = "绑定邮箱")
|
||||||
public Response<Boolean> bindEmail(@RequestParam("email") String email) {
|
public Response<BindEmailVO> bindEmail(@RequestParam("email") String email) {
|
||||||
return Response.success(accountService.bindEmail(email));
|
return Response.success(accountService.bindEmail(email));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
9
src/main/java/com/ai/da/model/vo/BindEmailVO.java
Normal file
9
src/main/java/com/ai/da/model/vo/BindEmailVO.java
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
package com.ai.da.model.vo;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
public class BindEmailVO {
|
||||||
|
|
||||||
|
private String token;
|
||||||
|
}
|
||||||
@@ -7,6 +7,7 @@ import com.ai.da.mapper.primary.entity.TrialOrder;
|
|||||||
import com.ai.da.model.dto.*;
|
import com.ai.da.model.dto.*;
|
||||||
import com.ai.da.model.vo.AccountLoginVO;
|
import com.ai.da.model.vo.AccountLoginVO;
|
||||||
import com.ai.da.model.vo.AccountPreLoginVO;
|
import com.ai.da.model.vo.AccountPreLoginVO;
|
||||||
|
import com.ai.da.model.vo.BindEmailVO;
|
||||||
import com.ai.da.model.vo.PersonalHomepageVO;
|
import com.ai.da.model.vo.PersonalHomepageVO;
|
||||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||||
import com.baomidou.mybatisplus.extension.service.IService;
|
import com.baomidou.mybatisplus.extension.service.IService;
|
||||||
@@ -49,7 +50,7 @@ public interface AccountService extends IService<Account> {
|
|||||||
*/
|
*/
|
||||||
Boolean bindEmail(AccountBindEmailDTO accountBindEmailDTO);
|
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());
|
qw.lambda().eq(Account::getUserEmail, emailSendDTO.getEmail());
|
||||||
List<Account> accounts = accountMapper.selectList(qw);
|
List<Account> accounts = accountMapper.selectList(qw);
|
||||||
if (CollectionUtil.isNotEmpty(accounts)) {
|
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,
|
result = SendEmailUtil.send(emailSendDTO.getEmail(), null,
|
||||||
SendEmailUtil.BIND_MAILBOX_TEMPLATE_ID, randomVerifyCode);
|
SendEmailUtil.BIND_MAILBOX_TEMPLATE_ID, randomVerifyCode);
|
||||||
@@ -2562,6 +2569,7 @@ public class AccountServiceImpl extends ServiceImpl<AccountMapper, Account> impl
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@Transactional
|
||||||
public AccountExtend bindWeChat(String code) {
|
public AccountExtend bindWeChat(String code) {
|
||||||
// 1. 获取 access_token 和 openid
|
// 1. 获取 access_token 和 openid
|
||||||
JSONObject accessTokenResponse = getAccessTokenFromWeChat(code);
|
JSONObject accessTokenResponse = getAccessTokenFromWeChat(code);
|
||||||
@@ -2588,7 +2596,14 @@ public class AccountServiceImpl extends ServiceImpl<AccountMapper, Account> impl
|
|||||||
List<AccountExtend> accountExtends = accountExtendMapper.selectList(qw);
|
List<AccountExtend> accountExtends = accountExtendMapper.selectList(qw);
|
||||||
|
|
||||||
if (CollectionUtil.isNotEmpty(accountExtends)) {
|
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();
|
AccountExtend accountExtendInsert = new AccountExtend();
|
||||||
@@ -2625,12 +2640,40 @@ public class AccountServiceImpl extends ServiceImpl<AccountMapper, Account> impl
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Boolean bindEmail(String email) {
|
@Transactional
|
||||||
|
public BindEmailVO bindEmail(String email) {
|
||||||
AuthPrincipalVo userHolder = UserContext.getUserHolder();
|
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 account = accountMapper.selectById(userHolder.getId());
|
||||||
account.setUserEmail(email);
|
account.setUserEmail(email);
|
||||||
accountMapper.updateById(account);
|
accountMapper.updateById(account);
|
||||||
return Boolean.TRUE;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void updateAccountValidity(Long accountId, Long currentPeriodEnd){
|
public void updateAccountValidity(Long accountId, Long currentPeriodEnd){
|
||||||
|
|||||||
Reference in New Issue
Block a user