Simplifies the UnlockUser method so we don't have to have it in the BackOfficeUserManager
This commit is contained in:
@@ -288,39 +288,7 @@ namespace Umbraco.Core.Security
|
||||
RaiseResetAccessFailedCountEvent(userId);
|
||||
return await UpdateAsync(user);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Clears a lock so that the membership user can be validated.
|
||||
/// </summary>
|
||||
/// <param name="username">The membership user to clear the lock status for.</param>
|
||||
/// <returns>
|
||||
/// true if the membership user was successfully unlocked; otherwise, false.
|
||||
/// </returns>
|
||||
/// <remarks>
|
||||
/// TODO: This is only currently used for membership provider compatibility so that an event is raised when the
|
||||
/// membership provider's UnlockUser method is called, this functionality changes in 7.7 since we use ASP.NET Identity APIs everwhere
|
||||
/// and the BackOfficeUserManager shouldn't be using singletons or know about the UserService since it should only need to know about
|
||||
/// the UserStore - we will fix this up for 7.7
|
||||
/// </remarks>
|
||||
internal bool UnlockUser(string username)
|
||||
{
|
||||
var user = ApplicationContext.Current.Services.UserService.GetByUsername(username);
|
||||
if (user == null)
|
||||
throw new ProviderException(string.Format("No user with the username '{0}' found", username));
|
||||
|
||||
// Non need to update
|
||||
if (user.IsLockedOut == false) return true;
|
||||
|
||||
user.IsLockedOut = false;
|
||||
user.FailedPasswordAttempts = 0;
|
||||
|
||||
ApplicationContext.Current.Services.UserService.Save(user);
|
||||
|
||||
RaiseAccountUnlockedEvent(user.Id);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
internal void RaiseAccountLockedEvent(int userId)
|
||||
{
|
||||
OnAccountLocked(new IdentityAuditEventArgs(AuditEvent.AccountLocked, GetCurrentRequestIpAddress(), userId));
|
||||
|
||||
@@ -447,16 +447,9 @@ namespace Umbraco.Web.Security.Providers
|
||||
return generatedPassword;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Clears a lock so that the membership user can be validated.
|
||||
/// </summary>
|
||||
/// <param name="username">The membership user to clear the lock status for.</param>
|
||||
/// <returns>
|
||||
/// true if the membership user was successfully unlocked; otherwise, false.
|
||||
/// </returns>
|
||||
public override bool UnlockUser(string username)
|
||||
internal virtual bool PerformUnlockUser(string username, out TEntity member)
|
||||
{
|
||||
var member = MemberService.GetByUsername(username);
|
||||
member = MemberService.GetByUsername(username);
|
||||
if (member == null)
|
||||
{
|
||||
throw new ProviderException(string.Format("No member with the username '{0}' found", username));
|
||||
@@ -469,10 +462,24 @@ namespace Umbraco.Web.Security.Providers
|
||||
member.FailedPasswordAttempts = 0;
|
||||
|
||||
MemberService.Save(member);
|
||||
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Clears a lock so that the membership user can be validated.
|
||||
/// </summary>
|
||||
/// <param name="username">The membership user to clear the lock status for.</param>
|
||||
/// <returns>
|
||||
/// true if the membership user was successfully unlocked; otherwise, false.
|
||||
/// </returns>
|
||||
public override bool UnlockUser(string username)
|
||||
{
|
||||
TEntity member;
|
||||
var result = PerformUnlockUser(username, out member);
|
||||
return result;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Updates e-mail approved status, lock status and comment on a user.
|
||||
/// </summary>
|
||||
|
||||
@@ -82,21 +82,25 @@ namespace Umbraco.Web.Security.Providers
|
||||
return _defaultMemberTypeAlias;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Overridden in order to call the BackOfficeUserManager.UnlockUser method in order to raise the user audit events
|
||||
/// </summary>
|
||||
/// <param name="username"></param>
|
||||
/// <param name="member"></param>
|
||||
/// <returns></returns>
|
||||
public override bool UnlockUser(string username)
|
||||
internal override bool PerformUnlockUser(string username, out IUser member)
|
||||
{
|
||||
var userManager = GetBackofficeUserManager();
|
||||
|
||||
//if this is null it means it's not in a web context so we'll revert to calling the base class
|
||||
if (userManager == null)
|
||||
return base.UnlockUser(username);
|
||||
|
||||
return userManager.UnlockUser(username);
|
||||
var result = base.PerformUnlockUser(username, out member);
|
||||
if (result)
|
||||
{
|
||||
var userManager = GetBackofficeUserManager();
|
||||
if (userManager != null)
|
||||
{
|
||||
userManager.RaiseAccountUnlockedEvent(member.Id);
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
Reference in New Issue
Block a user