anhskohbo / no-captcha

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

Add reCAPTCHA to laravel Auth #54

Closed ghost closed 7 years ago

ghost commented 7 years ago

Hello, How can I add reCAPTCHA to laravel Auth?(Default Auth)

dann95 commented 7 years ago

To Register, go to :

app/Http/Controllers/Auth/RegisterController.php

it has the following action:

    /**
     * Get a validator for an incoming registration request.
     *
     * @param  array  $data
     * @return \Illuminate\Contracts\Validation\Validator
     */
    protected function validator(array $data)
    {
        return Validator::make($data, [
            'name' => 'required|max:255',
            'email' => 'required|email|max:255|unique:users',
            'password' => 'required|min:6|confirmed',
        ]);
    }

you may add :

    /**
     * Get a validator for an incoming registration request.
     *
     * @param  array  $data
     * @return \Illuminate\Contracts\Validation\Validator
     */
    protected function validator(array $data)
    {
        return Validator::make($data, [
            'name' => 'required|max:255',
            'email' => 'required|email|max:255|unique:users',
            'password' => 'required|min:6|confirmed',
            'g-recaptcha-response' => 'required|captcha'
        ]);
    }

the view of register is located at: resources/views/auth/register.blade.php

add the snippet generator...

login

the LoginController uses the following trait:

<?php

use Illuminate\Foundation\Auth\AuthenticatesUsers;

and it has a function:

    /**
     * Validate the user login request.
     *
     * @param  \Illuminate\Http\Request  $request
     * @return void
     */
    protected function validateLogin(Request $request)
    {
        $this->validate($request, [
            $this->username() => 'required', 'password' => 'required',
        ]);
    }

Override this function inside the Controller and add the same validation of register, i hope it helps you :smiley_cat:

nlpguyz commented 6 years ago

I solved it by removing all files under laravel-auth/storage/framework/sessions