public bool ResetPassword(ResetPasswordDto resetPasswordDto)
        {
            if (resetPasswordDto == null)
            {
                return(false);
            }

            var isValidPw = PropertyValidation.IsValidPassword(resetPasswordDto.NewPassword);

            if (!isValidPw)
            {
                return(false);
            }

            var res = _userRepository.TryUseConfirmationLink(resetPasswordDto.Token, ConfirmType.EmailConfirmation);

            if (res.Success != ConfirmKeyUsageSuccess.Success)
            {
                return(false);
            }
            return(_userRepository.UpdatePassword(resetPasswordDto.Token, PasswordHasher.Hash(resetPasswordDto.NewPassword)));
        }
Exemple #2
0
        public RegisterResult RegisterRequestValid(RegisterRequestDto registerRequestDto)
        {
            if (registerRequestDto == null)
            {
                return(RegisterResult.Unknown);
            }
            if (
                !PropertyValidation.IsValidEmail(registerRequestDto.Email) ||
                !PropertyValidation.IsValidUsername(registerRequestDto.Username) ||
                !PropertyValidation.IsValidName(registerRequestDto.Firstname) ||
                !PropertyValidation.IsValidName(registerRequestDto.Lastname) ||
                !PropertyValidation.IsValidPassword(registerRequestDto.Password) ||
                !PropertyValidation.IsValidPassword(registerRequestDto.Password2)
                )
            {
                return(RegisterResult.MissingInformation);
            }

            if (registerRequestDto.Password != registerRequestDto.Password2)
            {
                return(RegisterResult.PasswordMismatch);
            }

            bool usernameTaken = _userRepository.CheckIfUsernameExists(registerRequestDto.Username);

            if (usernameTaken)
            {
                return(RegisterResult.UsernameTaken);
            }

            bool emailTaken = _userRepository.CheckIfEmailExists(registerRequestDto.Email);

            if (emailTaken)
            {
                return(RegisterResult.EmailTaken);
            }

            return(RegisterResult.Success);
        }