laravel user provider
This commit is contained in:
parent
37599e8cf6
commit
766c29c5f3
|
@ -0,0 +1,64 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Fufle\Orm\Providers;
|
||||||
|
|
||||||
|
use Fufle\ORM\Model;
|
||||||
|
use Illuminate\Support\Str;
|
||||||
|
use Illuminate\Contracts\Auth\UserProvider;
|
||||||
|
use Illuminate\Contracts\Auth\Authenticatable;
|
||||||
|
|
||||||
|
class PassportUserProvider implements UserProvider {
|
||||||
|
/**
|
||||||
|
* The ORM User Model
|
||||||
|
*/
|
||||||
|
private $model;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create a new ORM user provider.
|
||||||
|
*
|
||||||
|
* @return \Illuminate\Contracts\Auth\Authenticatable|null
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function __construct(Model $userModel) {
|
||||||
|
$this->model = $userModel;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Retrieve a user by the given credentials.
|
||||||
|
*
|
||||||
|
* @param array $credentials
|
||||||
|
* @return \Illuminate\Contracts\Auth\Authenticatable|null
|
||||||
|
*/
|
||||||
|
public function retrieveByCredentials(array $credentials) {
|
||||||
|
if (empty($credentials)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
$user = $this->model->findForPassport($credentials['username']);
|
||||||
|
|
||||||
|
return $user;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Validate a user against the given credentials.
|
||||||
|
*
|
||||||
|
* @param \Illuminate\Contracts\Auth\Authenticatable $user
|
||||||
|
* @param array $credentials Request credentials
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
|
public function validateCredentials(Authenticatable $user, Array $credentials) {
|
||||||
|
return ($credentials['username'] == $user->getAuthIdentifier() &&
|
||||||
|
md5($credentials['password']) == $user->getAuthPassword());
|
||||||
|
}
|
||||||
|
|
||||||
|
public function retrieveById($identifier) {
|
||||||
|
$userClass = get_class($this->model);
|
||||||
|
return $userClass::FindOrFail($identifier);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function retrieveByToken($identifier, $token) {
|
||||||
|
}
|
||||||
|
|
||||||
|
public function updateRememberToken(Authenticatable $user, $token) {
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue