2017 © Pedro PelĂĄez
 

library geetest

Geetest Package for Laravel5

image

germey/geetest

Geetest Package for Laravel5

  • Thursday, July 12, 2018
  • by Germey
  • Repository
  • 7 Watchers
  • 121 Stars
  • 8,384 Installations
  • PHP
  • 2 Dependents
  • 0 Suggesters
  • 24 Forks
  • 3 Open issues
  • 19 Versions
  • 13 % Grown

The README.md

Laravel Geetest

Build Status DUB Support Release, (*1)

Laravel Geetest is a package for Laravel 5 developed by Germey. It provides simple usage for laravel of Geetest., (*2)

Geetest Demo: Geetest, (*3)

Installation

Laravel 5.0 or later is required., (*4)

This Package now supports Geetest 3.0., (*5)

For Geetest 2.0, please see LaravelGeetest 2.0, (*6)

To get the latest version of Laravel Geetest, simply require the project using Composer:, (*7)

$ composer require germey/geetest

Or you can add following to require key in composer.json:, (*8)

"germey/geetest": "~3.0"

then run:, (*9)

$ composer update

Next, You should need to register the service provider. Open up config/app.php and add following into the providers key:, (*10)

Germey\Geetest\GeetestServiceProvider::class

And you can register the Geetest Facade in the aliases of config/app.php :, (*11)

'Geetest' => Germey\Geetest\Geetest::class

Configuration

To get started, you need to publish vendor assets using the following command:, (*12)

$ php artisan vendor:publish --tag=geetest

This will create a config file named config/geetest.php which you can configure geetest as you like., (*13)

It will also generate a views folder named resources/views/vendor/geetest, there will be a view file named geetest.blade.php. Here you can configure styles of geetest. For example, you can change the script alert() as you like., (*14)

Usage

Firstly, You need to register in Geetest. Creating an app and get ID and KEY., (*15)

For example. You can see app ID and KEY after you added an app in Geetest Admin Page, (*16)

, (*17)

Then configure them in your .env file because you'd better not make them public., (*18)

Add them to .env as follows:, (*19)

GEETEST_ID=0f1097bef7xxxxxx9afdeced970c63e4
GEETEST_KEY=c070f0628xxxxxxe68e138b55c56fb3b

Then, You can use render() in views like following, It will render a geetest code captcha:, (*20)

{!! Geetest::render() !!}

For example, you can use it in form like this:, (*21)

<form action="/" method="post">
    <input name="_token" type="hidden" value="{{ csrf_token() }}">
    <input type="text" name="name" placeholder="name">
    {!! Geetest::render() !!}
    <input type="submit" value="submit">
</form>

It will render like this:, (*22)

, (*23)

When you click the submit button, it will verify the Geetest Code. If you didn't complete the validation, it will alert some text and prevent the form from submitting., (*24)

Or you can set other style of Geetest:, (*25)

{!! Geetest::render('float') !!}
{!! Geetest::render('bind') !!}
{!! Geetest::render('popup') !!}
{!! Geetest::render('custom') !!}

Then it will be embed or popup style in the website. Default to float., (*26)

If the validation is completed, the form will be submitted successfully., (*27)

Server Validation

What's the reason that Geetest is safe? If it only has client validation of frontend, can we say it is complete? It also has server validation to ensure that the post request is validate., (*28)

First I have to say that you can only use Geetest of Frontend. But you can also do simple things to achieve server validation., (*29)

You can use $this->validate() method to achieve server validation. Here is an example:, (*30)

use Illuminate\Http\Request;

class BaseController extends Controller 
{
    /**
     * @param Request $request
     */
    public function postValidate(Request $request)
    {
        $this->validate($request, [
            'geetest_challenge' => 'geetest',
        ], [
            'geetest' => config('geetest.server_fail_alert')
        ]);
        return true;
    }
} 

If we use Geetest, the form will post three extra parameters geetest_challenge geetest_validate geetest_seccode. Geetest use these three parameters to achieve server validation., (*31)

If you use ORM, we don't need to add these keys to Model, so you should add following in Model:, (*32)

protected $guarded = ['geetest_challenge', 'geetest_validate', 'geetest_seccode'];

You can define alert text by altering server_fail_alert in config/geetest.php, (*33)

Also you can use Request to achieve validation:, (*34)

<?php namespace App\Http\Requests;
use App\Http\Requests\Request;

class ValidationRequest extends Request
{
    /**
     * Determine if the user is authorized to make this request.
     *
     * @return bool
     */
    public function authorize()
    {
        return true;
    }

    /**
     * Get the validation rules that apply to the request.
     *
     * @return array
     */
    public function rules()
    {
        return [
            'geetest_challenge' => 'geetest'
        ];
    }

    /**
     * Get validation messages.
     *
     * @return array
     */
    public function messages()
    {
        return [
            'geetest' => 'Validation Failed'
        ];
    }
}

We can use it in our Controller by Request parameter:, (*35)

use Illuminate\Support\Facades\Config;
use Illuminate\Http\Request;
use App\Http\Requests\ValidationRequest;

class BaseController extends Controller 
{
    /**
     * @param Request $request
     */
    public function postValidate(ValidationRequest $request)
    {
        // is Validate
    }
} 

Options

Change Ajax Url

If you want to change the Geetest Ajax Url, you can configure it in config/geetest.php, change url as you like, but at this time you need to add extra routes in your routes.php (Laravel 5.2 or former ) or routes/web.php (Laravel 5.3 or later). And you need to add a triat in your controller., (*36)

