Exemple #1
0
        public async Task <ICommandResult> Handle(UpdatePasswordUserCommand command)
        {
            //validar command
            command.Validate();
            if (command.Invalid)
            {
                return(new GenericCommandResult(false, "Ops, algo errado aconteceu!", command.Notifications));
            }

            //GetUser
            var user = await _repository.GetUser(command.Id, command.Email);

            if (user == null)
            {
                return(new GenericCommandResult(false, "Usuário não encontrado", null));
            }

            //Criar VO's
            var pass = new Password(command.Password);

            AddNotifications(pass);

            if (Invalid)
            {
                return(new GenericCommandResult(false, "Ops, algo errado aconteceu!", Notifications));
            }

            user.UpdatePassword(pass);
            _ = _repository.Update(user);

            user.Password.HidePassword();
            //Retorna valores
            return(new GenericCommandResult(true, "Senha atualizada", new { user }));
        }
Exemple #2
0
        public Task <ICommandResult> PutPassword([FromBody] UpdatePasswordUserCommand command)
        {
            command.Id    = Guid.Parse(User.FindFirst(ClaimTypes.Sid)?.Value);
            command.Email = User.FindFirst(ClaimTypes.NameIdentifier)?.Value;
            var result = _handler.Handle(command);

            return(result);
        }
        public void UserAuthHandler_UpdatePassword_Valid()
        {
            var repository    = new FakeUserAuthRepository();
            var logRepository = new FakeAccessLogRepository();
            var handler       = new UserAuthHandler(repository, logRepository);
            var command       = new UpdatePasswordUserCommand();

            command.Username    = repository.GetAll().FirstOrDefault().Username;
            command.Password    = "******";
            command.NewPassword = "******";
            var result = handler.UpdatePassword(command, "userIdentity");

            Assert.IsTrue(result.Success);
        }
        public CommandResult UpdatePassword(UpdatePasswordUserCommand command, string userIdentity)
        {
            // verificação da validade do usuario e senha
            var user = _repository.GetSalt(command.Username);

            if (user == null)
            {
                return(new CommandResult(false, "Login inválido. ", command));
            }

            var salt_tabela = user.Salt;

            byte[] salt         = Convert.FromBase64String(salt_tabela);
            var    hashPassword = Hash.Create(command.Password, salt);

            user = _repository.Login(command.Username, hashPassword);
            if (user == null)
            {
                return(new CommandResult(false, "Senha antiga não confere. ", command));
            }

            // criacao de novo hash para a nova senha
            hashPassword = Hash.Create(command.NewPassword, salt);

            user.UpdatePassword(hashPassword);

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

            _repository.UpdatePassword(user.Id, hashPassword);

            var log = new AccessLog(
                "UpdatePassword",
                DateTime.Now,
                userIdentity,
                "UserAuth",
                $"Usuário alterado: {command.Username}");

            _log.Register(log);

            user.HidePassword();

            return(new CommandResultToken(true, "Senha alterada com sucesso! ", user));
        }
Exemple #5
0
        public CommandResult UpdatePassword(UpdatePasswordUserCommand command)
        {
            CommandResult result = _handler.UpdatePassword(command, User.Identity.Name);

            return(result);
        }