示例#1
0
        public IHttpActionResult AuthenticateUser(UserAuthenticateCommand command)
        {
            UserAuthenticateCommandResult result = (UserAuthenticateCommandResult)_handlerAuthenticate.Handle(command);

            return(Response(result));
        }
示例#2
0
        public ICommandResult Handle(UserAuthenticateCommand command)
        {
            var commandResult = new UserAuthenticateCommandResult();

            if (!(_validationService.Validate(command)))
            {
                return(commandResult);
            }

            //Validações de coisas que não vão em repositório
            if (!(command.HasUserName() & command.HasPassword()))
            {
                return(commandResult);
            }

            //Validações de coisas que vão em repositório
            var person = _personRepository.GetByEmailAndPassword(command.User, _passwordService.Encrypt(command.Password));

            if (!(command.HasFoundAuthorizedUser(person) && command.HasActiveUser(person)))
            {
                return(commandResult);
            }

            //Trata fluxo demais regras
            person.SetSerialKey(Guid.NewGuid().ToString().Replace("-", ""));

            person.SetPushToken(command.PushToken);

            #region .: Comment :.
            //var personDevice = _deviceRepository.GetDeviceByPersonIncludingPerson(person);

            //if (personDevice == null)
            //{
            //    var newDevice = new Device(Guid.NewGuid(), description: "", deviceToken: command.Identification, pushToken: "", simCardNumber: "",
            //        deviceOs: DeviceOs.FromValue(command.DeviceOs), identification: command.Identification, person: person);

            //    _deviceRepository.Add(newDevice);
            //}
            //else
            //{
            //    if (personDevice.Identification != command.Identification)
            //    {
            //        personDevice.Disable();
            //        personDevice.Deactivate();
            //        _deviceRepository.Update(personDevice);

            //        var newDevice = new Device(Guid.NewGuid(), description: "", deviceToken: command.Identification, pushToken: "", simCardNumber: "",
            //            deviceOs: DeviceOs.FromValue(command.DeviceOs), identification: command.Identification, person: person);

            //        _deviceRepository.Add(newDevice);
            //    }
            //}

            //if (person.Token == null)
            //{
            //    var newToken = new Token(tokenId: Guid.NewGuid(), userToken: Guid.NewGuid(), deviceOs: DeviceOs.FromValue(command.DeviceOs));

            //    _tokenRepository.Add(newToken);

            //    person.SetToken(newToken);
            //}
            //else
            //{
            //    var token = person.Token;

            //    token.Deactivate();

            //    _tokenRepository.Update(token);


            //    var newToken = new Token(tokenId: Guid.NewGuid(), userToken: Guid.NewGuid(), deviceOs: DeviceOs.FromValue(command.DeviceOs));

            //    _tokenRepository.Add(newToken);

            //    person.SetToken(newToken);
            //}

            #endregion

            _personRepository.Update(person);

            //IEnumerable<CondoPerson> condoPersonList = _condoPersonRepository.GetByPersonIdIncludingCondo(person.PersonId);

            //var condos = condoPersonList.Select(x => new UserAuthenticateCommandResult.Condo()
            //{
            //    CondoId = x.Condo.CondoId.ToString(),
            //    CondoName = x.Condo.Name,
            //    AddressApartment = x.AddressApartment,
            //    AddressBlock = x.AddressBlock,
            //    AddressComplement = x.AddressComplement,
            //    Admin = x.Admin,
            //    Visitor = false,
            //    Resident = x.Resident,
            //    ResidentCode = x.ResidentCode
            //}).ToList();

            //var personVisitorList = _personVisitorRepository.GetByPersonId(person.PersonId);

            //foreach (var personVisitor in personVisitorList)
            //{
            //    if (condos.All(c => c.CondoId != personVisitor.Condo.CondoId.ToString()))
            //    {
            //        condos.Add(new UserAuthenticateCommandResult.Condo()
            //{
            //            CondoId = personVisitor.Condo.CondoId.ToString(),
            //            CondoName = personVisitor.Condo.Name,
            //            AddressApartment = string.Empty,
            //            AddressBlock = string.Empty,
            //            AddressComplement = string.Empty,
            //            Admin = false,
            //            Visitor = true,
            //            Resident = false,
            //            ResidentCode = string.Empty
            //        });
            //}
            //else
            //{
            //        //condos.FirstOrDefault(c => c.CondoId == personVisitor.Condo.CondoId.ToString()).Visitor = true;
            //    }
            //}

            return(new UserAuthenticateCommandResult()
            {
                Name = person.Name,
                SerialKey = person.SerialKey,
                PushToken = person.PushToken,
                PhoneNumber = person.PhoneNumber,
                DocumentNumber = person.DocumentNumber,
                Email = person.Email
                        //Condos = condos
            });
        }