【问题标题】:Adding hCaptcha to Laravel Jetstream (Inertia.js)将 hCaptcha 添加到 Laravel Jetstream (Inertia.js)
【发布时间】:2021-05-06 14:06:01
【问题描述】:

我正在使用 Laravel 8 - Jetstream 2.0 和 Inertia 堆栈。

我安装了 Vue hCaptcha 组件https://github.com/hCaptcha/vue-hcaptcha Vue 组件已经在我的登录表单中并且看起来不错。

Vue component is working

然后我按照这个指南https://serversideup.net/laravel-hcaptcha-custom-validation-rule/ 并在 laravel 中为 hCaptcha 设置了规则。

现在我的问题是,我可以在 laravel/jetstream 的哪个位置设置提交表单时需要的验证码规则。所以验证码被使用了,而不是只显示。

我知道这是一个非常基本的问题,但我对 laravel 还很陌生,并试图进入 vue、initial.js 和 jetstream。

【问题讨论】:

    标签: php laravel vue.js jetstream inertiajs


    【解决方案1】:

    好的,所以 fortitfy 中没有默认的 Logincontroller,所以我自己制作了验证表单中的验证码。此代码缺少用户友好的错误消息管理,但验证码可以正常工作。

    登录控制器

    <?php
    
    namespace App\Http\Controllers\Auth;
    
    use App\Http\Controllers\Controller;
    use App\Models\User;
    use App\Rules\ValidHCaptcha;
    use Illuminate\Http\Request;
    use Illuminate\Support\Facades\Auth;
    use Illuminate\Support\Facades\Hash;
    use Illuminate\Support\Facades\Validator;
    
    
    class LoginController extends Controller
    {
        public function authenticate(Request $request)
        {
    
            // Retrive Input
            $validation = $request->only('email', 'password', 'hcaptcharesponse');
    
            Validator::make($validation, [
                'email' => ['required', 'string', 'email', 'max:255'],
                'password' => ['required'],
                'hcaptcharesponse' => ['required', new ValidHCaptcha()],
            ])->validate();
    
    
            try {
    
                $user = User::where('email', $request->email)->first();
    
                if ($user && Hash::check($request->password, $user->password)) {
    
                    Auth::login($user);
                    return redirect('/dashboard');
    
                }
    
            } catch (Exception $e) {
                dd($e->getMessage());
    
            }
        }
    }
    

    登录控制器的路由

    //Custom login controller for Captcha use Route::post('login', 
    [LoginController::class, 'authenticate'])->name('login');
    

    【讨论】:

      猜你喜欢
      • 2021-03-21
      • 2021-11-22
      • 2021-05-31
      • 2021-06-23
      • 2021-01-23
      • 2021-07-03
      • 2021-04-15
      • 2021-01-08
      • 2021-12-15
      相关资源
      最近更新 更多