For example, If you add this route:, (*37)

Route::get('auth/geetest','Auth\AuthController@getGeetest');

you need to add Germey\Geetest\GeetestCaptcha in your AuthController:, (*38)

use Germey\Geetest\GeetestCaptcha;
class AuthController extends Controller {
    use GeetestCaptcha;
}

Then an Ajax url is configured successfully., (*39)

Also you can use this Trait in other Controller but you need to configure url in config/geetest.php., (*40)

Configure Url while rendering

Also, you can set Geetest Ajax Url by following way:, (*41)

{!! Geetest::setGeetestUrl('/auth/geetest')->render() !!}

By setGeetestUrl method you can set Geetest Ajax Url. If it is configured, it will override url configured in config/geetest.php., (*42)

Configure Alert Message

You can configure alert message by configure client_fail_alert and server_fail_alert in config/geetest.php., (*43)

Configure Language

Geetest supports different language:, (*44)

  • Simplified Chinese
  • Traditional Chinese
  • English
  • Japanese
  • Korean

You can configure it in config/geetest.php ., (*45)

Here are key-values of Languge Configuration:, (*46)

  • zh-cn (Simplified Chinese)
  • zh-tw (Traditional Chinese)
  • en (English)
  • ja (Japanese)
  • ko (Korean)

for example, If you want to use Korean, just change lang key to ko:, (*47)

'lang' => 'ko'

Configure Protocol

You can configure protocol in config/geetest.php ., (*48)

for example, If you want to use https, just change protocol key to https:, (*49)

'protocol' => 'https'

Configure Default Product

You can configure default product in config/geetest.php ., (*50)

for example, If you want to use popup product, just change product key to popup:, (*51)

'product' => 'popup'

Mind that it only works when you use like this:, (*52)

{!! Geetest::render() !!}

If you use like this:, (*53)

{!! Geetest::render('bind') !!}

It will override the configuration in config/geetest.php., (*54)

Contribution

If you find something wrong with this package, you can send an email to cqc@cuiqingcai.com, (*55)

Or just send a pull request to this repository., (*56)

Pull Requests are really welcomed., (*57)

Author

Germey , from Beijing China, (*58)

License

Laravel Geetest is licensed under The MIT License (MIT)., (*59)

The Versions

12/07 2018

dev-master

9999999-dev

Geetest Package for Laravel5

  Sources   Download

MIT

The Requires

 

The Development Requires

laravel germey geetest

12/07 2018

v3.0.7

3.0.7.0

Geetest Package for Laravel5

  Sources   Download

MIT

The Requires

 

The Development Requires

laravel germey geetest

24/01 2018

v3.0.6

3.0.6.0

Geetest Package for Laravel5

  Sources   Download

MIT

The Requires

 

The Development Requires

laravel germey geetest

13/11 2017

v3.0.5

3.0.5.0

Geetest Package for Laravel5

  Sources   Download

MIT

The Requires

 

The Development Requires

laravel germey geetest

13/11 2017

v3.0.4

3.0.4.0

Geetest Package for Laravel5

  Sources   Download

MIT

The Requires

 

The Development Requires

laravel germey geetest

04/09 2017

v3.0.3

3.0.3.0

Geetest Package for Laravel5

  Sources   Download

MIT

The Requires

 

The Development Requires

laravel germey geetest

04/09 2017

v3.0.2

3.0.2.0

Geetest Package for Laravel5

  Sources   Download

MIT

The Requires

 

The Development Requires

laravel germey geetest

11/07 2017

v3.0.1

3.0.1.0

Geetest Package for Laravel5

  Sources   Download

MIT

The Requires

 

The Development Requires

laravel germey geetest

30/06 2017

v3.0.0

3.0.0.0

Geetest Package for Laravel5

  Sources   Download

MIT

The Requires

 

The Development Requires

laravel germey geetest

30/06 2017

v2.0.3

2.0.3.0

Geetest Package for Laravel5

  Sources   Download

MIT

The Requires

 

The Development Requires

laravel germey geetest

19/02 2017

v2.0.2

2.0.2.0

Geetest Package for Laravel5

  Sources   Download

MIT

The Requires

 

The Development Requires

laravel germey geetest

03/02 2017

v2.0.1

2.0.1.0

Geetest Package for Laravel5

  Sources   Download

MIT

The Requires

 

The Development Requires

laravel germey geetest

03/02 2017

v2.0.0

2.0.0.0

Geetest Package for Laravel5

  Sources   Download

MIT

The Requires

 

The Development Requires

laravel germey geetest

10/10 2016

v1.0.4

1.0.4.0

Geetest Package for Laravel5

  Sources   Download

MIT

The Requires

 

The Development Requires

laravel germey geetest

11/08 2016

v1.0.3

1.0.3.0

Geetest Package for Laravel5

  Sources   Download

MIT

The Requires

 

The Development Requires

laravel germey geetest

26/07 2016

v1.0.2

1.0.2.0

Geetest Package for Laravel5

  Sources   Download

MIT

The Requires

 

The Development Requires

laravel germey geetest

25/07 2016

v1.0.1

1.0.1.0

Geetest Package for Laravel5

  Sources   Download

MIT

The Requires

 

laravel germey geetest

25/07 2016

v1.0.0

1.0.0.0

Geetest Package for Laravel5

  Sources   Download

MIT

The Requires

 

laravel germey geetest

25/07 2016

v0.9.0-alpha

0.9.0.0-alpha

Geetest Package for Laravel5

  Sources   Download

MIT

The Requires

 

laravel germey geetest