internal async Task <TResult> MarkInviteRedeemedAsync <TResult>(Guid inviteToken, Guid loginId, Func <Guid, TResult> onFound, Func <TResult> onNotFound, Func <Guid, TResult> onAlreadyRedeemed, Func <TResult> onAlreadyInUse, Func <TResult> onAlreadyConnected) { var lookupResults = await await repository.FindByIdAsync(inviteToken, async (Documents.InviteTokenDocument tokenDocument) => { var rollback = new RollbackAsync <TResult>(); rollback.AddTaskUpdate(tokenDocument.InviteId, (Documents.InviteDocument inviteDoc) => { inviteDoc.LoginId = loginId; }, (inviteDoc) => { inviteDoc.LoginId = default(Guid?); }, onNotFound, this.repository); var loginLookup = new Documents.LoginActorLookupDocument() { ActorId = tokenDocument.ActorId, }; rollback.AddTaskCreate(loginId, loginLookup, onAlreadyInUse, this.repository); return(await rollback.ExecuteAsync(() => onFound(tokenDocument.ActorId))); }, () => onNotFound().ToTask()); return(lookupResults); }
public async Task <TResult> CreatePasswordCredentialAsync <TResult>(Guid passwordCredentialId, Guid actorId, Guid loginId, DateTime?emailLastSent, Func <TResult> onSuccess, Func <TResult> onAlreadyExists, Func <TResult> onRelationshipAlreadyExists, Func <TResult> onLoginAlreadyUsed) { var rollback = new RollbackAsync <TResult>(); var lookupDoc = new Documents.LoginActorLookupDocument { ActorId = actorId, }; rollback.AddTaskCreate(loginId, lookupDoc, onLoginAlreadyUsed, this.repository); rollback.AddTaskCreateOrUpdate(actorId, (Documents.ActorMappingsDocument actorDoc) => actorDoc.AddPasswordCredential(passwordCredentialId), actorDoc => actorDoc.RemovePasswordCredential(passwordCredentialId), onRelationshipAlreadyExists, this.repository); var passwordCredentialDoc = new Documents.PasswordCredentialDocument { LoginId = loginId, EmailLastSent = emailLastSent, }; rollback.AddTaskCreate(passwordCredentialId, passwordCredentialDoc, onAlreadyExists, this.repository); return(await rollback.ExecuteAsync(onSuccess)); }
internal async Task <TResult> CreateCredentialMappingAsync <TResult>(Guid credentialMappingId, Guid loginId, Guid actorId, string email, Guid token, DateTime lastSent, bool isToken, bool overrideLoginId, Func <TResult> onSuccess, Func <TResult> onAlreadyExists, Func <TResult> onTokenAlreadyInUse, Func <TResult> onLoginAlreadyInUse) { var rollback = new RollbackAsync <TResult>(); var inviteDocument = new Documents.InviteDocument() { ActorId = actorId, Email = email, IsToken = isToken, LastSent = lastSent, Token = token, LoginId = loginId, }; rollback.AddTaskCreate(credentialMappingId, inviteDocument, onAlreadyExists, this.repository); var inviteTokenDocument = new Documents.InviteTokenDocument() { ActorId = actorId, InviteId = credentialMappingId, }; rollback.AddTaskCreate(token, inviteTokenDocument, onTokenAlreadyInUse, this.repository); if (overrideLoginId) { var oldActorId = default(Guid); rollback.AddTaskCreateOrUpdate(loginId, (Documents.LoginActorLookupDocument loginActorDocument) => { oldActorId = loginActorDocument.ActorId; loginActorDocument.ActorId = actorId; return(true); }, (loginActorDocument) => { loginActorDocument.ActorId = oldActorId; return(true); }, () => { throw new Exception("Login override failed"); }, // Should never happend because always return true on mutate this.repository); } else { var loginActorDocument = new Documents.LoginActorLookupDocument() { ActorId = actorId, }; rollback.AddTaskCreate(loginId, loginActorDocument, onLoginAlreadyInUse, this.repository); } rollback.AddTaskCreateOrUpdate(actorId, (Documents.ActorMappingsDocument authDoc) => authDoc.AddInviteId(credentialMappingId), (authDoc) => authDoc.RemoveInviteId(credentialMappingId), onAlreadyExists, // This should fail on the action above as well this.repository); return(await rollback.ExecuteAsync(onSuccess)); }