1 回答

TA貢獻1909條經驗 獲得超7個贊
您想要做的是實現您自己的用戶提供程序,以使用外部 POP3 電子郵件系統驗證您的用戶憑據。
我不認為您需要自定義您的 Guard,因為我假設您仍然希望StatefulGuard
默認的SessionGuard
Guard 會檢查并存儲有關會話中身份驗證狀態的信息。
我認為除了如何驗證所提供的憑據之外,您可能還需要所有其他默認行為。
也許./app/Providers/
您可以在文件夾中創建:
PopThreeUserProvider.php
namespace App\Providers;
use Illuminate\Auth\EloquentUserProvider;
use Illuminate\Contracts\Auth\Authenticatable as UserContract;
class PopThreeUserProvider extends EloquentUserProvider
{
? ? /**
? ? ?* Validate a user against the given credentials.
? ? ?*
? ? ?* @param? \Illuminate\Contracts\Auth\Authenticatable? $user
? ? ?* @param? array? $credentials
? ? ?* @return bool
? ? ?*/
? ? public function validateCredentials(UserContract $user, array $credentials)
? ? {
? ? ? ? // Implement your pop3 authentication here, I have left the default code
? ? ? ? // for the Eloquent provider below
? ? ? ? $plain = $credentials['password'];
? ? ? ? return $this->hasher->check($plain, $user->getAuthPassword());
? ? }
}
現在在你的./app/Providers/AuthServiceProvider.php
class AuthServiceProvider extends ServiceProvider
{
? ? ...
? ? /**
? ? ?* Register any application authentication / authorization services.
? ? ?*
? ? ?* @return void
? ? ?*/
? ? public function boot()
? ? {
? ? ? ? ...
? ? ? ? Auth::provider('pop3', function ($app, array $config) {
? ? ? ? ? ? return new PopThreeUserProvider($app->make('hash'), $config['model']);
? ? ? ? });
? ? ? ? ...
? ? }
? ? ...
}
現在在你的config/auth.php:
? ? ...
? ? 'providers' => [
? ? ? ? 'users' => [
? ? ? ? ? ? 'driver' => 'pop3',
? ? ? ? ],
? ? ],
? ? ...
當然,這一切都假設您擁有:
class User extends Authenticatable
{
? ? protected $table = 'sys_users';
? ? protected $primaryKey = 'user_acc';
? ? protected $incrementing = false;
? ? ...
- 1 回答
- 0 關注
- 140 瀏覽
添加回答
舉報