public void UserAuthHandler_Register_User_less_than_4_Characters_Invalid()
        {
            var repository    = new FakeUserAuthRepository();
            var logRepository = new FakeAccessLogRepository();
            var handler       = new UserAuthHandler(repository, logRepository);
            var command       = new RegisterUserAuthCommand();

            command.Username = "******";
            command.Password = "******";
            var result = handler.Register(command);

            Assert.IsFalse(result.Success);
        }
        public void UserAuthHandler_Register_Valid()
        {
            var repository    = new FakeUserAuthRepository();
            var logRepository = new FakeAccessLogRepository();
            var handler       = new UserAuthHandler(repository, logRepository);
            var command       = new RegisterUserAuthCommand();

            command.Username = "******";
            command.Password = "******";
            var result = handler.Register(command);

            Assert.IsTrue(result.Success);
        }
        public CommandResult Register(RegisterUserAuthCommand command)
        {
            var exist = _repository.Exists(command.Username);

            if (exist)
            {
                AddNotification("Já existe um Usuario cadastrado com esse Nome. ");
            }

            var user = new UserAuth(command.Username, command.Password);

            AddNotifications(user);

            if (Invalid)
            {
                return(new CommandResult(false, GroupNotifications.Group(Notifications), command));
            }

            // Add Hash e Salt
            var salt = Salt.Create();
            var hash = Hash.Create(user.Password, salt);

            if (!Hash.Validate(user.Password, salt, hash))
            {
                AddNotification("Erro na geração do Hash. ");
            }

            user.AddHash(hash, Convert.ToBase64String(salt));

            _repository.Register(user);

            var log = new AccessLog(
                "Register",
                DateTime.Now,
                "auto registro",
                "UserAuth",
                $"Nome usuario registrado: {command.Username}");

            _log.Register(log);

            user.HidePassword();

            return(new CommandResult(true, "Cadastro realizado. ", user));
        }
Ejemplo n.º 4
0
        public CommandResult Register(RegisterUserAuthCommand command)
        {
            CommandResult result = _handler.Register(command);

            return(result);
        }