Ejemplo n.º 1
0
        public SendNewPasswordValidator(IPlayerRepository repository, IAuthQueries authQueries)
        {
            int passwordMinLength = CommonPlayerSettings.PasswordMinLength;
            int passwordMaxLength = CommonPlayerSettings.PasswordMaxLength;

            string passwordIsNotWithinItsAllowedRangeErrorMessage =
                string.Format(Messages.PasswordIsNotWithinItsAllowedRangeErrorMessageFormat, passwordMinLength,
                              passwordMaxLength);

            RuleFor(x => x.PlayerId)
            .Must(x => repository.Players.Any(p => p.Id == x))
            .WithMessage(Messages.InvalidPlayerId)
            .DependentRules(x =>
            {
                RuleFor(y => y.NewPassword)
                .Length(passwordMinLength, passwordMaxLength)
                .WithMessage(passwordIsNotWithinItsAllowedRangeErrorMessage)
                .Must((data, y) =>
                {
                    var loginValidationResult = authQueries.GetValidationResult(new LoginActor
                    {
                        ActorId  = data.PlayerId,
                        Password = data.NewPassword
                    });

                    var passwordsMatch = loginValidationResult.IsValid;

                    return(!passwordsMatch);
                })
                .WithMessage(Messages.PasswordsMatch);
            });
        }
Ejemplo n.º 2
0
            public ValidationResult Validate(ConfirmResetPasswordRequest request)
            {
                var player = _playerQueries.GetPlayer(request.PlayerId);
                var loginValidationResult = _playerQueries.GetValidationFailures(player.Username, null);

                if (!loginValidationResult.IsValid)
                {
                    return new ValidationResult
                           {
                               Errors = loginValidationResult.Errors
                                        .GroupBy(o => o.PropertyName)
                                        .Select(o => o.First())
                                        .ToDictionary(k => k.PropertyName, v => v.ErrorMessage)
                           }
                }
                ;

                var data    = Mapper.DynamicMap <ConfirmResetPasswordRequest, ConfirmResetPasswordData>(request);
                var result2 = _validator.Validate(data);

                if (!result2.IsValid)
                {
                    return new ValidationResult
                           {
                               Errors = result2.Errors
                                        .GroupBy(o => o.PropertyName)
                                        .Select(o => o.First())
                                        .ToDictionary(k => k.PropertyName, v => v.ErrorMessage)
                           }
                }
                ;


                var result = _authQueries.GetValidationResult(new ChangePassword
                {
                    ActorId     = request.PlayerId,
                    NewPassword = request.NewPassword
                });

                return(new ValidationResult
                {
                    Errors = result.Errors
                             .GroupBy(o => o.PropertyName)
                             .Select(o => o.First())
                             .ToDictionary(k => k.PropertyName, v => v.ErrorMessage)
                });
            }
        }
Ejemplo n.º 3
0
        public ValidationResult GetValidationResult(LoginAdmin data)
        {
            var admin = _repository.Admins.SingleOrDefault(x => x.Username == data.Username);
            var adminValidationResult = new LoginValidator().Validate(admin);

            if (adminValidationResult.IsValid == false)
            {
                return(adminValidationResult);
            }

            var loginValidationResult = _authQueries.GetValidationResult(new LoginActor
            {
                ActorId  = admin.Id,
                Password = data.Password
            });

            return(loginValidationResult);
        }
Ejemplo n.º 4
0
        public void CreateActor(CreateActor model)
        {
            var result = _authQueries.GetValidationResult(model);

            if (result.IsValid == false)
            {
                throw new ApplicationException(result.Errors.First().ErrorMessage);
            }

            var actor = new Entities.Actor(model.ActorId, model.Username, model.Password);

            _repository.Actors.Add(actor.Data);
            _repository.SaveChanges();
        }
