86 lines
2.7 KiB
C#
86 lines
2.7 KiB
C#
using LiveForum.Code.Base;
|
|
using LiveForum.Code.JwtInfrastructure;
|
|
using LiveForum.IService.Cdk;
|
|
using LiveForum.Model.Dto.Cdk;
|
|
|
|
using Microsoft.AspNetCore.Authorization;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
|
|
namespace LiveForum.WebApi.Controllers
|
|
{
|
|
/// <summary>
|
|
/// CDK激活相关接口
|
|
/// </summary>
|
|
[Route("api/[controller]/[action]")]
|
|
[ApiController]
|
|
[Authorize]
|
|
public class CdkController : ControllerBase
|
|
{
|
|
private readonly ICdkService _cdkService;
|
|
private readonly JwtUserInfoModel _userInfoModel;
|
|
|
|
/// <summary>
|
|
/// 构造函数
|
|
/// </summary>
|
|
/// <param name="cdkService">CDK服务</param>
|
|
/// <param name="userInfoModel">用户信息模型</param>
|
|
public CdkController(ICdkService cdkService, JwtUserInfoModel userInfoModel)
|
|
{
|
|
_cdkService = cdkService;
|
|
_userInfoModel = userInfoModel;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 检查CDK状态
|
|
/// GET /api/cdk/check-status
|
|
/// </summary>
|
|
/// <returns>CDK状态信息</returns>
|
|
[HttpGet]
|
|
[ActionName("check-status")]
|
|
public async Task<BaseResponse<CdkStatusDto>> CheckStatus()
|
|
{
|
|
var userId = _userInfoModel.UserId;
|
|
if (userId <= 0)
|
|
{
|
|
return new BaseResponse<CdkStatusDto>(ResponseCode.Unauthorized, "用户未登录");
|
|
}
|
|
|
|
var status = await _cdkService.CheckCdkStatusAsync(userId);
|
|
return new BaseResponse<CdkStatusDto>(status);
|
|
}
|
|
|
|
/// <summary>
|
|
/// 激活CDK
|
|
/// POST /api/cdk/activate
|
|
/// </summary>
|
|
/// <param name="request">激活请求</param>
|
|
/// <returns>激活结果</returns>
|
|
[HttpPost]
|
|
public async Task<BaseResponse<object>> Activate([FromBody] CdkActivateReq request)
|
|
{
|
|
var userId = _userInfoModel.UserId;
|
|
if (userId <= 0)
|
|
{
|
|
return new BaseResponse<object>(ResponseCode.Unauthorized, "用户未登录");
|
|
}
|
|
|
|
if (request == null || string.IsNullOrWhiteSpace(request.Code))
|
|
{
|
|
return new BaseResponse<object>(ResponseCode.ParamError, "请输入有效 CDK");
|
|
}
|
|
|
|
var result = await _cdkService.ActivateCdkAsync(userId, request.Code);
|
|
|
|
// 根据结果返回不同的响应码
|
|
if (result == "CDK 激活成功")
|
|
{
|
|
return new BaseResponse<object>(ResponseCode.Success, result);
|
|
}
|
|
else
|
|
{
|
|
return new BaseResponse<object>(ResponseCode.ParamError, result);
|
|
}
|
|
}
|
|
}
|
|
}
|