/// <summary>
        /// Sign in a user that has already been authenticated.
        /// </summary>
        public async Task SignMemberInAsync(SignMemberInCommand command)
        {
            // Because we're not logged in yet we need to elevate permissions here to save a new user,
            // otherwise the ambient anonymous user will be used and a permission exception will be thrown
            var systemExecutionContext = await _executionContextFactory.CreateSystemUserExecutionContextAsync();

            var existingUser = await _userRepository.GetUserMicroSummaryByEmailAsync(command.Email, MemberUserArea.AreaCode, systemExecutionContext);

            int userId;

            if (existingUser == null)
            {
                // If we haven't logged in with this user before, we'll create a Cofoundry user to match your
                // SSO login.

                var role = await GetMemberRole(systemExecutionContext);

                var addUserCommand = MapAddUserCommand(command, role);

                await _userRepository.AddUserAsync(addUserCommand, systemExecutionContext);

                // Note that the new user id is set in the OutputUserId which is a
                // convention used by the CQS framework (see https://github.com/cofoundry-cms/cofoundry/wiki/CQS)
                userId = addUserCommand.OutputUserId;
            }
            else
            {
                // If the user already exists, we sign in using that Id
                userId = existingUser.UserId;
            }

            await _loginService.LogAuthenticatedUserInAsync(MemberUserArea.AreaCode, userId, true);
        }
예제 #2
0
        public async Task ExecuteAsync(UpdateUnauthenticatedUserPasswordCommand command, IExecutionContext executionContext)
        {
            if (IsLoggedInAlready(command, executionContext))
            {
                throw new Exception("UpdateUnauthenticatedUserPasswordCommand cannot be used when the user is already logged in.");
            }

            await ValidateMaxLoginAttemptsNotExceeded(command, executionContext);

            var userArea = _userAreaRepository.GetByCode(command.UserAreaCode);

            var userLoginInfo = await GetUserLoginInfoAsync(command, executionContext);

            if (userLoginInfo == null)
            {
                var failedLoginLogCommand = new LogFailedLoginAttemptCommand(command.UserAreaCode, command.Username);
                await _commandExecutor.ExecuteAsync(failedLoginLogCommand);

                throw new InvalidCredentialsAuthenticationException(nameof(command.OldPassword));
            }

            var updatePasswordCommand = new UpdateUserPasswordByUserIdCommand()
            {
                UserId      = userLoginInfo.UserId,
                NewPassword = command.NewPassword
            };

            // User is not logged in, so will need to elevate permissions here to change the password.
            var systemExecutionContext = await _executionContextFactory.CreateSystemUserExecutionContextAsync(executionContext);

            await _commandExecutor.ExecuteAsync(updatePasswordCommand, systemExecutionContext);

            // We pass out the userid since we do the auth inside the command and it might be useful to the callee
            command.OutputUserId = userLoginInfo.UserId;
        }
예제 #3
0
        public async Task ExecuteAsync(RegisterPageTemplatesAndPageBlockTypesCommand command)
        {
            var cx = await _executionContextFactory.CreateSystemUserExecutionContextAsync();

            await _commandExecutor.ExecuteAsync(new RegisterPageTemplatesCommand(), cx);

            await _commandExecutor.ExecuteAsync(new RegisterPageBlockTypesCommand(), cx);
        }
        public ContentRepositoryWithElevatedPermissions(
            IServiceProvider serviceProvider,
            IQueryExecutor queryExecutor,
            ICommandExecutor commandExecutor,
            IExecutionContextFactory executionContextFactory
            )
            : base(serviceProvider, queryExecutor, commandExecutor)
        {
            _queryExecutor   = queryExecutor;
            _commandExecutor = commandExecutor;

            _elevatedExecutionContextAsync = new Lazy <Task <IExecutionContext> >(() =>
            {
                return(executionContextFactory.CreateSystemUserExecutionContextAsync());
            });
        }
        public async Task ExecuteAsync()
        {
            if (_assetFileCleanupSettings.Disabled)
            {
                return;
            }

            var executionContext = await _executionContextFactory.CreateSystemUserExecutionContextAsync();

            var deleteFilesCommand = new CleanUpAssetFilesCommand()
            {
                BatchSize = _assetFileCleanupSettings.BatchSize
            };
            await _commandExecutor.ExecuteAsync(deleteFilesCommand, executionContext);

            var cleanUpCommand = new CleanupAssetFileCleanupQueueCommand()
            {
                CompletedItemRetentionTime = TimeSpan.FromMinutes(_assetFileCleanupSettings.CompletedItemRetentionTimeInMinutes),
                DeadLetterRetentionTime    = TimeSpan.FromMinutes(_assetFileCleanupSettings.DeadLetterRetentionTimeInMinutes)
            };

            await _commandExecutor.ExecuteAsync(cleanUpCommand, executionContext);
        }
예제 #6
0
        public async Task ExecuteAsync(RegisterPermissionsAndRolesUpdateCommand command)
        {
            var cx = await _executionContextFactory.CreateSystemUserExecutionContextAsync();

            await _commandExecutor.ExecuteAsync(new RegisterPermissionsAndRolesCommand(), cx);
        }
        public async Task ExecuteAsync(ICommand command, IExecutionContext executionContext)
        {
            var newExecutionContext = await _executionContextFactory.CreateSystemUserExecutionContextAsync(executionContext);

            await _innerDomainRepositoryExecutor.ExecuteAsync(command, newExecutionContext);
        }
        private async Task SaveNewUser(IExecutionContext executionContext, AddUserCommand addUserCommand)
        {
            var systemExecutionContext = await _executionContextFactory.CreateSystemUserExecutionContextAsync(executionContext);

            await _commandExecutor.ExecuteAsync(addUserCommand, systemExecutionContext);
        }
예제 #9
0
        public async Task ExecuteAsync(RegisterNewDefinedRolesCommand command)
        {
            var cx = await _executionContextFactory.CreateSystemUserExecutionContextAsync();

            await _commandExecutor.ExecuteAsync(new RegisterDefinedRolesCommand(), cx);
        }