Exemplo n.º 1
0
        // Executes the username strategy
        public ResponseDto <bool> ExecuteStrategy()
        {
            var validationWrapper = new ValidationWrapper <UserAccountDto>(_userAccountDto, "Username", _userAccountDtoValidator);
            var result            = validationWrapper.ExecuteValidator();

            if (!result.Data)
            {
                result.Error = ValidationErrorMessages.INVALID_USERNAME;
                return(result);
            }

            // Validate user does exist
            result = _userValidator.CheckIfUserExists(_userAccountDto.Username);
            if (!result.Data)
            {
                if (result.Error == null)
                {
                    result.Error = ValidationErrorMessages.USER_DOES_NOT_EXIST;
                }

                result.Data = false;
                return(result);
            }

            return(new ResponseDto <bool>()
            {
                Data = true
            });
        }
        /// <summary>
        /// The ExecuteStrategy method.
        /// Contains the logic to validate domain models for creating an individual user.
        /// <para>
        /// @author: Jennifer Nguyen
        /// @updated: 03/13/2018
        /// </para>
        /// </summary>
        /// <returns>A boolean</returns>
        public ResponseDto <bool> ExecuteStrategy()
        {
            ResponseDto <bool> result;

            var validationWrappers = new List <IValidationWrapper>()
            {
                new ValidationWrapper <UserAccount>(_userAccount, "CreateUser", new UserAccountValidator()),
                new ValidationWrapper <PasswordSalt>(_passwordSalt, new PasswordSaltValidator()),
                new ValidationWrapper <UserProfile>(_userProfile, "CreateUser", new UserProfileValidator()),
                new ValidationWrapper <UserClaims>(_userClaims, new ClaimsValidator())
            };

            foreach (var securityQuestion in _securityQuestions)
            {
                validationWrappers.Add(new ValidationWrapper <SecurityQuestion>(securityQuestion, "CreateUser", _securityQuestionValidator));
            }

            foreach (var securityAnswerSalt in _securityAnswerSalts)
            {
                validationWrappers.Add(new ValidationWrapper <SecurityAnswerSalt>(securityAnswerSalt, _securityAnswerSaltValidator));
            }

            foreach (var validationWrapper in validationWrappers)
            {
                result = validationWrapper.ExecuteValidator();
                if (!result.Data)
                {
                    result.Error = GeneralErrorMessages.GENERAL_ERROR;
                    return(result);
                }
            }

            // Validate username and display name are not equal
            result = _userValidator.CheckIfUsernameEqualsDisplayName(_userAccount.Username, _userProfile.DisplayName);
            if (result.Data)
            {
                result.Error = GeneralErrorMessages.GENERAL_ERROR;
                return(result);
            }

            // Validate user does not exist
            result = _userValidator.CheckIfUserExists(_userAccount.Username);
            if (result.Data)
            {
                result.Error = GeneralErrorMessages.GENERAL_ERROR;
                return(result);
            }
            return(new ResponseDto <bool>()
            {
                Data = true
            });
        }
        /// <summary>
        /// The ExecuteStrategy method.
        /// Contains the logic to validate a data transfer object for resetting a user's password.
        /// <para>
        /// @author: Jennifer Nguyen
        /// @updated: 03/20/2018
        /// </para>
        /// </summary>
        /// <returns>ResponseDto</returns>
        public ResponseDto <bool> ExecuteStrategy()
        {
            ResponseDto <bool> result;

            // Get collection of validation wrappers
            var validationWrappers = GetValidationWrappers();

            foreach (var validationWrapper in validationWrappers)
            {
                result = validationWrapper.ExecuteValidator();
                if (!result.Data)
                {
                    return(result);
                }
            }

            // Validate user exists
            result = _userValidator.CheckIfUserExists(_resetPasswordDto.Username);
            if (!result.Data)
            {
                if (result.Error == null)
                {
                    result.Error = ValidationErrorMessages.USER_DOES_NOT_EXIST;
                }

                result.Data = false;
                return(result);
            }

            // Validate password has not been previously breached.
            if (_resetPasswordDto.Password != null)
            {
                result = new PwnedPasswordValidationService().IsPasswordValid(_resetPasswordDto.Password);
                if (!result.Data)
                {
                    if (result.Error == null)
                    {
                        result.Error = ValidationErrorMessages.PASSWORD_BREACHED;
                    }

                    return(result);
                }
            }

            return(new ResponseDto <bool>()
            {
                Data = true
            });
        }
        public ResponseDto <bool> ExecuteStrategy()
        {
            // Executes the username strategy
            var validationWrapper = new ValidationWrapper <UserProfileDto>(_userProfileDto, "Username", _userProfileDtoValidator);
            var result            = validationWrapper.ExecuteValidator();

            if (result.Error != null)
            {
                return(result);
            }

            // Validate if user does exist
            result = _userValidator.CheckIfUserExists(_userProfileDto.Username);
            if (!result.Data)
            {
                result.Error = ValidationErrorMessages.USER_DOES_NOT_EXIST;

                return(result);
            }

            // Validate Image Extension
            var imageExtension = Path.GetExtension(_image.FileName);

            if (!_allowedFileExtensions.Contains(imageExtension))
            {
                return(new ResponseDto <bool>
                {
                    Data = false,
                    Error = ValidationErrorMessages.INVALID_IMAGE_TYPE
                });
            }

            // Validate Image Size - average file sizes 12000
            var imageSize = _image.ContentLength;

            if (imageSize >= MaxImageSize)
            {
                return(new ResponseDto <bool>()
                {
                    Data = false,
                    Error = ValidationErrorMessages.INVALID_IMAGE_SIZE
                });
            }
            // Validations are successful!
            return(new ResponseDto <bool>()
            {
                Data = true
            });
        }
        public ResponseDto <bool> ExecuteStrategy()
        {
            // Will validate the username and new username
            var validationWrappers = new List <IValidationWrapper>()
            {
                new ValidationWrapper <EditUserDto>(_editUserDto, "EditUsername", _editUserDtoValidator),
            };

            // Goes through each validation in the validation wrapper.
            foreach (var validationWrapper in validationWrappers)
            {
                var result = validationWrapper.ExecuteValidator();
                if (!result.Data)
                {
                    return(result);
                }
            }
            // Validator to check if user exists
            var userValidator = new UserValidator();

            if (userValidator.CheckIfUserExists(_editUserDto.Username).Data == false)
            {
                return(new ResponseDto <bool>
                {
                    Data = false,
                    Error = ValidationErrorMessages.USER_DOES_NOT_EXIST
                });
            }

            //Check if new display name is null
            if (_editUserDto.NewDisplayName != null)
            {
                //Checks if username is equal to displayname
                if (userValidator.CheckIfUsernameEqualsDisplayName(_editUserDto.Username, _editUserDto.NewDisplayName).Data == true)
                {
                    return(new ResponseDto <bool>
                    {
                        Data = false,
                        Error = ValidationErrorMessages.USERNAME_IS_EQUAL_TO_DISPLAYNAME
                    });
                }
            }

            return(new ResponseDto <bool>()
            {
                Data = true
            });
        }
Exemplo n.º 6
0
        /// <summary>
        /// The ExecuteStrategy method.
        /// Contains the logic to validate a UserAccountDto.
        /// <para>
        /// @author: Jennifer Nguyen
        /// @updated: 04/04/2018
        /// </para>
        /// </summary>
        /// <returns>ResponseDto</returns>
        public ResponseDto <bool> ExecuteStrategy()
        {
            var validationWrapper = new ValidationWrapper <UserAccountDto>(data: _userAccountDto, ruleSet: "SsoRegistration", validator: _userAccountDtoValidator);
            var result            = validationWrapper.ExecuteValidator();

            if (!result.Data)
            {
                return(result);
            }

            result = _userValidator.CheckIfUserExists(_userAccountDto.Username);
            if (result.Data)
            {
                result.Error = UserManagementErrorMessages.USER_EXISTS;
            }

            return(result);
        }
Exemplo n.º 7
0
        public ResponseDto <bool> ExecuteStrategy()
        {
            var validationWrapper =
                new ValidationWrapper <LoginDto>(_loginDto, "UsernameAndPassword", new LoginDtoValidator());
            var validationResult = validationWrapper.ExecuteValidator();

            // Checking if there is an error in the validation
            if (!validationResult.Data)
            {
                // Return an error if validation fails
                return(new ResponseDto <bool>()
                {
                    Data = false,
                    Error = AuthenticationErrorMessages.USERNAME_PASSWORD_ERROR
                });
            }

            // Checking if user Exists
            var userExistanceValidator      = new UserValidator();
            var validateUserExistanceResult = userExistanceValidator.CheckIfUserExists(_loginDto.Username);

            if (!validateUserExistanceResult.Data)
            {
                return(new ResponseDto <bool>
                {
                    Data = false,
                    Error = AuthenticationErrorMessages.USERNAME_PASSWORD_ERROR
                });
            }

            // Returning the Dto Back if after it has been validated
            return(new ResponseDto <bool>
            {
                Data = true
            });
        }
        /// <summary>
        /// The ExecuteStrategy method.
        /// Contains the logic to validate a data transfer object for creating an individual user.
        /// <para>
        /// @author: Jennifer Nguyen
        /// @updated: 03/20/2018
        /// </para>
        /// </summary>
        /// <returns>ResponseDto</returns>
        public ResponseDto <bool> ExecuteStrategy()
        {
            ResponseDto <bool> result;

            var validationWrappers = new List <IValidationWrapper>()
            {
                new ValidationWrapper <UserAccountDto>(_registerUserDto.UserAccountDto, "CreateUser", new UserAccountDtoValidator()),
                new ValidationWrapper <UserProfileDto>(_registerUserDto.UserProfileDto, "CreateUser", new UserProfileDtoValidator())
            };

            foreach (var securityQuestionDto in _registerUserDto.SecurityQuestionDtos)
            {
                validationWrappers.Add(new ValidationWrapper <SecurityQuestionDto>(securityQuestionDto, "CreateUser", _securityQuestionDtoValidator));
            }

            foreach (var validationWrapper in validationWrappers)
            {
                result = validationWrapper.ExecuteValidator();
                if (!result.Data)
                {
                    return(result);
                }
            }

            // Validate username and display name are not equal
            result = _userValidator.CheckIfUsernameEqualsDisplayName(_registerUserDto.UserAccountDto.Username, _registerUserDto.UserProfileDto.DisplayName);
            if (result.Data)
            {
                if (result.Error == null)
                {
                    result.Error = ValidationErrorMessages.USERNAME_IS_EQUAL_TO_DISPLAYNAME;
                }

                result.Data = false;
                return(result);
            }

            // Validate user does not exist
            result = _userValidator.CheckIfUserExists(_registerUserDto.UserAccountDto.Username);
            if (result.Data)
            {
                if (result.Error == null)
                {
                    result.Error = UserManagementErrorMessages.USER_EXISTS;
                }

                result.Data = false;
                return(result);
            }

            // Validate password has not been previously breached.
            result = _passwordValidator.IsPasswordValid(_registerUserDto.UserAccountDto.Password);
            if (!result.Data)
            {
                if (result.Error == null)
                {
                    result.Error = ValidationErrorMessages.PASSWORD_BREACHED;
                }

                return(result);
            }

            return(new ResponseDto <bool>()
            {
                Data = true
            });
        }