From 38571f2cdd93712af30bdf327b6d6cce27611e06 Mon Sep 17 00:00:00 2001 From: Sebastiaan Janssen Date: Sat, 29 Apr 2017 13:43:51 +0200 Subject: [PATCH] Wire up LoginSuccess and LoginRequiresVerification --- src/Umbraco.Core/Auditing/IdentityAuditEventArgs.cs | 3 ++- src/Umbraco.Core/Security/BackOfficeSignInManager.cs | 2 ++ src/Umbraco.Core/Security/BackOfficeUserManager.cs | 8 ++++++++ src/Umbraco.Web/Editors/AuthenticationController.cs | 11 ++++++++++- 4 files changed, 22 insertions(+), 2 deletions(-) diff --git a/src/Umbraco.Core/Auditing/IdentityAuditEventArgs.cs b/src/Umbraco.Core/Auditing/IdentityAuditEventArgs.cs index bc53aa3b64..e6d0b6ddb2 100644 --- a/src/Umbraco.Core/Auditing/IdentityAuditEventArgs.cs +++ b/src/Umbraco.Core/Auditing/IdentityAuditEventArgs.cs @@ -65,6 +65,7 @@ namespace Umbraco.Core.Auditing AccountCreated, //not yet being called ResetAccessFailedCount, AccountUpdated, - PasswordReset + PasswordReset, + LoginRequiresVerification } } diff --git a/src/Umbraco.Core/Security/BackOfficeSignInManager.cs b/src/Umbraco.Core/Security/BackOfficeSignInManager.cs index 71bd2474cd..fd1d828369 100644 --- a/src/Umbraco.Core/Security/BackOfficeSignInManager.cs +++ b/src/Umbraco.Core/Security/BackOfficeSignInManager.cs @@ -191,6 +191,8 @@ namespace Umbraco.Core.Security //track the last login date user.LastLoginDateUtc = DateTime.UtcNow; + if (user.AccessFailedCount > 0) + user.AccessFailedCount = 0; await UserManager.UpdateAsync(user); _logger.WriteCore(TraceEventType.Information, 0, diff --git a/src/Umbraco.Core/Security/BackOfficeUserManager.cs b/src/Umbraco.Core/Security/BackOfficeUserManager.cs index 7c3139d323..10903acdc9 100644 --- a/src/Umbraco.Core/Security/BackOfficeUserManager.cs +++ b/src/Umbraco.Core/Security/BackOfficeUserManager.cs @@ -361,6 +361,14 @@ namespace Umbraco.Core.Security }); } + internal void RaiseLoginRequiresVerificationEvent(int userId) + { + OnAuthResetAccessFailedCount(new IdentityAuditEventArgs(AuditEvent.LoginRequiresVerification) + { + AffectedUser = userId + }); + } + public override Task UpdateAsync(T user) { var result = base.UpdateAsync(user); diff --git a/src/Umbraco.Web/Editors/AuthenticationController.cs b/src/Umbraco.Web/Editors/AuthenticationController.cs index 398657e63d..72b11199d4 100644 --- a/src/Umbraco.Web/Editors/AuthenticationController.cs +++ b/src/Umbraco.Web/Editors/AuthenticationController.cs @@ -131,7 +131,9 @@ namespace Umbraco.Web.Editors var http = EnsureHttpContext(); var result = await SignInManager.PasswordSignInAsync( - loginModel.Username, loginModel.Password, isPersistent: true, shouldLockout: true); + loginModel.Username, loginModel.Password, isPersistent: true, shouldLockout: true); + + var backofficeUserManager = GetBackofficeUserManager(); switch (result) { @@ -139,6 +141,10 @@ namespace Umbraco.Web.Editors //get the user var user = Security.GetBackOfficeUser(loginModel.Username); + + if (backofficeUserManager != null) + backofficeUserManager.RaiseLoginSuccessEvent(user.Id); + return SetPrincipalAndReturnUserDetail(user); case SignInStatus.RequiresVerification: @@ -173,6 +179,9 @@ namespace Umbraco.Web.Editors userId = attemptedUser.Id }); + if (backofficeUserManager != null) + backofficeUserManager.RaiseLoginRequiresVerificationEvent(attemptedUser.Id); + return verifyResponse; case SignInStatus.LockedOut: