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 关注
- 103 浏览
添加回答
举报