From 66e3a00e5650524f6fc3408fe69364cef27fdb92 Mon Sep 17 00:00:00 2001 From: Sebastiaan Janssen Date: Sun, 4 Jun 2017 15:18:24 +0200 Subject: [PATCH] Raise unlocking and saving events from EditUser.aspx --- .../Security/BackOfficeUserManager.cs | 16 ++++++++++++++ .../umbraco/users/EditUser.aspx.cs | 21 +++++++++++++++++-- 2 files changed, 35 insertions(+), 2 deletions(-) diff --git a/src/Umbraco.Core/Security/BackOfficeUserManager.cs b/src/Umbraco.Core/Security/BackOfficeUserManager.cs index 9d456be458..6b700a60df 100644 --- a/src/Umbraco.Core/Security/BackOfficeUserManager.cs +++ b/src/Umbraco.Core/Security/BackOfficeUserManager.cs @@ -319,6 +319,14 @@ namespace Umbraco.Core.Security return await Task.FromResult(IdentityResult.Success); } + internal void RaiseAccountUpdatedEvent(int userId) + { + OnAccountUpdated(new IdentityAuditEventArgs(AuditEvent.AccountUpdated) + { + AffectedUser = userId + }); + } + internal void RaisePasswordChangedEvent(int userId) { OnPasswordChanged(new IdentityAuditEventArgs(AuditEvent.PasswordChanged) @@ -343,6 +351,14 @@ namespace Umbraco.Core.Security }); } + internal void RaiseAccountUnlockedEvent(int userId) + { + OnAccountUnlocked(new IdentityAuditEventArgs(AuditEvent.AccountUnlocked) + { + AffectedUser = userId + }); + } + internal void RaiseResetAccessFailedCountEvent(int userId) { OnResetAccessFailedCount(new IdentityAuditEventArgs(AuditEvent.ResetAccessFailedCount) diff --git a/src/Umbraco.Web/umbraco.presentation/umbraco/users/EditUser.aspx.cs b/src/Umbraco.Web/umbraco.presentation/umbraco/users/EditUser.aspx.cs index 91a8677c81..778a1ee0f5 100644 --- a/src/Umbraco.Web/umbraco.presentation/umbraco/users/EditUser.aspx.cs +++ b/src/Umbraco.Web/umbraco.presentation/umbraco/users/EditUser.aspx.cs @@ -33,6 +33,7 @@ using Umbraco.Core.Services; using PropertyType = umbraco.cms.businesslogic.propertytype.PropertyType; using System.Text.RegularExpressions; using System.Text; +using Umbraco.Core.Models.Identity; namespace umbraco.cms.presentation.user { @@ -520,15 +521,21 @@ namespace umbraco.cms.presentation.user //update the membership provider UpdateMembershipProvider(membershipUser); + var backofficeUserManager = GetBackofficeUserManager(); + //update the Umbraco user properties - even though we are updating some of these properties in the membership provider that is // ok since the membership provider might be storing these details someplace totally different! But we want to keep our UI in sync. u.Name = uname.Text.Trim(); u.Language = userLanguage.SelectedValue; u.UserType = UserType.GetUserType(int.Parse(userType.SelectedValue)); u.Email = email.Text.Trim(); - u.LoginName = lname.Text; + u.LoginName = lname.Text; u.Disabled = Disabled.Checked; - u.NoConsole = NoConsole.Checked; + if (u.NoConsole && NoConsole.Checked == false && backofficeUserManager != null) + //unlocking the user + backofficeUserManager.RaiseAccountUnlockedEvent(u.Id); + + u.NoConsole = NoConsole.Checked; int startNode; if (int.TryParse(contentPicker.Value, out startNode) == false) @@ -560,6 +567,8 @@ namespace umbraco.cms.presentation.user } u.Save(); + if(backofficeUserManager != null) + backofficeUserManager.RaiseAccountUpdatedEvent(u.Id); // save data if (cName.Text != "") @@ -631,5 +640,13 @@ namespace umbraco.cms.presentation.user /// To modify move field declaration from designer file to code-behind file. /// protected TabView UserTabs; + + internal BackOfficeUserManager GetBackofficeUserManager() + { + return HttpContext.Current == null + ? null + : HttpContext.Current.GetOwinContext().GetBackOfficeUserManager(); + } + } }