msurguy / Honeypot

Simple spam prevention package for Laravel applications
maxoffsky.com/code-blog/implementing-honeypot-spam-prevention-in-laravel-applications/
MIT License
428 stars 43 forks source link

Does not recognize honeypot method #2

Open enchance opened 10 years ago

enchance commented 10 years ago

Might just be me but I'm getting: An exception has been thrown during the rendering of a template ("Method honeypot does not exist.") in my view. I'm using Twig and access your method as such, form_honeypot('hname', 'htime').

I also have my own custom macros which I'm able to access as form_mymacroname('xxx') so I don't think it's the macro but I might be wrong on this.

lud commented 10 years ago

Hi,

Does Laravel find the service provider as expected ? Can you call its methods ?

enchance commented 10 years ago

It's really not working. I tried using <?php echo Form::honeypot('h', 't'); ?> on a non-twig view and I still got Method honeypot does not exist.. Everything is installed exactly as instructed.

msurguy commented 10 years ago

Are you sure you have the service provider added in the app.php? 'Msurguy\Honeypot\HoneypotServiceProvider',

enchance commented 10 years ago

Yes. Btw, I'm using L4.1. Perhaps this version is affecting your package?

lud commented 10 years ago

I'm using L4.1 and it's ok.

I believe you must add the service provider at the end of the providers array, not at the top. It that all right ?

enchance commented 10 years ago

No, it didn't. Let me check this might be an isolated incident having to do with some of the core classes I've extended.

garygreen commented 9 years ago

Does my recent changes to the service provider fix this issue?

rombat commented 9 years ago

I have the exact same problem. I'm using Laravel 4.2 and I've added 'Msurguy\Honeypot\HoneypotServiceProvider' to app.php

garygreen commented 9 years ago

@rombat are you using twig too? Do you use twigbridge or anything like that?

rombat commented 9 years ago

Nope I'm using Blade. I've just added {{ Form::honeypot('my_name', 'my_time') }} in a form to test Honeypot.

rombat commented 9 years ago

Here's the Exception:


Open: /home/vagrant/Code/laravel/vendor/laravel/framework/src/Illuminate/Support/Traits/MacroableTrait.php

        public static function __callStatic($method, $parameters)
        {
            if (static::hasMacro($method))
            {
                return call_user_func_array(static::$macros[$method], $parameters);
            }

            throw new \BadMethodCallException("Method {$method} does not exist.");
        }

Exception message: Method honeypot does not exist.
garygreen commented 9 years ago

Can you paste your app.php providers array too please.

rombat commented 9 years ago
    'providers' => array(

        'Illuminate\Foundation\Providers\ArtisanServiceProvider',
        'Illuminate\Auth\AuthServiceProvider',
        'Illuminate\Cache\CacheServiceProvider',
        'Illuminate\Session\CommandsServiceProvider',
        'Illuminate\Foundation\Providers\ConsoleSupportServiceProvider',
        'Illuminate\Routing\ControllerServiceProvider',
        'Illuminate\Cookie\CookieServiceProvider',
        'Illuminate\Database\DatabaseServiceProvider',
        'Illuminate\Encryption\EncryptionServiceProvider',
        'Illuminate\Filesystem\FilesystemServiceProvider',
        'Illuminate\Hashing\HashServiceProvider',
        'Illuminate\Html\HtmlServiceProvider',
        'Illuminate\Log\LogServiceProvider',
        'Illuminate\Mail\MailServiceProvider',
        'Illuminate\Database\MigrationServiceProvider',
        'Illuminate\Pagination\PaginationServiceProvider',
        'Illuminate\Queue\QueueServiceProvider',
        'Illuminate\Redis\RedisServiceProvider',
        'Illuminate\Remote\RemoteServiceProvider',
        'Illuminate\Auth\Reminders\ReminderServiceProvider',
        'Illuminate\Database\SeedServiceProvider',
        'Illuminate\Session\SessionServiceProvider',
        'Illuminate\Translation\TranslationServiceProvider',
        'Illuminate\Validation\ValidationServiceProvider',
        'Illuminate\View\ViewServiceProvider',
        'Illuminate\Workbench\WorkbenchServiceProvider',
        'Barryvdh\Debugbar\ServiceProvider',
        'Barryvdh\LaravelIdeHelper\IdeHelperServiceProvider',
        'Roumen\Asset\AssetServiceProvider',
        'Way\Generators\GeneratorsServiceProvider',
        'DaveJamesMiller\Breadcrumbs\ServiceProvider',
        'Jenssegers\Agent\AgentServiceProvider',
        'Arg\Tagcloud\TagcloudServiceProvider',
        'Former\FormerServiceProvider',
        'Bootstrapper\BootstrapperServiceProvider',
        'Lib\Search\SearchServiceProvider',
        'Lib\Validation\ValidationExtensionServiceProvider',
        'Kmd\Logviewer\LogviewerServiceProvider',
        'Indatus\Dispatcher\ServiceProvider',
        'BigName\BackupManager\Integrations\Laravel\BackupManagerServiceProvider',
        'Spatie\Glide\GlideServiceProvider',
        'Msurguy\Honeypot\HoneypotServiceProvider',
    ),
