Base solution for your next web application
Open Closed

Login Identity.DuplicateEmail #181


User avatar
0
hans abelshausen created

Hi, we are using module Zero for Login. We only need the Name as required. So I overwrited the mail with: [Required(AllowEmptyStrings = true)] public override string EmailAddress { get; set; }

But now, if two people leave the mail field empty, the user is not saved to db. Is there a way to stop watching the DuplicateEmail functionality?


1 Answer(s)
  • User Avatar
    0
    hikalkan created
    Support Team

    You can try to override CheckDuplicateUsernameOrEmailAddressAsync in your UserManager class. It's default implementation is like that (defined in <a class="postlink" href="https://github.com/aspnetboilerplate/module-zero/blob/master/src/Abp.Zero/Authorization/Users/AbpUserManager.cs#L460">https://github.com/aspnetboilerplate/mo ... er.cs#L460</a>):

    public virtual async Task<IdentityResult> CheckDuplicateUsernameOrEmailAddressAsync(long? expectedUserId, string userName, string emailAddress)
            {
                var user = (await FindByNameAsync(userName));
                if (user != null && user.Id != expectedUserId)
                {
                    return AbpIdentityResult.Failed(string.Format(L("Identity.DuplicateName"), userName));
                }
    
                user = (await FindByEmailAsync(emailAddress));
                if (user != null && user.Id != expectedUserId)
                {
                    return AbpIdentityResult.Failed(string.Format(L("Identity.DuplicateEmail"), emailAddress));
                }
    
                return IdentityResult.Success;
            }
    

    You can override and change behaviour (so, don't call base method in override).