using System.Threading.Tasks;
using Microsoft.AspNet.Identity;
using Umbraco.Web.Models.Identity;
namespace Umbraco.Core.Security
{
///
/// Custom validator to not validate a user's username or email if they haven't changed
///
///
internal class BackOfficeUserValidator : UserValidator
where T : BackOfficeIdentityUser
{
public BackOfficeUserValidator(UserManager manager) : base(manager)
{
}
public override async Task ValidateAsync(T item)
{
//Don't validate if the user's email or username hasn't changed otherwise it's just wasting SQL queries.
if (item.IsPropertyDirty("Email") || item.IsPropertyDirty("UserName"))
{
return await base.ValidateAsync(item);
}
return IdentityResult.Success;
}
}
}