浏览代码

怎加图形验证码

黄宗昌 2 年之前
父节点
当前提交
906ec47401
共有 6 个文件被更改,包括 240 次插入2 次删除
  1. 15 0
      app/Http/Controllers/V1/AuthController.php
  2. 1 0
      composer.json
  3. 170 1
      composer.lock
  4. 2 1
      config/app.php
  5. 51 0
      config/captcha.php
  6. 1 0
      routes/api.php

+ 15 - 0
app/Http/Controllers/V1/AuthController.php

xqd xqd xqd xqd
@@ -15,6 +15,7 @@ use Illuminate\Http\Request;
 use Illuminate\Support\Facades\Auth;
 use Illuminate\Support\Facades\DB;
 use Laravel\Socialite\Facades\Socialite;
+use Mews\Captcha\Captcha;
 use PHPUnit\Util\Exception;
 use Illuminate\Support\Facades\Validator;
 
@@ -30,6 +31,8 @@ class AuthController extends Controller
         $account   = $request->input('account', '');
         $password = $request->input('password', '');
         $passwords = $request->input('passwords', '');
+        $captcha = $request->input('captcha', '');
+        $captcha_key = $request->input('captcha_key','');
         $validator = Validator::make($request->all(), [
             'account' => 'required',
             'name' => 'required|alpha_num',
@@ -40,6 +43,9 @@ class AuthController extends Controller
         if ($validator->fails()) {
             return $this->error($validator->errors()->first());
         }
+        if(!captcha_api_check($captcha,$captcha_key)){
+            return $this->error("图形验证码错误!");
+        }
         if($password != $passwords){
             return $this->error('密码不一致!');
         }
@@ -310,4 +316,13 @@ class AuthController extends Controller
         auth('api')->logout();
         return $this->success('',0,'退出成功!');
     }
+
+    /**
+     * @return void
+     * 图形验证码
+     */
+    public function captcha(){
+        $captcha = app('captcha')->create('default', true);
+        return $this->success($captcha);
+    }
 }

+ 1 - 0
composer.json

xqd
@@ -19,6 +19,7 @@
         "laravel/framework": "^8.0",
         "laravel/sanctum": "^2.11",
         "laravel/tinker": "^2.5",
+        "mews/captcha": "^3.3",
         "nesbot/carbon": "^2.52",
         "overtrue/easy-sms": "^2.1",
         "overtrue/laravel-lang": "^3.0",

+ 170 - 1
composer.lock

xqd xqd xqd
@@ -4,7 +4,7 @@
         "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
         "This file is @generated automatically"
     ],
-    "content-hash": "49749ea095e75e6e4958bcc7bced5fec",
+    "content-hash": "c91d47386ef9d2fbcabd043f7a00e4ac",
     "packages": [
         {
             "name": "adbario/php-dot-notation",
@@ -2710,6 +2710,96 @@
             },
             "time": "2020-11-30T06:17:22+00:00"
         },
