我已经在我的 laravel Starter Kit 中手动安装了 fortify,因为我需要在登录时添加一些附加检查
我 app/Providers/FortifyServiceProvider.php 我这样做:
<?php
namespace App\Providers;
use App\Actions\Fortify\CreateNewUser;
use App\Actions\Fortify\ResetUserPassword;
use App\Actions\Fortify\UpdateUserPassword;
use App\Actions\Fortify\UpdateUserProfileInformation;
use App\Models\User;
use Carbon\Carbon;
use Illuminate\Cache\RateLimiting\Limit;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Hash;
use Illuminate\Support\Facades\RateLimiter;
use Illuminate\Support\ServiceProvider;
use Illuminate\Validation\ValidationException;
use Laravel\Fortify\Fortify;
class FortifyServiceProvider extends ServiceProvider
{
public function register()
{
//
}
/**
* Bootstrap any application services.
*
* @return void
*/
public function boot()
{
Fortify::loginView(function () { // THIS ACTION IS TRIGGERED
return view('auth.login', [] );
});
Fortify::authenticateUsing(function (Request $request) { // BUT THIS ACTION IS NOT TRIGGERED
$user = User::where('email', $request->email)->first();
\Log::info( varDump($user, ' -1 $user::') );
\Log::info( varDump($request, ' -2 $request::') );
$request = request();
if ($user && Hash::check($request->password, $user->password)) {
if ( $user->status === 'A') {
return $user;
}
else {
throw ValidationException::withMessages([
Fortify::username() => "Account is inactive",
]);
}
}
});
Fortify::registerView(function () {
\Log::info( ' -33 registerView::');
return view('auth.register', [] );
});
我在 resources/views/auth/login.blade.php 我定义了表单:
<form action="/login" method="POST" enctype="multipart/form-data">
@csrf
<div class="row">
<div class="row mb-4">
<div class="col-lg-4">
<label class="form-label" for="example-email-input">{{ __('email') }}</label>
</div>
<div class="col-lg-8">
<input type="email" class="form-control" id="example-email-input"
name="example-email-input" placeholder="">
</div>
</div>
<div class="row mb-4">
<div class="col-lg-4">
<label class="form-label" for="example-password-input">{{ __('password') }}</label>
</div>
<div class="col-lg-8">
<input type="password" class="form-control" id="example-password-input"
name="example-password-input" placeholder="">
</div>
</div>
<div class="d-flex justify-content-end">
<div class="mr-auto"> </div>
<div class="m-2" >
<button type="button" href="{{ route('home') }}" class="btn btn-secondary">{{ __('Home') }}</button>
</div>
<div class="m-2">
<button type="submit" class="btn btn-primary mx-4 ">{{ __('login') }}</button>
</div>
</div>
</div>
</form>
在我看到的路线列表中:
| GET|HEAD | login | login | Laravel\Fortify\Http\Controllers\AuthenticatedSessionController@create | web |
| | | | | | App\Http\Middleware\RedirectIfAuthenticated:web |
| | POST | login | generated::uIOPlOK71yjjoFFT | Laravel\Fortify\Http\Controllers\AuthenticatedSessionController@store | web |
|
在 config/fortify.php 我有:
'features' => [
Features::registration(),
Features::resetPasswords(),
Features::emailVerification(),
Features::updateProfileInformation(),
Features::updatePasswords(),
Features::twoFactorAuthentication([
'confirmPassword' => true,
]),
],
同样在 config/app.php 我添加了行
'providers' => [
...
App\Providers\FortifyServiceProvider::class,
我错过了什么 ?
修改块:
我发现了 1 个问题,在登录刀片表单中,我使用 route('login') 修改了表单定义:
<form action="{{ route('login') }}" method="POST" enctype="multipart/form-data">
@csrf
但无论如何,不会触发 Fortify::authenticateUsing。
我在文件 routes/web.php 中没有任何登录定义我在输出中看不到原因
php artisan route:list
命令我看到行:
| | POST | login | generated::spwtVnYkPvigASwV | Laravel\Fortify\Http\Controllers\AuthenticatedSessionController@store | web |
| | | | | | App\Http\Middleware\RedirectIfAuthenticated:web |
| | | | | | Illuminate\Routing\Middleware\ThrottleRequests:login |
上面的引用正确吗?
似乎我不必手动编辑 app/Http/Kernel.php ?
最初那是基于 Admin 模板的 laravel Starter Kit,没有进行强化,它可以作为该套件的参考吗?在哪里可以检查?
谢谢!