|
@@ -50,7 +50,7 @@ public class IdentityAppService : IIdentityAppService, IScopeDependency
|
|
|
private readonly ISystemSettingCacheManager _systemSettingCacheManager;
|
|
|
private readonly IThirdIdentiyService _thirdIdentiyService;
|
|
|
private readonly IThirdAccountRepository _thirdAccountRepository;
|
|
|
- private readonly IRepository<GuiderInfo> _guiderInfoRepository;
|
|
|
+ private readonly IGuiderInfoRepository _guiderInfoRepository;
|
|
|
private readonly IVolunteerRepository _volunteerRepository;
|
|
|
|
|
|
public IdentityAppService(
|
|
@@ -68,7 +68,7 @@ public class IdentityAppService : IIdentityAppService, IScopeDependency
|
|
|
IThirdAccountRepository thirdAccountRepository,
|
|
|
ISessionContext sessionContext,
|
|
|
IRepository<Citizen> citizenRepository,
|
|
|
- IRepository<GuiderInfo> guiderInfoRepository,
|
|
|
+ IGuiderInfoRepository guiderInfoRepository,
|
|
|
IVolunteerRepository volunteerRepository)
|
|
|
{
|
|
|
_accountRepository = accountRepository;
|
|
@@ -322,16 +322,41 @@ public class IdentityAppService : IIdentityAppService, IScopeDependency
|
|
|
}
|
|
|
var thirdToken = await _thirdIdentiyService.GetTokenAsync(thirdDto);
|
|
|
var phone = await _thirdIdentiyService.GetPhoneNumberAsync(thirdDto);
|
|
|
- var thirdAccount = await _thirdAccountRepository.QueryByOpenIdAsync(thirdToken.OpenId);
|
|
|
+ var thirdAccount = await _thirdAccountRepository.GetByOpenIdAsync(thirdToken.OpenId);
|
|
|
|
|
|
// 新用户注册
|
|
|
if (thirdAccount is null)
|
|
|
{
|
|
|
thirdAccount = thirdToken.Adapt<ThirdAccount>();
|
|
|
+ thirdAccount.CitizenType = EReadPackUserType.Citizen;
|
|
|
thirdAccount.PhoneNumber = phone.PhoneNumber;
|
|
|
+ var guider = await _guiderInfoRepository.GetByPhoneNumberAsync(phone.PhoneNumber);
|
|
|
+ if (guider != null)
|
|
|
+ {
|
|
|
+ thirdAccount.CitizenType = EReadPackUserType.Guider;
|
|
|
+ thirdAccount.UserId = guider.Id;
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ var citizen = await _citizenRepository.Queryable().Where(m => m.PhoneNumber == phone.PhoneNumber).FirstAsync();
|
|
|
+ thirdAccount.UserId = citizen.Id;
|
|
|
+ }
|
|
|
thirdAccount.Id = await _thirdAccountRepository.AddAsync(thirdAccount);
|
|
|
}
|
|
|
|
|
|
+ return await GetJwtToken(thirdAccount);
|
|
|
+ }
|
|
|
+
|
|
|
+ public async Task<TokenOutDto> RefreshTokenAsync(string openId)
|
|
|
+ {
|
|
|
+ var thirdAccount = await _thirdAccountRepository.GetByOpenIdAsync(openId)
|
|
|
+ ?? throw UserFriendlyException.SameMessage("未找到用户信息");
|
|
|
+
|
|
|
+ return await GetJwtToken(thirdAccount);
|
|
|
+ }
|
|
|
+
|
|
|
+ private async Task<TokenOutDto> GetJwtToken(ThirdAccount thirdAccount)
|
|
|
+ {
|
|
|
var jwtOptions = _identityOptionsAccessor.Value.Jwt;
|
|
|
var claims = new List<Claim>
|
|
|
{
|
|
@@ -345,6 +370,15 @@ public class IdentityAppService : IIdentityAppService, IScopeDependency
|
|
|
await _cacheAudience.SetAsync(audience.Id, audience, TimeSpan.FromSeconds(expiredSeconds));
|
|
|
var token = _jwtSecurity.EncodeJwtToken(claims, audience.Ticket);
|
|
|
var isVolunteer = await _volunteerRepository.IsVolunteerAsync(thirdAccount.PhoneNumber);
|
|
|
- return new TokenOutDto(thirdAccount.CitizenType, token, isVolunteer);
|
|
|
+ return new TokenOutDto()
|
|
|
+ {
|
|
|
+ UserType = thirdAccount.CitizenType,
|
|
|
+ Token = token,
|
|
|
+ IsVolunteer = isVolunteer,
|
|
|
+ OpenId = thirdAccount.OpenId,
|
|
|
+ PhoneNumber = thirdAccount.PhoneNumber,
|
|
|
+ InvitationCode = thirdAccount.InvitationCode,
|
|
|
+ UserName = thirdAccount.UserName
|
|
|
+ };
|
|
|
}
|
|
|
- }
|
|
|
+}
|