+        {
+            "name": "intervention/image",
+            "version": "2.7.2",
+            "source": {
+                "type": "git",
+                "url": "https://github.com/Intervention/image.git",
+                "reference": "04be355f8d6734c826045d02a1079ad658322dad"
+            },
+            "dist": {
+                "type": "zip",
+                "url": "https://api.github.com/repos/Intervention/image/zipball/04be355f8d6734c826045d02a1079ad658322dad",
+                "reference": "04be355f8d6734c826045d02a1079ad658322dad",
+                "shasum": "",
+                "mirrors": [
+                    {
+                        "url": "https://mirrors.aliyun.com/composer/dists/%package%/%reference%.%type%",
+                        "preferred": true
+                    }
+                ]
+            },
+            "require": {
+                "ext-fileinfo": "*",
+                "guzzlehttp/psr7": "~1.1 || ^2.0",
+                "php": ">=5.4.0"
+            },
+            "require-dev": {
+                "mockery/mockery": "~0.9.2",
+                "phpunit/phpunit": "^4.8 || ^5.7 || ^7.5.15"
+            },
+            "suggest": {
+                "ext-gd": "to use GD library based image processing.",
+                "ext-imagick": "to use Imagick based image processing.",
+                "intervention/imagecache": "Caching extension for the Intervention Image library"
+            },
+            "type": "library",
+            "extra": {
+                "branch-alias": {
+                    "dev-master": "2.4-dev"
+                },
+                "laravel": {
+                    "providers": [
+                        "Intervention\\Image\\ImageServiceProvider"
+                    ],
+                    "aliases": {
+                        "Image": "Intervention\\Image\\Facades\\Image"
+                    }
+                }
+            },
+            "autoload": {
+                "psr-4": {
+                    "Intervention\\Image\\": "src/Intervention/Image"
+                }
+            },
+            "notification-url": "https://packagist.org/downloads/",
+            "license": [
+                "MIT"
+            ],
+            "authors": [
+                {
+                    "name": "Oliver Vogel",
+                    "email": "oliver@intervention.io",
+                    "homepage": "https://intervention.io/"
+                }
+            ],
+            "description": "Image handling and manipulation library with support for Laravel integration",
+            "homepage": "http://image.intervention.io/",
+            "keywords": [
+                "gd",
+                "image",
+                "imagick",
+                "laravel",
+                "thumbnail",
+                "watermark"
+            ],
+            "support": {
+                "issues": "https://github.com/Intervention/image/issues",
+                "source": "https://github.com/Intervention/image/tree/2.7.2"
+            },
+            "funding": [
+                {
+                    "url": "https://paypal.me/interventionio",
+                    "type": "custom"
+                },
+                {
+                    "url": "https://github.com/Intervention",
+                    "type": "github"
+                }
+            ],
+            "time": "2022-05-21T17:30:32+00:00"
+        },
         {
             "name": "jpush/jpush",
             "version": "v3.6.8",
@@ -3947,6 +4037,85 @@
             },
             "time": "2022-04-15T14:02:14+00:00"
         },
+        {
+            "name": "mews/captcha",
+            "version": "3.3.0",
+            "source": {
+                "type": "git",
+                "url": "https://github.com/mewebstudio/captcha.git",
+                "reference": "8c439263d0ba42e6c05e4d1f3bee0a2b97e675d5"
+            },
+            "dist": {
+                "type": "zip",
+                "url": "https://api.github.com/repos/mewebstudio/captcha/zipball/8c439263d0ba42e6c05e4d1f3bee0a2b97e675d5",
+                "reference": "8c439263d0ba42e6c05e4d1f3bee0a2b97e675d5",
+                "shasum": "",
+                "mirrors": [
+                    {
+                        "url": "https://mirrors.aliyun.com/composer/dists/%package%/%reference%.%type%",
+                        "preferred": true
+                    }
+                ]
+            },
+            "require": {
+                "ext-gd": "*",
+                "illuminate/config": "~5|^6|^7|^8|^9|^10.0",
+                "illuminate/filesystem": "~5|^6|^7|^8|^9|^10.0",
+                "illuminate/hashing": "~5|^6|^7|^8|^9|^10.0",
+                "illuminate/session": "~5|^6|^7|^8|^9|^10.0",
+                "illuminate/support": "~5|^6|^7|^8|^9|^10.0",
+                "intervention/image": "~2.5",
+                "php": "^7.2|^8.0"
+            },
+            "require-dev": {
+                "mockery/mockery": "^1.0",
+                "phpunit/phpunit": "^8.5|^9.0"
+            },
+            "type": "package",
+            "extra": {
+                "laravel": {
+                    "providers": [
+                        "Mews\\Captcha\\CaptchaServiceProvider"
+                    ],
+                    "aliases": {
+                        "Captcha": "Mews\\Captcha\\Facades\\Captcha"
+                    }
+                }
+            },
+            "autoload": {
+                "files": [
+                    "src/helpers.php"
+                ],
+                "psr-4": {
+                    "Mews\\Captcha\\": "src/"
+                }
+            },
+            "notification-url": "https://packagist.org/downloads/",
+            "license": [
+                "MIT"
+            ],
+            "authors": [
+                {
+                    "name": "Muharrem ERİN",
+                    "email": "me@mewebstudio.com",
+                    "homepage": "https://github.com/mewebstudio",
+                    "role": "Developer"
+                }
+            ],
+            "description": "Laravel 5 & 6 Captcha Package",
+            "homepage": "https://github.com/mewebstudio/captcha",
+            "keywords": [
+                "captcha",
+                "laravel5 Security",
+                "laravel6 Captcha",
+                "laravel6 Security"
+            ],
+            "support": {
+                "issues": "https://github.com/mewebstudio/captcha/issues",
+                "source": "https://github.com/mewebstudio/captcha/tree/3.3.0"
+            },
+            "time": "2023-03-14T08:30:02+00:00"
+        },
         {
             "name": "monolog/monolog",
             "version": "2.7.0",

+ 2 - 1
config/app.php

xqd xqd
@@ -177,6 +177,7 @@ return [
         // App\Providers\BroadcastServiceProvider::class,
         App\Providers\EventServiceProvider::class,
         App\Providers\RouteServiceProvider::class,
+        Mews\Captcha\CaptchaServiceProvider::class,
 
     ],
 
@@ -231,7 +232,7 @@ return [
         'URL' => Illuminate\Support\Facades\URL::class,
         'Validator' => Illuminate\Support\Facades\Validator::class,
         'View' => Illuminate\Support\Facades\View::class,
-
+        'Captcha' => Mews\Captcha\Facades\Captcha::class,
     ],
 
 ];

