anhskohbo / no-captcha

No CAPTCHA reCAPTCHA For Laravel.
https://packagist.org/packages/anhskohbo/no-captcha
MIT License
1.78k stars 234 forks source link

validation not working #26

Closed ghost closed 9 years ago

ghost commented 9 years ago

my no-captcha validation is not working, i can signin without clicking on captcha

this is my validation code

public function validator(array $data) {
    return Validator::make($data, [
        'username' => 'required|max:255|unique:users',
        'email' => 'required|max:255|unique:users',
        'g-recaptcha-response' => 'required|captcha',
        'password' => 'required|confirmed|min:6',
    ]);
}

username, email, password are working, what am i doing wrong ?

yacinelazaar commented 9 years ago

Hi, I'm gonna go ahead and assume you are using Laravel 5.1. I've had the same issue and this is how i managed to solve it: In the 'NoCaptchaServiceProvider' class, your 'register' method should look like this:

public function boot()
    {   
        $app = $this->app;

        $this->bootConfig();

         Validator::extendImplicit('captcha', function ($attribute, $value, $parameters) use ($app){
            return $app['captcha']->verifyResponse($value, $app['request']->getClientIp());
        });

        if ($app->bound('form')) {
            $app['form']->macro('captcha', function ($attributes = []) use ($app) {
                return $app['captcha']->display($attributes, $app->getLocale());
            });
        }
    }

Don't forget to import the 'Validator' facade.

use Validator;
ghost commented 9 years ago

sorry im closing this, the code above is for my signup page, so the captcha actualy works, i forgot to implements the captcha for my login page.. My Bad