Ejemplo n.º 5
0
        public LoginValidator(BrandQueries brandQueries, IAuthQueries authQueries, string password)
        {
            CascadeMode = CascadeMode.StopOnFirstFailure;

            RuleFor(player => player)
            .NotNull()
            .WithMessage(PlayerAccountResponseCode.UsernamePasswordCombinationIsNotValid.ToString())
            .WithName("Player");

            When(player => player != null, () =>
            {
                RuleFor(player => player.IsInactive)
                .NotEqual(true)
                .WithMessage(PlayerAccountResponseCode.NonActive.ToString());

                RuleFor(player => player.IsLocked)
                .NotEqual(true)
                .WithMessage(PlayerAccountResponseCode.AccountLocked.ToString());

                RuleFor(player => player.BrandId)
                .Must(brandQueries.IsBrandActive)
                .WithMessage(PlayerAccountResponseCode.InactiveBrand.ToString());

                if (password != null)
                {
                    RuleFor(player => player)
                    .Must(player =>
                    {
                        var loginValidationResult = authQueries.GetValidationResult(new LoginActor
                        {
                            ActorId  = player.Id,
                            Password = password
                        });

                        return(loginValidationResult.IsValid);
                    })
                    .WithMessage(PlayerAccountResponseCode.UsernamePasswordCombinationIsNotValid.ToString())
                    .WithName("Player");
                }

                RuleFor(player => player.SelfExclusion)
                .Must(selfExclusion => !selfExclusion.HasValue || selfExclusion.Value != SelfExclusion.Permanent)
                .WithMessage(PlayerAccountResponseCode.SelfExcludedPermanent.ToString(),
                             player => new ValidationParam
                {
                    Name  = "start",
                    Value = player.SelfExclusionDate.Value.ToString("yyyy/MM/dd hh:mm tt")
                })
                .Must(selfExclusion => !selfExclusion.HasValue)
                .WithMessage(PlayerAccountResponseCode.SelfExcluded.ToString(),
                             player => new ValidationParam
                {
                    Name  = "start",
                    Value = player.SelfExclusionDate.Value.ToString("yyyy/MM/dd hh:mm tt")
                },
                             player =>
                {
                    var endDate = ExclusionDateHelper.GetSelfExcusionEndDate(player.SelfExclusion.Value,
                                                                             player.SelfExclusionDate.Value);

                    return(new ValidationParam
                    {
                        Name = "end",
                        Value = endDate.ToString("yyyy/MM/dd hh:mm tt")
                    });
                },
                             player =>
                {
                    return(new ValidationParam
                    {
                        Name = "length",
                        Value = Enum.GetName(typeof(SelfExclusion), player.SelfExclusion.Value)
                    });
                });

                RuleFor(player => player.TimeOut.HasValue)
                .NotEqual(true)
                .WithMessage(PlayerAccountResponseCode.TimedOut.ToString(),
                             player => new ValidationParam
                {
                    Name  = "start",
                    Value = player.TimeOutDate.Value.ToString("yyyy/MM/dd hh:mm tt")
                },
                             player =>
                {
                    var endDate = ExclusionDateHelper.GetTimeOutEndDate(player.TimeOut.Value,
                                                                        player.TimeOutDate.Value);

                    return(new ValidationParam
                    {
                        Name = "end",
                        Value = endDate.ToString("yyyy/MM/dd hh:mm tt")
                    });
                },
                             player =>
                {
                    return(new ValidationParam
                    {
                        Name = "length",
                        Value = Enum.GetName(typeof(TimeOut), player.TimeOut.Value)
                    });
                });
            });
        }
Ejemplo n.º 6
0
        public void Invalid_actorId_is_not_valid_for_login()
        {
            var model = new LoginActor();

            var result = _authQueries.GetValidationResult(model);

            result.IsValid.Should().BeFalse();
            result.Errors.Single().ErrorMessage.Should().Be(ErrorsCodes.ActorDoesNotExist.ToString());
        }