+ 51 - 0
config/captcha.php

xqd
@@ -0,0 +1,51 @@
+<?php
+
+return [
+    'disable' => env('CAPTCHA_DISABLE', false),
+    'characters' => ['2', '3', '4', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'j', 'm', 'n', 'p', 'q', 'r', 't', 'u', 'x', 'y', 'z', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'J', 'M', 'N', 'P', 'Q', 'R', 'T', 'U', 'X', 'Y', 'Z'],
+    'default' => [
+        'length' => 4,
+        'width' => 120,
+        'height' => 36,
+        'quality' => 90,
+        'math' => false,
+        'expire' => 600,
+        'encrypt' => false,
+    ],
+    'math' => [
+        'length' => 9,
+        'width' => 120,
+        'height' => 36,
+        'quality' => 90,
+        'math' => true,
+    ],
+
+    'flat' => [
+        'length' => 6,
+        'width' => 160,
+        'height' => 46,
+        'quality' => 90,
+        'lines' => 6,
+        'bgImage' => false,
+        'bgColor' => '#ecf2f4',
+        'fontColors' => ['#2c3e50', '#c0392b', '#16a085', '#c0392b', '#8e44ad', '#303f9f', '#f57c00', '#795548'],
+        'contrast' => -5,
+    ],
+    'mini' => [
+        'length' => 3,
+        'width' => 60,
+        'height' => 32,
+    ],
+    'inverse' => [
+        'length' => 5,
+        'width' => 120,
+        'height' => 36,
+        'quality' => 90,
+        'sensitive' => true,
+        'angle' => 12,
+        'sharpen' => 10,
+        'blur' => 2,
+        'invert' => true,
+        'contrast' => -5,
+    ]
+];

+ 1 - 0
routes/api.php

xqd
@@ -30,6 +30,7 @@ $api->version('v1', ['namespace' => 'App\Http\Controllers\V1'], function ($api)
         $api->delete('attachments/{uid}', 'AttachmentController@delete'); //删除附件
         $api->post('reset_password', 'AuthController@forgetPassword');  //用户找回密码
         $api->post('find_id', 'AuthController@findId');  //用户找回ID
+        $api->get('captcha', 'AuthController@captcha'); // 图形二维码
 
         $api->get('privacy', 'IndexController@privacyPolice'); //隐私政策
         $api->get('agreement', 'IndexController@userAgreement'); //用户协议