2018-06-07 00:45:47 +08:00
|
|
|
|
using Bootstrap.Admin.Query;
|
|
|
|
|
using Bootstrap.DataAccess;
|
2019-03-04 16:29:35 +08:00
|
|
|
|
using Longbow.Web;
|
2018-06-07 00:45:47 +08:00
|
|
|
|
using Longbow.Web.Mvc;
|
|
|
|
|
using Microsoft.AspNetCore.Mvc;
|
2019-01-16 14:19:33 +08:00
|
|
|
|
using System.Net;
|
2018-06-07 00:45:47 +08:00
|
|
|
|
|
|
|
|
|
namespace Bootstrap.Admin.Controllers.Api
|
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
///
|
|
|
|
|
/// </summary>
|
|
|
|
|
[Route("api/[controller]")]
|
2018-11-24 15:12:44 +08:00
|
|
|
|
[ApiController]
|
|
|
|
|
public class LogsController : ControllerBase
|
2018-06-07 00:45:47 +08:00
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
///
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="value"></param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
[HttpGet]
|
2018-11-24 15:12:44 +08:00
|
|
|
|
public QueryData<Log> Get([FromQuery]QueryLogOption value)
|
2018-06-07 00:45:47 +08:00
|
|
|
|
{
|
|
|
|
|
return value.RetrieveData();
|
|
|
|
|
}
|
2019-01-16 14:19:33 +08:00
|
|
|
|
|
2018-10-28 15:08:58 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
///
|
|
|
|
|
/// </summary>
|
2019-03-04 16:29:35 +08:00
|
|
|
|
/// <param name="onlineUserSvr"></param>
|
2019-04-08 16:01:40 +08:00
|
|
|
|
/// <param name="ipLocator"></param>
|
2018-10-28 15:08:58 +08:00
|
|
|
|
/// <param name="value"></param>
|
|
|
|
|
/// <returns></returns>
|
2018-06-07 00:45:47 +08:00
|
|
|
|
[HttpPost]
|
2019-04-08 16:01:40 +08:00
|
|
|
|
public bool Post([FromServices]IOnlineUsers onlineUserSvr, [FromServices]IIPLocatorProvider ipLocator, [FromBody]Log value)
|
2018-06-07 00:45:47 +08:00
|
|
|
|
{
|
2019-04-27 20:39:24 +08:00
|
|
|
|
value.UserAgent = Request.Headers["User-Agent"];
|
|
|
|
|
var agent = new UserAgent(value.UserAgent);
|
2019-03-09 19:18:03 +08:00
|
|
|
|
value.Ip = (HttpContext.Connection.RemoteIpAddress ?? IPAddress.IPv6Loopback).ToString();
|
2019-04-27 20:39:24 +08:00
|
|
|
|
value.Browser = $"{agent.Browser?.Name} {agent.Browser?.Version}";
|
|
|
|
|
value.OS = $"{agent.OS?.Name} {agent.OS?.Version}";
|
2019-04-08 16:01:40 +08:00
|
|
|
|
value.City = ipLocator.Locate(value.Ip);
|
2018-06-07 00:45:47 +08:00
|
|
|
|
value.UserName = User.Identity.Name;
|
2019-01-11 23:20:28 +08:00
|
|
|
|
return LogHelper.Save(value);
|
2018-06-07 00:45:47 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
2016-11-02 15:35:25 +08:00
|
|
|
|
}
|