public async Task <IActionResult> AcceptInvite(string code) { if (!string.IsNullOrWhiteSpace(code)) { var user = await GetCurrentLocalUserAsync(); var accessCode = await _invitationService.GetAccessCodeAsync(code, user?.Id, null); if (accessCode != null) { var statusMessage = "Accepted invitation"; var statusType = "success"; switch (accessCode.Type) { case InvitationType.AddMeToGroup: { if (!await _userManager.IsInRoleAsync(user, accessCode.GroupName)) { _logger.LogInformation($"Adding {user.Id} ({user.Email}) to {accessCode.GroupName} role"); statusMessage = "You are now a part of " + accessCode.GroupName; } else { _logger.LogInformation($"{user.Id} ({user.Email}) was already a part of {accessCode.GroupName} role"); statusMessage = "You were already a part of " + accessCode.GroupName; } } break; case InvitationType.FollowMe: { // TODO: fix this for cross peer invitations await _reactions.React(user.PublicId, new PublicId(accessCode.CreatedByUserId, 0) { Type = "Actor" }, ReactionType.Follow); statusMessage = "You are now following " + accessCode.CreatedByUserId; } break; case InvitationType.Register: return(RedirectToAction(nameof(Register), new { code })); } // TODO: send notification that the invite was consumed await _invitationService.ConsumeAccessCodeAsync(user, accessCode); return(RedirectToAction(nameof(Index), new { statusMessage, statusType })); } } return(NotFound()); }