public void Consume(InvitationAccepted e) { Console.WriteLine("Invitation Accepted"); Console.WriteLine("Player Id: " + e.PlayerId); Console.WriteLine("Player Name: " + e.PlayerName); Console.WriteLine("Invitation Token: " + e.InvitationToken); }
/// <summary> /// Accepts and deletes the invitation. Sends an event which is picked up by the application domain (which transforms /// the pending invite to a membership) /// </summary> /// <remarks> /// <para> /// Do note that an invitation can be accepted by using another email address than the one that the invitation was /// sent to. So take care /// when handling the <see cref="InvitationAccepted" /> event. Update the email that as used when sending the /// invitation. /// </para> /// </remarks> public async Task <ClaimsIdentity> AcceptInvitation(ClaimsPrincipal user, AcceptInvitation request) { var invitation = await _invitationRepository.GetByInvitationKeyAsync(request.InvitationKey); if (invitation == null) { _logger.Error("Failed to find invitation key" + request.InvitationKey); return(null); } await _invitationRepository.DeleteAsync(request.InvitationKey); Account account; if (request.AccountId == 0) { account = new Account(request.UserName, request.Password); account.SetVerifiedEmail(request.AcceptedEmail); account.Activate(); account.Login(request.Password); await _repository.CreateAsync(account); } else { account = await _repository.GetByIdAsync(request.AccountId); account.SetVerifiedEmail(request.AcceptedEmail); } var inviter = await _repository.FindByUserNameAsync(invitation.InvitedBy); ClaimsIdentity identity = null; identity = await CreateIdentity(account.Id, account.UserName, account.IsSysAdmin); // Account have not been created before the invitation was accepted. if (request.AccountId == 0) { await _messageBus.SendAsync(user, new AccountRegistered(account.Id, account.UserName)); await _messageBus.SendAsync(user, new AccountActivated(account.Id, account.UserName) { EmailAddress = account.Email }); } var e = new InvitationAccepted(account.Id, invitation.InvitedBy, account.UserName) { InvitedEmailAddress = invitation.EmailToInvitedUser, AcceptedEmailAddress = request.AcceptedEmail, ApplicationIds = invitation.Invitations.Select(x => x.ApplicationId).ToArray() }; await _messageBus.SendAsync(user, e); return(identity); }
public void Apply(InvitationAccepted @event) { Invitation invitation = this.Invitations?.Items.FirstOrDefault(item => item.Id.Equals(@event.InvitationId)); if (invitation == null) { return; } invitation.Accepted = true; invitation.User = @event.User; }
public async Task <AcceptInvitationReply> ExecuteAsync(AcceptInvitation request) { var account = new Account(request.UserName, request.Password); account.SetVerifiedEmail(request.Email); var invitation = await _repository.FindByEmailAsync(request.Email); if (invitation == null) { return(null); } await _repository.DeleteAsync(request.InvitationKey); var inviter = await _accountRepository.FindByUserNameAsync(invitation.InvitedBy); account.Activate(); account.Login(request.Password); var roles = invitation.Invitations.Select(x => "Member_" + x.ApplicationId).ToArray(); await _accountRepository.CreateAsync(account); Thread.CurrentPrincipal = new OneTruePrincipal(account.Id, account.UserName, roles); await _eventBus.PublishAsync(new AccountActivated(account.Id, account.UserName) { EmailAddress = account.Email }); var e = new InvitationAccepted(account.Id, invitation.InvitedBy, account.UserName) { EmailAddress = account.Email, ApplicationIds = invitation.Invitations.Select(x => x.ApplicationId).ToArray() }; await _eventBus.PublishAsync(e); return(new AcceptInvitationReply(account.Id, account.UserName)); }
public async Task <AcceptInvitationReply> ExecuteAsync(AcceptInvitation request) { var invitation = await _repository.GetByInvitationKeyAsync(request.InvitationKey); if (invitation == null) { _logger.Error("Failed to find invitation key" + request.InvitationKey); return(null); } await _repository.DeleteAsync(request.InvitationKey); Account account; if (request.AccountId == 0) { account = new Account(request.UserName, request.Password); account.SetVerifiedEmail(request.AcceptedEmail); account.Activate(); account.Login(request.Password); await _accountRepository.CreateAsync(account); } else { account = await _accountRepository.GetByIdAsync(request.AccountId); account.SetVerifiedEmail(request.AcceptedEmail); } var inviter = await _accountRepository.FindByUserNameAsync(invitation.InvitedBy); if (ClaimsPrincipal.Current.IsAccount(account.Id)) { var claims = invitation.Invitations .Select( x => new Claim(OneTrueClaims.Application, x.ApplicationId.ToString(), ClaimValueTypes.Integer32)) .ToList(); var context = new PrincipalFactoryContext(account.Id, account.UserName, new string[0]) { Claims = claims.ToArray(), AuthenticationType = "Invite" }; var principal = await PrincipalFactory.CreateAsync(context); principal.AddUpdateCredentialClaim(); Thread.CurrentPrincipal = principal; } // Account have not been created before the invitation was accepted. if (request.AccountId == 0) { await _eventBus.PublishAsync(new AccountRegistered(account.Id, account.UserName)); await _eventBus.PublishAsync(new AccountActivated(account.Id, account.UserName) { EmailAddress = account.Email }); } var e = new InvitationAccepted(account.Id, invitation.InvitedBy, account.UserName) { InvitedEmailAddress = invitation.EmailToInvitedUser, AcceptedEmailAddress = request.AcceptedEmail, ApplicationIds = invitation.Invitations.Select(x => x.ApplicationId).ToArray() }; await _eventBus.PublishAsync(e); return(new AcceptInvitationReply(account.Id, account.UserName)); }