Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

SpamProtection to use the honeypot everywhere #107

Merged
merged 21 commits into from
May 21, 2022

Conversation

masterix21
Copy link
Contributor

It adds the ability to use the honeypot everywhere through a trait: for example, in a Livewire component.

I will add a test before the merge (if it will be approved).

@freekmurze
Copy link
Member

Looks good, ping me again when tests have been added.

@masterix21
Copy link
Contributor Author

@freekmurze

I replaced many code parts because my first version wasn't good for me.

So, look at the README.md to understand how it works: I think this is the best solution to support the antispam in the Livewire components.

Tests are ready.

@freekmurze freekmurze merged commit fc7ff9e into spatie:main May 21, 2022
@freekmurze
Copy link
Member

Thanks! I'll polish a bit on main and release it.

@masterix21
Copy link
Contributor Author

❤️

@masterix21
Copy link
Contributor Author

Do you have any idea about the release date? Thanks for all your effort.

@freekmurze
Copy link
Member

O, I thought I already done that.

There you go: https://github.com/spatie/laravel-honeypot/releases/tag/4.3.0

Thanks again!

@francoism90
Copy link

@masterix21 @freekmurze Maybe this can be added to the README? By using an extra trait, it can be included with ease into every component with minimal code:

<?php

namespace App\Traits;

use Spatie\Honeypot\Http\Livewire\Concerns\HoneypotData;
use Spatie\Honeypot\Http\Livewire\Concerns\UsesSpamProtection;

trait WithHoneypot
{
    use UsesSpamProtection;

    public HoneypotData $extraFields;

    public function mountWithHoneypot()
    {
        $this->extraFields = new HoneypotData();
    }
}

e.g. #

<?php

use App\Traits\WithHoneypot;

class #Component extends Component
{
    use WithHoneypot;

    public function submit()
    {
        // Protect against spam
        $this->protectAgainstSpam();

        // Validate request
        $validated = $this->validate();

       // ..
    }
}

@freekmurze
Copy link
Member

@francoism90 Feel free to PR that to the readme.

@masterix21
Copy link
Contributor Author

@francoism90: I didn't create a trait like yours only to randomize the forms better, but as Freek said, feel free to PR it (I'm not a maintainer here, so I can't help you).

@masterix21 masterix21 deleted the add-livewire-support branch May 24, 2022 09:43
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants