我有两个环境:
users
表只有两列,id
和external_user_id
。 id
由 A 创建,external_user_id
由 B 创建。
如果我实施自定义提供程序,我需要遵循两个合同:
<?php
interface UserProvider
{
public function retrieveById($identifier);
public function retrieveByToken($identifier, $token);
public function updateRememberToken(Authenticatable $user, $token);
public function retrieveByCredentials(array $credentials);
public function validateCredentials(Authenticatable $user, array $credentials);
}
interface Authenticatable
{
public function getAuthIdentifierName();
public function getAuthIdentifier();
public function getAuthPassword();
public function getRememberToken();
public function setRememberToken($value);
public function getRememberTokenName();
}
但是,有一个非常棘手的问题:如何在验证用户之前调用retrieveByCredentials()
?
答案 0 :(得分:0)
BadMethodCallException
Auth::attempt()
Auth::login()
<?php
class MyUserProvider extends Provider implements UserProvider
{
public function retrieveById($identifier)
{
throw new \BadMethodCallException();
}
public function retrieveByToken($identifier, $token)
{
throw new \BadMethodCallException();
}
public function updateRememberToken(Authenticatable $user, $token)
{
throw new \BadMethodCallException();
}
public function retrieveByCredentials(array $credentials)
{
throw new \BadMethodCallException();
}
public function validateCredentials(Authenticatable $user, array $credentials)
{
throw new \BadMethodCallException();
}
}
class User extends Model implements Authenticatable
{
public function getAuthIdentifierName()
{
throw new \BadMethodCallException();
}
public function getAuthIdentifier()
{
throw new \BadMethodCallException();
}
public function getAuthPassword()
{
throw new \BadMethodCallException();
}
public function getRememberToken()
{
throw new \BadMethodCallException();
}
public function setRememberToken($value)
{
throw new \BadMethodCallException();
}
public function getRememberTokenName()
{
throw new \BadMethodCallException();
}
}