datatable.directory codebase
https://datatable.directory/
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
58 lines
1.5 KiB
58 lines
1.5 KiB
<?php
|
|
namespace AdamWathan\EloquentOAuth;
|
|
|
|
use App\Models\User;
|
|
use Illuminate\Database\Eloquent\Model;
|
|
use SocialNorm\ProviderUser;
|
|
|
|
class EloquentIdentityStore implements IdentityStore
|
|
{
|
|
public function getByProvider(string $provider, ProviderUser $providerUser)
|
|
{
|
|
return OAuthIdentity::where('provider', $provider)
|
|
->where('provider_user_id', $providerUser->id)
|
|
->first();
|
|
}
|
|
|
|
/**
|
|
* Try to retrieve user by their e-mail
|
|
* (!!! this is coupled to the application code !!!)
|
|
*
|
|
* @param ProviderUser $providerUser
|
|
* @return User|Model|null|object
|
|
*/
|
|
public function getByEmail(ProviderUser $providerUser)
|
|
{
|
|
$first = User::where('email', $providerUser->email)->first();
|
|
|
|
if($first->email) return $first;
|
|
return null;
|
|
}
|
|
|
|
public function flush(Model $user, string $provider)
|
|
{
|
|
OAuthIdentity::where('user_id', $user->getKey())
|
|
->where('provider', $provider)
|
|
->delete();
|
|
}
|
|
|
|
public function store(OAuthIdentity $identity)
|
|
{
|
|
$identity->save();
|
|
}
|
|
|
|
public function userExists(string $provider, ProviderUser $providerUser, bool $allowByEmail)
|
|
{
|
|
$byProvider = (bool) $this->getByProvider($provider, $providerUser);
|
|
if ($byProvider) return true;
|
|
|
|
if (!$allowByEmail) return false;
|
|
|
|
if ($providerUser->email) {
|
|
$byEmail = $this->getByEmail($providerUser);
|
|
if ($byEmail) return true;
|
|
}
|
|
|
|
return false;
|
|
}
|
|
}
|
|
|