garygreen commented 9 years ago

if possible, can you comment out/remove these providers and see if it honeypot works?

    'Former\FormerServiceProvider',
    'Bootstrapper\BootstrapperServiceProvider',
garygreen commented 9 years ago

Also are you using the latest dev-master of honeypot? Latest tagged version of honeypot is quite old

rombat commented 9 years ago

Yep, I have "vinicius73/seotools": "dev-master". It was due to Former actually. My form was opened/closed with Former. I tried {{ Former::honeypot('my_name', 'my_time') }} and it works. Well, actually, sort of: only the 'my name' field is added, 'my time' is not.

Is there a way to make it work? I'm using Former and Bootstrapper\Form in almost all my forms.

garygreen commented 9 years ago

Weird how the my time field is not added, what's the actual raw HTML output for the honeypot section? You got quite a lot of dependencies to be honest, could be anything.

I did take a look at former and bootstrapper service provider on github as I originally suspected it was replacing Laravel's built in form and therefore overriding the macros, but that doesn't seem like the case. Can you setup a real bare repository on github that replicates the issue in the min number of steps I can take a look.

iBotPeaches commented 9 years ago

Ever since this commit: f18c81f814ca7a4f0d82dc76b78d2790b277c0f5

My regular 4.2 application fails with honeypot method does not exist. I reverted back to the commit prior to that one and everything worked.

garygreen commented 9 years ago

@iBotPeaches what's in your app.providers array?

