Beispiel #1
0
        private async Task ValidatePasswordAsync(
            IUserAreaDefinition userArea,
            User user,
            AddUserCommand command,
            IExecutionContext executionContext
            )
        {
            var isPasswordEmpty = string.IsNullOrWhiteSpace(command.Password);

            if (userArea.AllowPasswordSignIn && isPasswordEmpty)
            {
                throw ValidationErrorException.CreateWithProperties("Password field is required", nameof(command.Password));
            }
            else if (!userArea.AllowPasswordSignIn && !isPasswordEmpty)
            {
                throw ValidationErrorException.CreateWithProperties("Password field should be empty because the specified user area does not use passwords", nameof(command.Password));
            }
            else if (!userArea.AllowPasswordSignIn)
            {
                return;
            }

            var context = NewPasswordValidationContext.MapFromUser(user);

            context.Password         = command.Password;
            context.PropertyName     = nameof(command.Password);
            context.ExecutionContext = executionContext;

            await _newPasswordValidationService.ValidateAsync(context);
        }
Beispiel #2
0
        public static NewPasswordValidationContext MapFromUser(User user)
        {
            var context = new NewPasswordValidationContext()
            {
                Email        = user.Email,
                UserAreaCode = user.UserAreaCode ?? user.UserArea?.UserAreaCode,
                UserId       = user.UserId,
                Username     = user.Username
            };

            return(context);
        }
Beispiel #3
0
        private async Task ValidatePasswordAsync(User user, CompleteUserAccountRecoveryViaEmailCommand command, IExecutionContext executionContext)
        {
            var userArea = _userAreaDefinitionRepository.GetRequiredByCode(command.UserAreaCode);

            _passwordUpdateCommandHelper.ValidateUserArea(userArea);

            var context = NewPasswordValidationContext.MapFromUser(user);

            context.Password         = command.NewPassword;
            context.PropertyName     = nameof(command.NewPassword);
            context.ExecutionContext = executionContext;

            await _newPasswordValidationService.ValidateAsync(context);
        }
Beispiel #4
0
        private async Task ValidatePasswordAsync(UpdateCurrentUserPasswordCommand command, User user, IExecutionContext executionContext)
        {
            var userArea = _userAreaRepository.GetRequiredByCode(user.UserAreaCode);

            _passwordUpdateCommandHelper.ValidateUserArea(userArea);

            var context = NewPasswordValidationContext.MapFromUser(user);

            context.CurrentPassword  = command.OldPassword;
            context.Password         = command.NewPassword;
            context.PropertyName     = nameof(command.NewPassword);
            context.ExecutionContext = executionContext;

            await _newPasswordValidationService.ValidateAsync(context);
        }
Beispiel #5
0
        private async Task ValidatePasswordAsync(
            UpdateUserPasswordByUserIdCommand command,
            User user,
            IExecutionContext executionContext
            )
        {
            await _userCommandPermissionsHelper.ThrowIfCannotManageSuperAdminAsync(user, executionContext);

            var userArea = _userAreaRepository.GetRequiredByCode(user.UserAreaCode);

            _passwordUpdateCommandHelper.ValidateUserArea(userArea);
            _passwordUpdateCommandHelper.ValidatePermissions(userArea, executionContext);

            var context = NewPasswordValidationContext.MapFromUser(user);

            context.Password         = command.NewPassword;
            context.PropertyName     = nameof(command.NewPassword);
            context.ExecutionContext = executionContext;

            await _newPasswordValidationService.ValidateAsync(context);
        }