63 lines
2.1 KiB
C#
63 lines
2.1 KiB
C#
using Competition.Common.Util;
|
||
using CompetitionAPI.api.unity;
|
||
using CompetitionAPI.Util;
|
||
using Microsoft.AspNetCore.Authorization;
|
||
using Microsoft.AspNetCore.Http;
|
||
using Microsoft.AspNetCore.Mvc;
|
||
using Org.BouncyCastle.Ocsp;
|
||
|
||
namespace CompetitionAPI.Controllers.unity.newinterface
|
||
{
|
||
[Route("unity/[controller]")]
|
||
[ApiController]
|
||
public class DetectingIPController : Controller
|
||
{
|
||
private readonly IHttpContextAccessor _httpContextAccessor;
|
||
|
||
Competition.Mysql.BLL.admin_user bll = new Competition.Mysql.BLL.admin_user();
|
||
|
||
Competition.Mysql.BLL.admin_ip bll_admin_ip = new Competition.Mysql.BLL.admin_ip();
|
||
|
||
Competition.Mysql.BLL.pow_config config_bll = new Competition.Mysql.BLL.pow_config();
|
||
|
||
public DetectingIPController(IHttpContextAccessor httpContextAccessor)
|
||
{
|
||
_httpContextAccessor = httpContextAccessor;
|
||
}
|
||
|
||
/// <summary>
|
||
/// 检测考试IP接口
|
||
/// </summary>
|
||
/// <returns></returns>
|
||
[Authorize]
|
||
[HttpPost]
|
||
[APIFilter]
|
||
public JsonResult Index([FromForm] DetectingIPRequest req)
|
||
{
|
||
try
|
||
{
|
||
var ip_list = bll_admin_ip.GetModelList("");
|
||
var items = ip_list.Where(s => req.IP.Contains(s.IP)).ToList();
|
||
if (items.Count <= 0)
|
||
{
|
||
var config = config_bll.GetModelList("").FirstOrDefault();
|
||
if (config != null)
|
||
{
|
||
if (!string.IsNullOrEmpty(config.LimitIp) && config.LimitIp == "1")
|
||
{
|
||
return Json(Tool.GetJsonWithCode(APICode.Fail, "登录ip限制!登录ip:" + req.IP));
|
||
}
|
||
}
|
||
}
|
||
|
||
return Json(Tool.GetJsonWithCode(APICode.Success, "成功"));
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
LogHelper.WriteLog(ex.Message + ",行号:" + ex.StackTrace);
|
||
return Json(Tool.GetJsonWithCode(APICode.Fail, "发生错误,请联系管理员。"));
|
||
}
|
||
}
|
||
}
|
||
}
|