public async Task DynamoRoleUsersStore_GetUserIdsInRole_GetsUsers()
        {
            var user1    = new DynamoIdentityUser(TestUtils.RandomString(10));
            var user2    = new DynamoIdentityUser(TestUtils.RandomString(10));
            var roleName = TestUtils.RandomString(10);

            using (var dbProvider = DynamoDbServerTestUtils.CreateDatabase())
            {
                var roleStore = new DynamoRoleUsersStore <DynamoIdentityRole, DynamoIdentityUser>();
                await roleStore.EnsureInitializedAsync(dbProvider.Client, dbProvider.Context);

                await roleStore.AddToRoleAsync(user1, roleName, CancellationToken.None);

                Assert.True(await roleStore.IsInRoleAsync(user1, roleName, CancellationToken.None));

                await roleStore.AddToRoleAsync(user2, roleName, CancellationToken.None);

                Assert.True(await roleStore.IsInRoleAsync(user2, roleName, CancellationToken.None));

                // ACT
                var result = await roleStore.GetUserIdsInRoleAsync(roleName, CancellationToken.None);

                // ASSERT
                Assert.Contains(user1.Id, result);
                Assert.Contains(user2.Id, result);
                Assert.Equal(2, result.Count);
            }
        }
Example #2
0
        public async Task <IActionResult> RegistrationRequest(RegistrationRequest request)
        {
            try
            {
                var cancellationToken = GetCancellationToken();

                var userExists = await _userManager.FindByEmailAsync(request.Email);

                if (userExists != null)
                {
                    var urlLink = Url.Action("ForgotPassword", "Account");
                    ViewData["message"] = $"A user has already been registered with this email address. If you are this person, head <a href=\"{urlLink}\"> here </a> to reset your password.";
                    ViewBag.Success     = false;
                }
                else
                {
                    var adminUsers       = (await _roleManager.GetUserIdsInRoleAsync(RoleNameConstants.AdminRole, cancellationToken)).ToList();
                    var superAdmminUsers = (await _roleManager.GetUserIdsInRoleAsync(RoleNameConstants.SuperAdminRole, cancellationToken)).ToList();

                    var emails = new List <string>();
                    foreach (var userId in (adminUsers.Union(superAdmminUsers)))
                    {
                        var user = await _userManager.FindByIdAsync(userId);

                        emails.Add(user.Email.Value);
                    }

                    await _sesService.SendBulkEmail(emails.AsEnumerable(), GetRequestEmail(request), "New User Request", cancellationToken);

                    ViewData["message"] = "Thanks, your request has been sent to the web site admins one of whom will respond as soon as they're able to.";
                    ViewBag.Success     = true;
                }
            }
            catch (Exception ex)
            {
                ViewBag.Success = false;
                _logger.LogError(ex, $"There was an error handling the registration request for {request.Email}");
                ViewData["message"] = "Unfortunately there was an error handling your request. The web admins have been notified";
            }

            return(View(request));
        }