68 lines
2.2 KiB
C#
68 lines
2.2 KiB
C#
using LiveForum.Code.Base;
|
|
using LiveForum.Code.JwtInfrastructure;
|
|
using LiveForum.IService.RealName;
|
|
using LiveForum.Model.Dto.RealName;
|
|
|
|
using Microsoft.AspNetCore.Authorization;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
|
|
namespace LiveForum.WebApi.Controllers
|
|
{
|
|
/// <summary>
|
|
/// 实名认证接口
|
|
/// </summary>
|
|
[Route("api/Auth/[action]")]
|
|
[ApiController]
|
|
[Authorize]
|
|
public class RealNameController : ControllerBase
|
|
{
|
|
private readonly IRealNameService _realNameService;
|
|
private readonly JwtUserInfoModel _userInfo;
|
|
|
|
public RealNameController(IRealNameService realNameService, JwtUserInfoModel userInfo)
|
|
{
|
|
_realNameService = realNameService;
|
|
_userInfo = userInfo;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 检查实名认证状态
|
|
/// </summary>
|
|
[HttpGet]
|
|
public async Task<BaseResponse<RealNameStatusDto>> RealNameStatus()
|
|
{
|
|
var userId = long.Parse(_userInfo.UserName);
|
|
var status = await _realNameService.CheckStatusAsync(userId);
|
|
return new BaseResponse<RealNameStatusDto>(status);
|
|
}
|
|
|
|
/// <summary>
|
|
/// 实名认证
|
|
/// </summary>
|
|
[HttpPost]
|
|
public async Task<BaseResponse<string>> RealNameVerify([FromBody] RealNameVerifyReq req)
|
|
{
|
|
if (req == null || string.IsNullOrWhiteSpace(req.RealName) || string.IsNullOrWhiteSpace(req.IdCardNumber))
|
|
{
|
|
return new BaseResponse<string>(ResponseCode.Error, "请输入姓名和身份证号");
|
|
}
|
|
|
|
if (req.IdCardNumber.Length != 18)
|
|
{
|
|
return new BaseResponse<string>(ResponseCode.Error, "请输入18位身份证号");
|
|
}
|
|
|
|
var userId = long.Parse(_userInfo.UserName);
|
|
var clientIp = HttpContext.Connection.RemoteIpAddress?.ToString();
|
|
var result = await _realNameService.VerifyAsync(userId, req.RealName, req.IdCardNumber, clientIp);
|
|
|
|
if (result == "实名认证成功")
|
|
{
|
|
return new BaseResponse<string>(result);
|
|
}
|
|
|
|
return new BaseResponse<string>(ResponseCode.Error, result);
|
|
}
|
|
}
|
|
}
|