fix #2176 - update LastIPAddress correctly during login
This commit is contained in:
parent
d3c40a7e8b
commit
eed27e101a
|
@ -184,7 +184,7 @@
|
||||||
var interop = new Interop(JSRuntime);
|
var interop = new Interop(JSRuntime);
|
||||||
if (await interop.FormValid(login))
|
if (await interop.FormValid(login))
|
||||||
{
|
{
|
||||||
var user = new User { SiteId = PageState.Site.SiteId, Username = _username, Password = _password};
|
var user = new User { SiteId = PageState.Site.SiteId, Username = _username, Password = _password, LastIPAddress = SiteState.RemoteIPAddress};
|
||||||
|
|
||||||
if (!twofactor)
|
if (!twofactor)
|
||||||
{
|
{
|
||||||
|
|
|
@ -327,6 +327,8 @@ namespace Oqtane.Controllers
|
||||||
var result = await _identitySignInManager.CheckPasswordSignInAsync(identityuser, user.Password, true);
|
var result = await _identitySignInManager.CheckPasswordSignInAsync(identityuser, user.Password, true);
|
||||||
if (result.Succeeded)
|
if (result.Succeeded)
|
||||||
{
|
{
|
||||||
|
var LastIPAddress = user.LastIPAddress;
|
||||||
|
|
||||||
user = _users.GetUser(user.Username);
|
user = _users.GetUser(user.Username);
|
||||||
if (user.TwoFactorRequired)
|
if (user.TwoFactorRequired)
|
||||||
{
|
{
|
||||||
|
@ -353,7 +355,7 @@ namespace Oqtane.Controllers
|
||||||
{
|
{
|
||||||
loginUser.IsAuthenticated = true;
|
loginUser.IsAuthenticated = true;
|
||||||
loginUser.LastLoginOn = DateTime.UtcNow;
|
loginUser.LastLoginOn = DateTime.UtcNow;
|
||||||
loginUser.LastIPAddress = HttpContext.Connection.RemoteIpAddress.ToString();
|
loginUser.LastIPAddress = LastIPAddress;
|
||||||
_users.UpdateUser(loginUser);
|
_users.UpdateUser(loginUser);
|
||||||
_logger.Log(LogLevel.Information, this, LogFunction.Security, "User Login Successful {Username}", user.Username);
|
_logger.Log(LogLevel.Information, this, LogFunction.Security, "User Login Successful {Username}", user.Username);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,21 +1,25 @@
|
||||||
using System;
|
using System;
|
||||||
using System.Diagnostics;
|
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using Microsoft.AspNetCore.Antiforgery;
|
using Microsoft.AspNetCore.Antiforgery;
|
||||||
using Microsoft.AspNetCore.Http;
|
using Microsoft.AspNetCore.Http;
|
||||||
|
using Microsoft.AspNetCore.Http.Extensions;
|
||||||
using Microsoft.AspNetCore.Mvc;
|
using Microsoft.AspNetCore.Mvc;
|
||||||
using Microsoft.AspNetCore.Mvc.Filters;
|
using Microsoft.AspNetCore.Mvc.Filters;
|
||||||
using Microsoft.AspNetCore.Mvc.ViewFeatures;
|
using Microsoft.AspNetCore.Mvc.ViewFeatures;
|
||||||
|
using Microsoft.Extensions.Logging;
|
||||||
|
using Oqtane.Shared;
|
||||||
|
|
||||||
namespace Oqtane.Security
|
namespace Oqtane.Security
|
||||||
{
|
{
|
||||||
public class AutoValidateAntiforgeryTokenFilter : IAsyncAuthorizationFilter, IAntiforgeryPolicy
|
public class AutoValidateAntiforgeryTokenFilter : IAsyncAuthorizationFilter, IAntiforgeryPolicy
|
||||||
{
|
{
|
||||||
private readonly IAntiforgery _antiforgery;
|
private readonly IAntiforgery _antiforgery;
|
||||||
|
private readonly ILogger<AutoValidateAntiforgeryTokenFilter> _filelogger;
|
||||||
|
|
||||||
public AutoValidateAntiforgeryTokenFilter(IAntiforgery antiforgery)
|
public AutoValidateAntiforgeryTokenFilter(IAntiforgery antiforgery, ILogger<AutoValidateAntiforgeryTokenFilter> filelogger)
|
||||||
{
|
{
|
||||||
_antiforgery = antiforgery;
|
_antiforgery = antiforgery;
|
||||||
|
_filelogger = filelogger;
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task OnAuthorizationAsync(AuthorizationFilterContext context)
|
public async Task OnAuthorizationAsync(AuthorizationFilterContext context)
|
||||||
|
@ -39,7 +43,7 @@ namespace Oqtane.Security
|
||||||
catch
|
catch
|
||||||
{
|
{
|
||||||
context.Result = new AntiforgeryValidationFailedResult();
|
context.Result = new AntiforgeryValidationFailedResult();
|
||||||
Debug.WriteLine($"Oqtane Error: AutoValidateAntiforgeryTokenFilter Failure on {context.HttpContext.Request.Path}");
|
_filelogger.LogError(Utilities.LogMessage(this, $"AutoValidateAntiforgeryTokenFilter Failure For {context.HttpContext.Request.GetEncodedUrl()}"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user