diff --git a/src/Microsoft.Extensions.Identity.Core/RoleManager.cs b/src/Microsoft.Extensions.Identity.Core/RoleManager.cs index 22d0b1a7b0..ac93b9941e 100644 --- a/src/Microsoft.Extensions.Identity.Core/RoleManager.cs +++ b/src/Microsoft.Extensions.Identity.Core/RoleManager.cs @@ -160,7 +160,7 @@ namespace Microsoft.AspNetCore.Identity { throw new ArgumentNullException(nameof(role)); } - var result = await ValidateRoleInternal(role); + var result = await ValidateRoleAsync(role); if (!result.Succeeded) { return result; @@ -415,7 +415,13 @@ namespace Microsoft.AspNetCore.Identity _disposed = true; } - private async Task ValidateRoleInternal(TRole role) + /// + /// Should return if validation is successful. This is + /// called before saving the role via Create or Update. + /// + /// The role + /// A representing whether validation was successful. + protected virtual async Task ValidateRoleAsync(TRole role) { var errors = new List(); foreach (var v in RoleValidators) @@ -434,9 +440,14 @@ namespace Microsoft.AspNetCore.Identity return IdentityResult.Success; } - private async Task UpdateRoleAsync(TRole role) + /// + /// Called to update the role after validating and updating the normalized role name. + /// + /// The role. + /// Whether the operation was successful. + protected virtual async Task UpdateRoleAsync(TRole role) { - var result = await ValidateRoleInternal(role); + var result = await ValidateRoleAsync(role); if (!result.Succeeded) { return result; diff --git a/src/Microsoft.Extensions.Identity.Core/UserManager.cs b/src/Microsoft.Extensions.Identity.Core/UserManager.cs index 9f6d06c937..5aa64f3e10 100644 --- a/src/Microsoft.Extensions.Identity.Core/UserManager.cs +++ b/src/Microsoft.Extensions.Identity.Core/UserManager.cs @@ -454,7 +454,7 @@ namespace Microsoft.AspNetCore.Identity { ThrowIfDisposed(); await UpdateSecurityStampInternal(user); - var result = await ValidateUserInternal(user); + var result = await ValidateUserAsync(user); if (!result.Succeeded) { return result; @@ -872,8 +872,7 @@ namespace Microsoft.AspNetCore.Identity { return IdentityResult.Failed(ErrorDescriber.InvalidToken()); } - var passwordStore = GetPasswordStore(); - var result = await UpdatePasswordHash(passwordStore, user, newPassword); + var result = await UpdatePasswordHash(user, newPassword, validatePassword: true); if (!result.Succeeded) { return result; @@ -2253,7 +2252,7 @@ namespace Microsoft.AspNetCore.Identity } } - internal IUserTwoFactorStore GetUserTwoFactorStore() + private IUserTwoFactorStore GetUserTwoFactorStore() { var cast = Store as IUserTwoFactorStore; if (cast == null) @@ -2263,7 +2262,7 @@ namespace Microsoft.AspNetCore.Identity return cast; } - internal IUserLockoutStore GetUserLockoutStore() + private IUserLockoutStore GetUserLockoutStore() { var cast = Store as IUserLockoutStore; if (cast == null) @@ -2273,7 +2272,7 @@ namespace Microsoft.AspNetCore.Identity return cast; } - internal IUserEmailStore GetEmailStore(bool throwOnFail = true) + private IUserEmailStore GetEmailStore(bool throwOnFail = true) { var cast = Store as IUserEmailStore; if (throwOnFail && cast == null) @@ -2283,7 +2282,7 @@ namespace Microsoft.AspNetCore.Identity return cast; } - internal IUserPhoneNumberStore GetPhoneNumberStore() + private IUserPhoneNumberStore GetPhoneNumberStore() { var cast = Store as IUserPhoneNumberStore; if (cast == null) @@ -2304,7 +2303,7 @@ namespace Microsoft.AspNetCore.Identity } // Update the security stamp if the store supports it - internal async Task UpdateSecurityStampInternal(TUser user) + private async Task UpdateSecurityStampInternal(TUser user) { if (SupportsUserSecurityStamp) { @@ -2312,12 +2311,22 @@ namespace Microsoft.AspNetCore.Identity } } - internal async Task UpdatePasswordHash(IUserPasswordStore passwordStore, + /// + /// Updates a user's password hash. + /// + /// The user. + /// The new password. + /// Whether to validate the password. + /// Whether the password has was successfully updated. + protected virtual Task UpdatePasswordHash(TUser user, string newPassword, bool validatePassword) + => UpdatePasswordHash(GetPasswordStore(), user, newPassword, validatePassword); + + private async Task UpdatePasswordHash(IUserPasswordStore passwordStore, TUser user, string newPassword, bool validatePassword = true) { if (validatePassword) { - var validate = await ValidatePasswordInternal(user, newPassword); + var validate = await ValidatePasswordAsync(user, newPassword); if (!validate.Succeeded) { return validate; @@ -2377,16 +2386,22 @@ namespace Microsoft.AspNetCore.Identity /// - /// Generates the token purpose used to change email + /// Generates the token purpose used to change email. /// - /// - /// + /// The new email address. + /// The token purpose. protected static string GetChangeEmailTokenPurpose(string newEmail) { return "ChangeEmail:" + newEmail; } - private async Task ValidateUserInternal(TUser user) + /// + /// Should return if validation is successful. This is + /// called before saving the user via Create or Update. + /// + /// The user + /// A representing whether validation was successful. + protected async Task ValidateUserAsync(TUser user) { if (SupportsUserSecurityStamp) { @@ -2413,7 +2428,14 @@ namespace Microsoft.AspNetCore.Identity return IdentityResult.Success; } - private async Task ValidatePasswordInternal(TUser user, string password) + /// + /// Should return if validation is successful. This is + /// called before updating the password hash. + /// + /// The user. + /// The password. + /// A representing whether validation was successful. + protected async Task ValidatePasswordAsync(TUser user, string password) { var errors = new List(); foreach (var v in PasswordValidators) @@ -2432,9 +2454,14 @@ namespace Microsoft.AspNetCore.Identity return IdentityResult.Success; } - private async Task UpdateUserAsync(TUser user) + /// + /// Called to update the user after validating and updating the normalized email/user name. + /// + /// The user. + /// Whether the operation was successful. + protected virtual async Task UpdateUserAsync(TUser user) { - var result = await ValidateUserInternal(user); + var result = await ValidateUserAsync(user); if (!result.Succeeded) { return result;