Moves raising events for reseting/changing password out of the MembershipHelper ChangePassword method and to the places where it is being called

This commit is contained in:
Shannon
2017-09-18 16:56:43 +10:00
parent 4ec04c779a
commit 2a10eed059
3 changed files with 27 additions and 22 deletions

View File

@@ -18,6 +18,7 @@ using umbraco;
using legacyUser = umbraco.BusinessLogic.User;
using System.Net.Http;
using System.Collections.Specialized;
using Umbraco.Core.Security;
using Constants = Umbraco.Core.Constants;
@@ -60,6 +61,18 @@ namespace Umbraco.Web.Editors
var passwordChangeResult = Members.ChangePassword(Security.CurrentUser.Username, data, userProvider);
if (passwordChangeResult.Success)
{
var userMgr = this.TryGetOwinContext().Result.GetBackOfficeUserManager();
//raise the appropriate event
if (data.Reset.HasValue && data.Reset.Value)
{
userMgr.RaisePasswordResetEvent(Security.CurrentUser.Id);
}
else
{
userMgr.RaisePasswordChangedEvent(Security.CurrentUser.Id);
}
//even if we weren't resetting this, it is the correct value (null), otherwise if we were resetting then it will contain the new pword
var result = new ModelWithNotifications<string>(passwordChangeResult.Result.ResetPassword);
result.AddSuccessNotification(ui.Text("user", "password"), ui.Text("user", "passwordChanged"));

View File

@@ -717,21 +717,7 @@ namespace Umbraco.Web.Security
if (passwordModel == null) throw new ArgumentNullException("passwordModel");
if (membershipProvider == null) throw new ArgumentNullException("membershipProvider");
BackOfficeUserManager<BackOfficeIdentityUser> backofficeUserManager = null;
var userId = -1;
if (membershipProvider.IsUmbracoUsersProvider())
{
backofficeUserManager = _httpContext.GetOwinContext().GetBackOfficeUserManager();
if (backofficeUserManager != null)
{
var profile = _applicationContext.Services.UserService.GetProfileByUserName(username);
if (profile != null)
int.TryParse(profile.Id.ToString(), out userId);
}
}
//Are we resetting the password??
if (passwordModel.Reset.HasValue && passwordModel.Reset.Value)
{
@@ -751,9 +737,6 @@ namespace Umbraco.Web.Security
username,
membershipProvider.RequiresQuestionAndAnswer ? passwordModel.Answer : null);
if (membershipProvider.IsUmbracoUsersProvider() && backofficeUserManager != null && userId >= 0)
backofficeUserManager.RaisePasswordResetEvent(userId);
//return the generated pword
return Attempt.Succeed(new PasswordChangedModel { ResetPassword = newPass });
}
@@ -804,10 +787,7 @@ namespace Umbraco.Web.Security
try
{
var result = membershipProvider.ChangePassword(username, passwordModel.OldPassword, passwordModel.NewPassword);
if (result && backofficeUserManager != null && userId >= 0)
backofficeUserManager.RaisePasswordChangedEvent(userId);
return result == false
? Attempt.Fail(new PasswordChangedModel { ChangeError = new ValidationResult("Could not change password, invalid username or password", new[] { "value" }) })
: Attempt.Succeed(new PasswordChangedModel());

View File

@@ -481,6 +481,18 @@ namespace umbraco.cms.presentation.user
if (changePassResult.Success)
{
var userMgr = Context.GetOwinContext().GetBackOfficeUserManager();
//raise the appropriate event
if (changePasswordModel.Reset.HasValue && changePasswordModel.Reset.Value)
{
userMgr.RaisePasswordResetEvent(UmbracoUser.Id);
}
else
{
userMgr.RaisePasswordChangedEvent(UmbracoUser.Id);
}
//if it is successful, we need to show the generated password if there was one, so set
//that back on the control
passwordChangerControl.ChangingPasswordModel.GeneratedPassword = changePassResult.Result.ResetPassword;