public Task ExecuteAsync(SignMemberOutCommand command, IExecutionContext executionContext)
 {
     return(_contentRepository
            .Users()
            .Authentication()
            .SignOutAsync());
 }
예제 #2
0
        private static async Task InitRole(
            TestUserAreaInfo testUserAreaInfo,
            CofoundryDbContext dbContext,
            IAdvancedContentRepository contentRepository,
            TestRoleInfo role
            )
        {
            role.RoleId = await dbContext
                          .Roles
                          .FilterByRoleCode(role.RoleCode)
                          .Select(c => c.RoleId)
                          .SingleAsync();

            var uniqueIdentifier = testUserAreaInfo.UserAreaCode + role.RoleId;

            role.User = new TestUserInfo()
            {
                Username = uniqueIdentifier.ToLower() + "@example.com",
                Password = uniqueIdentifier + "w1P1r4Rz"
            };

            role.User.UserId = await contentRepository
                               .Users()
                               .AddAsync(new AddUserCommand()
            {
                Email        = role.User.Username,
                FirstName    = "Role",
                LastName     = "User",
                Password     = role.User.Password,
                RoleId       = role.RoleId,
                UserAreaCode = testUserAreaInfo.UserAreaCode
            });
        }
예제 #3
0
        public async Task <ActionResult> Login(string returnUrl, SignInViewModel viewModel)
        {
            var authResult = await _contentRepository
                             .WithModelState(this)
                             .Users()
                             .Authentication()
                             .AuthenticateCredentials(new AuthenticateUserCredentialsQuery()
            {
                Username           = viewModel.Username,
                Password           = viewModel.Password,
                UserAreaCode       = CofoundryAdminUserArea.Code,
                PropertyToValidate = nameof(viewModel.Password)
            })
                             .ExecuteAsync();

            if (!ModelState.IsValid)
            {
                var viewPath = ViewPathFormatter.View(CONTROLLER_NAME, nameof(Login));
                return(View(viewPath, viewModel));
            }

            // Support redirect urls from login
            var redirectUrl = RedirectUrlHelper.GetAndValidateReturnUrl(this);

            if (authResult.User.RequirePasswordChange)
            {
                return(Redirect(_adminRouteLibrary.Auth.ChangePassword(returnUrl)));
            }

            // If no action required, log the user in
            await _contentRepository
            .Users()
            .Authentication()
            .SignInAuthenticatedUserAsync(new SignInAuthenticatedUserCommand()
            {
                UserId       = authResult.User.UserId,
                RememberUser = true
            });

            if (redirectUrl != null)
            {
                return(Redirect(redirectUrl));
            }

            return(await GetLoggedInDefaultRedirectActionAsync());
        }
예제 #4
0
 public Task ExecuteAsync(SignMemberInCommand command, IExecutionContext executionContext)
 {
     return(_contentRepository
            .Users()
            .Authentication()
            .SignInWithCredentialsAsync(new SignInUserWithCredentialsCommand()
     {
         Username = command.Email,
         Password = command.Password,
         UserAreaCode = MemberUserArea.Code,
         RememberUser = true
     }));
 }
예제 #5
0
    public async Task ExecuteAsync(RegisterMemberAndLogInCommand command, IExecutionContext executionContext)
    {
        var addUserCommand = MapAddUserCommand(command);

        // Because the user is not signed in, we'll need to elevate
        // permissions to be able add a new user account.
        var userId = await _contentRepository
                     .WithElevatedPermissions()
                     .Users()
                     .AddAsync(addUserCommand);

        await SendWelcomeNotification(command);

        await _contentRepository
        .Users()
        .Authentication()
        .SignInAuthenticatedUserAsync(new SignInAuthenticatedUserCommand()
        {
            UserId       = userId,
            RememberUser = true
        });
    }
예제 #6
0
        public async Task<IActionResult> Test()
        {
            var user = await _contentRepository
                .WithElevatedPermissions()
                .Users()
                .GetById(2)
                .AsMicroSummary()
                .ExecuteAsync();

            var image = await _contentRepository
                .ImageAssets()
                .GetById(2)
                .AsRenderDetails()
                .ExecuteAsync();

            var page = await _contentRepository
                .Pages()
                .Search()
                .AsRenderSummaries(new SearchPageRenderSummariesQuery()
                {
                    PageSize = 20,
                    PageDirectoryId = 2
                })
                .ExecuteAsync();

            var page2 = await _contentRepository
                .Pages()
                .GetById(1)
                .AsRenderSummary()
                .ExecuteAsync();

            // Perhaps NotFound should look like this:
            await _contentRepository
                .Pages()
                .NotFound()
                .GetByPath(new GetNotFoundPageRouteByPathQuery())
                .ExecuteAsync();

            var regions = await _contentRepository
                .Pages()
                .Versions()
                .Regions()
                .Blocks()
                .GetById(2)
                .AsRenderDetails(PublishStatusQuery.Latest)
                .ExecuteAsync();

            await _contentRepository
                .Pages()
                .GetByPath()
                .AsRoutingInfo(new GetPageRoutingInfoByPathQuery())
                .ExecuteAsync();
            //.PublishAsync(new PublishPageCommand() { PageId = 2 });

            var isUnique = await _contentRepository
                .Users()
                .IsUsernameUnique(new IsUsernameUniqueQuery()
                {
                    UserAreaCode = CofoundryAdminUserArea.AreaCode,
                    Username = "******"
                })
                .ExecuteAsync();

            int userId;

            using (var scope = _contentRepository
                .Transactions()
                .CreateScope()
            {
                var adminRole = await _contentRepository
                    .Roles()
                    .GetByCode(SuperAdminRole.SuperAdminRoleCode)
                    .AsDetails()
                    .ExecuteAsync();

                userId = await _contentRepository
                    .WithElevatedPermissions()
                    .Users()
                    .AddAsync(new AddUserCommand()
                    {
                        Email = Guid.NewGuid().ToString() + "@cofoundry.org",
                        Password = "******",
                        UserAreaCode = CofoundryAdminUserArea.AreaCode,
                        RoleId = adminRole.RoleId
                    });

                //await _contentRepository
                //    .WithElevatedPermissions()
                //    .ImageAssets()
                //    .DeleteAsync(2);

                await _contentRepository
                    .CustomEntities()
                    .Definitions()
                    .GetByCode(BlogPostCustomEntityDefinition.DefinitionCode)
                    .AsSummary()
                    .ExecuteAsync();

                await _contentRepository
                    .CustomEntities()
                    .DataModelSchemas()
                    .GetByCustomEntityDefinitionCode(BlogPostCustomEntityDefinition.DefinitionCode)
                    .AsDetails()
                    .ExecuteAsync();

                await _contentRepository
                    .CustomEntities()
                    .GetById(1)
                    .AsRenderSummary()
                    .ExecuteAsync();

                var permissions = await _contentRepository
                    .Roles()
                    .Permissions()
                    .GetAll()
                    .AsIPermission()
                    .ExecuteAsync();

                var directoryTree = await _contentRepository
                    .PageDirectories()
                    .GetAll()
                    .AsTree()
                    .ExecuteAsync();

                var rewriteRules = await _contentRepository
                    .RewriteRules()
                    .GetAll()
                    .AsSummaries()
                    .ExecuteAsync();

                var blockTypes = await _contentRepository
                    .PageBlockTypes()
                    .GetAll()
                    .AsSummaries()
                    .ExecuteAsync();

                await scope.CompleteAsync();
            }

            await _contentRepository
                .WithElevatedPermissions()
                .Users()
                .DeleteUserAsync(userId);

            return View();
        }