public virtual async Task <TUser> FindByEmailAsync(string email) { ThrowIfDisposed(); IUserEmailStore <TUser> emailStore = GetEmailStore(); if (email == null) { throw new ArgumentNullException(nameof(email)); } TUser user = await emailStore.FindByEmailAsync(email, CancellationToken); if (user == null && Options.Stores.ProtectPersonalData) { ILookupProtectorKeyRing keyRing = _services.GetService <ILookupProtectorKeyRing>(); ILookupProtector protector = _services.GetService <ILookupProtector>(); if (keyRing != null && protector != null) { foreach (var key in keyRing.GetAllKeyIds()) { string oldKey = protector.Protect(key, email); user = await emailStore.FindByEmailAsync(oldKey, CancellationToken); if (user != null) { return(user); } } } } return(user); }
public async Task <User> FindByPhoneNumberAsync(string phone) { this.ThrowIfDisposed(); if (phone == null) { throw new ArgumentNullException(nameof(phone)); } User byEmailAsync = await(this.Users).FirstOrDefaultAsync((Expression <Func <User, bool> >)(u => u.PhoneNumber == phone), CancellationToken.None); if ((object)byEmailAsync == null && this.Options.Stores.ProtectPersonalData) { ILookupProtectorKeyRing service = this._services.GetService <ILookupProtectorKeyRing>(); ILookupProtector protector = this._services.GetService <ILookupProtector>(); if (service != null && protector != null) { foreach (string allKeyId in service.GetAllKeyIds()) { byEmailAsync = await(this.Users).FirstOrDefaultAsync((Expression <Func <User, bool> >)(u => u.PhoneNumber == protector.Protect(allKeyId, phone)), CancellationToken.None); if ((object)byEmailAsync != null) { return(byEmailAsync); } } } protector = (ILookupProtector)null; } return(byEmailAsync); }