iBotPeaches commented 9 years ago
    'providers' => array(
        'Illuminate\Foundation\Providers\ArtisanServiceProvider',
        'Illuminate\Auth\AuthServiceProvider',
        'Illuminate\Cache\CacheServiceProvider',
        'Illuminate\Session\CommandsServiceProvider',
        'Illuminate\Foundation\Providers\ConsoleSupportServiceProvider',
        'Illuminate\Routing\ControllerServiceProvider',
        'Illuminate\Cookie\CookieServiceProvider',
        'Illuminate\Database\DatabaseServiceProvider',
        'Illuminate\Encryption\EncryptionServiceProvider',
        'Illuminate\Filesystem\FilesystemServiceProvider',
        'Illuminate\Hashing\HashServiceProvider',
        'Illuminate\Html\HtmlServiceProvider',
        'Illuminate\Log\LogServiceProvider',
        'Illuminate\Database\MigrationServiceProvider',
        'Illuminate\Pagination\PaginationServiceProvider',
        'Illuminate\Queue\QueueServiceProvider',
        'Illuminate\Redis\RedisServiceProvider',
        'Illuminate\Remote\RemoteServiceProvider',
        'Illuminate\Database\SeedServiceProvider',
        'Illuminate\Session\SessionServiceProvider',
        'Illuminate\Translation\TranslationServiceProvider',
        'Illuminate\Validation\ValidationServiceProvider',
        'Illuminate\View\ViewServiceProvider',
        'Illuminate\Workbench\WorkbenchServiceProvider',
        'GrahamCampbell\Markdown\MarkdownServiceProvider',
        'App\Form\Providers\FormBuilderServiceProvider',
        'App\Auth\Providers\PasswordBrokerServiceProvider',
        'Intervention\Image\ImageServiceProvider',
        'Zizaco\Entrust\EntrustServiceProvider',
        'Msurguy\Honeypot\HoneypotServiceProvider',
        'Laravel\Cashier\CashierServiceProvider',
        'Appitventures\Phpgmaps\PhpgmapsServiceProvider',
        'Snowfire\Mail\MailServiceProvider',
        'Bugsnag\BugsnagLaravel\BugsnagLaravelServiceProvider',
garygreen commented 9 years ago

Can you comment out App\Form\Providers\FormBuilderServiceProvider and try if honeypot works?

iBotPeaches commented 9 years ago

Yes that fixed it, but then removed all my custom Form functions that I had created, so can't really use that fix.

garygreen commented 9 years ago

Of course not, just trying to find the cause. Can you post your FormBuilderServiceProvider?

iBotPeaches commented 9 years ago

FormBuilderServiceProvider.php

<?php namespace App\Form\Providers;

use Illuminate\Support\ServiceProvider as IlluminateServiceProvider;
use App\Form\FormBuilder as FormBuilder;

class FormBuilderServiceProvider extends IlluminateServiceProvider {

    /**
     * Indicates if loading of the provider is deferred.
     *
     * @var bool
     */
    protected $defer = true;

    /**
     * Register the service provider.
     *
     * @return void
     */
    public function register()
    {
        $this->app->bindShared('formbuilder', function($app)
        {
            $form = new FormBuilder($app['html'], $app['url'], $app['session.store']->getToken());

            return $form->setSessionStore($app['session.store']);
        });
    }

    /**
     * Get the services provided by the provider.
     *
     * @return array
     */
    public function provides()
    {
        return array('formbuilder');
    }
}
garygreen commented 9 years ago

Does your FormBuilder extends Laravels one? How are you using your custom form builder, do you have a facade?

iBotPeaches commented 9 years ago

Yep my custom FormBuilder extends laravel.

use \Illuminate\Html\FormBuilder as IlluminateFormBuilder;

class FormBuilder extends IlluminateFormBuilder {

Which then changes the Facade in app/config to point to my custom one, allowing me to use my custom functions in addition to the laravel ones.

        'Form'            => 'App\Form\FormBuilderFacade',
garygreen commented 9 years ago

The new service provider in honeypot will listen for when the form alias get's resolved from the container, then register all the macros. The default alias in Laravel is form but I notice you've changed it to formbuilder in your provider. Can you try changing it to just form which will override Laravel's built in one.

iBotPeaches commented 9 years ago

That worked. Thank you!

No idea why I used formbuilder vs form.

rombat commented 9 years ago

@garygreen : here's a test repository with the error: https://github.com/rombat/test-laravel-honeypot It's just a fresh install of Laravel 4.2 with the packages I use on my project, and the default "hello" view edited with honeypot method.

garygreen commented 9 years ago

I've created a PR which will help resolve #25

rombat commented 9 years ago

Thanks!

purplegriffon commented 9 years ago

Getting this too using with L5. Both providers and aliases arrays are setup correctly.

garygreen commented 9 years ago

@purplegriffon are you using the Honeypot facade?

purplegriffon commented 9 years ago

@garygreen I have it listed in the aliases array and in my views I'm using {{ Form::honeypot('pot', 'pot_time') }}, that's what's breaking.

purplegriffon commented 9 years ago

Ah, ignore me. I see the usage has changed. Apologies.

garygreen commented 9 years ago

Yup, we got rid of the form macro as it was a bit of a headache to maintain especially as the form builder is deprecated/no longer maintained, and it's usage didn't really add much value.