50 lines
1.5 KiB
C#
50 lines
1.5 KiB
C#
using Microsoft.AspNetCore.Authorization;
|
||
using Volo.Abp.Application.Services;
|
||
using Volo.Abp.Users;
|
||
using Yi.Framework.AiHub.Domain.Entities.OpenApi;
|
||
using Yi.Framework.AiHub.Domain.Managers;
|
||
using Yi.Framework.SqlSugarCore.Abstractions;
|
||
|
||
namespace Yi.Framework.AiHub.Application.Services;
|
||
|
||
public class TokenService : ApplicationService
|
||
{
|
||
private readonly ISqlSugarRepository<TokenAggregateRoot> _tokenRepository;
|
||
private readonly TokenManager _tokenManager;
|
||
|
||
/// <summary>
|
||
/// 构造函数
|
||
/// </summary>
|
||
/// <param name="tokenRepository"></param>
|
||
/// <param name="tokenManager"></param>
|
||
public TokenService(ISqlSugarRepository<TokenAggregateRoot> tokenRepository, TokenManager tokenManager)
|
||
{
|
||
_tokenRepository = tokenRepository;
|
||
_tokenManager = tokenManager;
|
||
}
|
||
|
||
/// <summary>
|
||
/// 获取token
|
||
/// </summary>
|
||
/// <returns></returns>
|
||
[Authorize]
|
||
public async Task<string?> GetAsync()
|
||
{
|
||
return await _tokenManager.GetAsync(CurrentUser.GetId());
|
||
}
|
||
|
||
/// <summary>
|
||
/// 创建token
|
||
/// </summary>
|
||
/// <exception cref="UserFriendlyException"></exception>
|
||
[Authorize]
|
||
public async Task CreateAsync()
|
||
{
|
||
if (!CurrentUser.Roles.Contains("YiXinAi-Vip") && CurrentUser.UserName != "cc")
|
||
{
|
||
throw new UserFriendlyException("充值成为Vip,畅想第三方token服务");
|
||
}
|
||
|
||
await _tokenManager.CreateAsync(CurrentUser.GetId());
|
||
}
|
||
} |