public async Task Handle(SignOn command) { if (command.Principal.Identity.IsAuthenticated) { command.SignedOn = await _queries.Execute(new UserBy(command.Principal)); return; } // try to find user by external login credentials var externalLogin = await _queries.Execute(new PrincipalRemoteMembershipTicket(command.Principal)); if (externalLogin == null) { return; } var user = await _queries.Execute(new UserBy(externalLogin.Login)); if (user != null) { await _authenticator.SignOn(user, command.IsPersistent); command.SignedOn = user; return; } // if they don't exist, check with email claim var emailClaim = await _queries.Execute(new ExternalCookieClaim(ClaimTypes.Email)); if (emailClaim != null) { var emailAddress = await _queries.Execute(new EmailAddressBy(emailClaim) { IsVerified = true, EagerLoad = new Expression <Func <EmailAddress, object> >[] { x => x.User, }, }); if (emailAddress != null) { // need to add the external login credentials user = emailAddress.User; _entities.Update(user); // make sure it is attached to the context await _commands.Execute(new CreateRemoteMembership { Principal = command.Principal, User = user, }); await _authenticator.SignOn(user, command.IsPersistent); command.SignedOn = user; } } }
public Task UpdateAsync(User user) { ThrowIfDisposed(); if (user == null) { throw new ArgumentNullException("user"); } _entities.Update(user); //await SaveChanges().ConfigureAwait(false); return(Task.FromResult(0)); }