Merge pull request !9 from Argo-QQ/dev-Refector

This commit is contained in:
Argo-QQ 2019-03-10 03:19:14 +08:00 committed by Argo
commit d16ef028d2
6 changed files with 8 additions and 10 deletions

View File

@ -1,7 +1,5 @@
using Bootstrap.Admin.Models;
using Bootstrap.DataAccess;
using Longbow;
using Longbow.Configuration;
using Longbow.Web;
using Microsoft.AspNetCore.Authentication;
using Microsoft.AspNetCore.Authentication.Cookies;
@ -10,6 +8,7 @@ using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using System;
using System.Linq;
using System.Net;
using System.Security.Claims;
using System.Threading.Tasks;
@ -63,7 +62,7 @@ namespace Bootstrap.Admin.Controllers
internal static void CreateLoginUser(IOnlineUsers onlineUserSvr, HttpContext context, LoginUser loginUser)
{
var agent = new UserAgent(context.Request.Headers["User-Agent"]);
loginUser.Ip = context.Connection.RemoteIpAddress?.ToString();
loginUser.Ip = (context.Connection.RemoteIpAddress ?? IPAddress.IPv6Loopback).ToString();
loginUser.City = onlineUserSvr.RetrieveLocaleByIp(loginUser.Ip);
loginUser.Browser = $"{agent.Browser.Name} {agent.Browser.Version}";
loginUser.OS = $"{agent.OS.Name} {agent.OS.Version}";

View File

@ -35,12 +35,11 @@ namespace Bootstrap.Admin.Controllers.Api
public bool Post([FromServices]IOnlineUsers onlineUserSvr, [FromBody]Log value)
{
var agent = new UserAgent(Request.Headers["User-Agent"]);
value.Ip = HttpContext.Connection.RemoteIpAddress?.ToString();
value.Ip = (HttpContext.Connection.RemoteIpAddress ?? IPAddress.IPv6Loopback).ToString();
value.Browser = $"{agent.Browser.Name} {agent.Browser.Version}";
value.OS = $"{agent.OS.Name} {agent.OS.Version}";
value.City = onlineUserSvr.RetrieveLocaleByIp(value.Ip);
value.UserName = User.Identity.Name;
if (string.IsNullOrEmpty(value.Ip)) value.Ip = IPAddress.IPv6Loopback.ToString();
return LogHelper.Save(value);
}
}

View File

@ -5,6 +5,7 @@ using Microsoft.AspNetCore.Http;
using Microsoft.Extensions.DependencyInjection;
using System;
using System.Linq;
using System.Net;
namespace Microsoft.AspNetCore.Builder
{
@ -43,7 +44,7 @@ namespace Microsoft.AspNetCore.Builder
var agent = new UserAgent(context.Request.Headers["User-Agent"]);
var v = new OnlineUser();
v.ConnectionId = key;
v.Ip = context.Connection.RemoteIpAddress?.ToString();
v.Ip = (context.Connection.RemoteIpAddress ?? IPAddress.IPv6Loopback).ToString();
v.Location = onlineUserSvr.RetrieveLocaleByIp(v.Ip);
v.Browser = $"{agent.Browser.Name} {agent.Browser.Version}";
v.OS = $"{agent.OS.Name} {agent.OS.Version}";

View File

@ -39,7 +39,6 @@ namespace Bootstrap.DataAccess
Result = "登录失败"
};
config(loginUser);
if (string.IsNullOrEmpty(loginUser.Ip)) loginUser.Ip = System.Net.IPAddress.IPv6Loopback.ToString();
var ret = DbContextManager.Create<User>().Authenticate(userName, password);
if (ret) loginUser.Result = "登录成功";
LoginHelper.Log(loginUser);

View File

@ -41,7 +41,7 @@ namespace Bootstrap.Admin.Controllers
var r = await Client.GetAsync("AccessDenied");
Assert.True(r.IsSuccessStatusCode);
var content = await r.Content.ReadAsStringAsync();
Assert.Contains("您无权访问本页面请联系网站管理员授权后再查看", content);
Assert.Contains("服务器拒绝处理您的请求", content);
}
}
}

View File

@ -14,7 +14,7 @@ namespace Bootstrap.DataAccess
Browser = "UnitTest",
City = "本地连接",
OS = "UnitTest",
Ip = "::",
Ip = "::1",
CRUD = "UnitTest",
RequestUrl = "~/Home/Index"
};
@ -30,7 +30,7 @@ namespace Bootstrap.DataAccess
Browser = "UnitTest",
City = "本地连接",
OS = "UnitTest",
Ip = "::",
Ip = "::1",
CRUD = "UnitTest",
RequestUrl = "~/Home/Index"
};