Merge pull request #14 from Qtoss-AI/jason_dev

Jason dev
This commit is contained in:
Haiping 2024-09-24 21:23:52 -05:00 committed by GitHub
commit 6e611b7126
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 9 additions and 4 deletions

View file

@ -10,4 +10,5 @@ public interface IUserIdentity
string FullName { get; }
string? UserLanguage { get; }
string? Phone { get; }
string? AffiliateId { get; }
}

View file

@ -69,4 +69,7 @@ public class UserIdentity : IUserIdentity
[JsonPropertyName("phone")]
public string? Phone => _claims?.FirstOrDefault(x => x.Type == "phone")?.Value;
[JsonPropertyName("affiliateId")]
public string? AffiliateId => _claims?.FirstOrDefault(x => x.Type == "affiliateId")?.Value;
}

View file

@ -254,7 +254,8 @@ public class UserService : IUserService
new Claim("type", user.Type ?? UserType.Client),
new Claim("role", user.Role ?? UserRole.User),
new Claim(JwtRegisteredClaimNames.Jti, Guid.NewGuid().ToString()),
new Claim("phone", user.Phone ?? string.Empty)
new Claim("phone", user.Phone ?? string.Empty),
new Claim("affiliateId", user.AffiliateId ?? string.Empty)
};
var validators = _services.GetServices<IAuthenticationHook>();
@ -280,14 +281,14 @@ public class UserService : IUserService
};
var tokenHandler = new JwtSecurityTokenHandler();
var token = tokenHandler.CreateToken(tokenDescriptor);
SaveUserTokenExpiresCache(user.Id, expires).GetAwaiter().GetResult();
SaveUserTokenExpiresCache(user.Id, expires, expireInMinutes).GetAwaiter().GetResult();
return tokenHandler.WriteToken(token);
}
private async Task SaveUserTokenExpiresCache(string userId, DateTime expires)
private async Task SaveUserTokenExpiresCache(string userId, DateTime expires, int expireInMinutes)
{
var _cacheService = _services.GetRequiredService<ICacheService>();
await _cacheService.SetAsync<DateTime>(GetUserTokenExpiresCacheKey(userId), expires, null);
await _cacheService.SetAsync<DateTime>(GetUserTokenExpiresCacheKey(userId), expires, TimeSpan.FromMinutes(expireInMinutes));
}
private string GetUserTokenExpiresCacheKey(string userId)