Subiendo proyecto completo sin restricciones de git ignore
This commit is contained in:
13
vendor/genealabs/laravel-socialiter/src/Facades/Socialiter.php
vendored
Normal file
13
vendor/genealabs/laravel-socialiter/src/Facades/Socialiter.php
vendored
Normal file
@@ -0,0 +1,13 @@
|
||||
<?php
|
||||
|
||||
namespace GeneaLabs\LaravelSocialiter\Facades;
|
||||
|
||||
use Illuminate\Support\Facades\Facade;
|
||||
|
||||
class Socialiter extends Facade
|
||||
{
|
||||
protected static function getFacadeAccessor()
|
||||
{
|
||||
return 'socialiter';
|
||||
}
|
||||
}
|
||||
49
vendor/genealabs/laravel-socialiter/src/Providers/ServiceProvider.php
vendored
Normal file
49
vendor/genealabs/laravel-socialiter/src/Providers/ServiceProvider.php
vendored
Normal file
@@ -0,0 +1,49 @@
|
||||
<?php
|
||||
|
||||
namespace GeneaLabs\LaravelSocialiter\Providers;
|
||||
|
||||
use GeneaLabs\LaravelSocialiter\Socialiter;
|
||||
use Illuminate\Support\ServiceProvider as LaravelServiceProvider;
|
||||
|
||||
class ServiceProvider extends LaravelServiceProvider
|
||||
{
|
||||
protected $defer = false;
|
||||
|
||||
public function boot()
|
||||
{
|
||||
if (Socialiter::$runsMigrations) {
|
||||
$this->loadMigrationsFrom(__DIR__ . "/../../database/migrations");
|
||||
}
|
||||
|
||||
$this->publishes(
|
||||
[
|
||||
__DIR__ . '/../../database/migrations/' => database_path('migrations')
|
||||
],
|
||||
'migrations'
|
||||
);
|
||||
}
|
||||
|
||||
public function register()
|
||||
{
|
||||
// $this->registerConfiguration();
|
||||
$this->registerFacade();
|
||||
}
|
||||
|
||||
protected function registerFacade()
|
||||
{
|
||||
$this->app->bind(
|
||||
'socialiter',
|
||||
function () {
|
||||
return new Socialiter;
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
// protected function registerConfiguration()
|
||||
// {
|
||||
// $this->mergeConfigFrom(
|
||||
// __DIR__ . '/../../config/services.php',
|
||||
// 'services'
|
||||
// );
|
||||
// }
|
||||
}
|
||||
35
vendor/genealabs/laravel-socialiter/src/SocialCredentials.php
vendored
Normal file
35
vendor/genealabs/laravel-socialiter/src/SocialCredentials.php
vendored
Normal file
@@ -0,0 +1,35 @@
|
||||
<?php
|
||||
|
||||
namespace GeneaLabs\LaravelSocialiter;
|
||||
|
||||
use GeneaLabs\LaravelOverridableModel\Traits\Overridable;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
|
||||
class SocialCredentials extends Model
|
||||
{
|
||||
use Overridable;
|
||||
|
||||
protected $dates = [
|
||||
"expires_at",
|
||||
];
|
||||
protected $fillable = [
|
||||
"access_token",
|
||||
"avatar",
|
||||
"email",
|
||||
"expires_at",
|
||||
"name",
|
||||
"nickname",
|
||||
"provider_id",
|
||||
"provider_name",
|
||||
"refresh_token",
|
||||
"user_id",
|
||||
];
|
||||
|
||||
public function user() : BelongsTo
|
||||
{
|
||||
$userClass = config("auth.providers.users.model");
|
||||
|
||||
return $this->belongsTo($userClass);
|
||||
}
|
||||
}
|
||||
132
vendor/genealabs/laravel-socialiter/src/Socialiter.php
vendored
Normal file
132
vendor/genealabs/laravel-socialiter/src/Socialiter.php
vendored
Normal file
@@ -0,0 +1,132 @@
|
||||
<?php
|
||||
|
||||
namespace GeneaLabs\LaravelSocialiter;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Support\Carbon;
|
||||
use Illuminate\Support\Str;
|
||||
use Laravel\Socialite\AbstractUser;
|
||||
use Laravel\Socialite\Facades\Socialite;
|
||||
|
||||
class Socialiter
|
||||
{
|
||||
public static $runsMigrations = true;
|
||||
|
||||
protected $isStateless = false;
|
||||
protected $config;
|
||||
protected $driver;
|
||||
protected $apiToken;
|
||||
|
||||
public static function ignoreMigrations(): void
|
||||
{
|
||||
static::$runsMigrations = false;
|
||||
}
|
||||
|
||||
public function driver(string $driver): self
|
||||
{
|
||||
$this->driver = $driver;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function login(): Model
|
||||
{
|
||||
$socialite = Socialite::driver($this->driver);
|
||||
|
||||
if ($this->config) {
|
||||
$socialite = $socialite
|
||||
->setConfig($this->config);
|
||||
}
|
||||
|
||||
if ($this->isStateless) {
|
||||
$socialite = $socialite->stateless();
|
||||
}
|
||||
|
||||
$socialiteUser = $socialite->user();
|
||||
|
||||
return $this->performLogin($socialiteUser);
|
||||
}
|
||||
|
||||
public function apiLogin(AbstractUser $socialiteUser, string $apiToken): Model
|
||||
{
|
||||
$this->apiToken = $apiToken;
|
||||
|
||||
return $this->performLogin($socialiteUser);
|
||||
}
|
||||
|
||||
protected function performLogin(AbstractUser $socialiteUser): Model
|
||||
{
|
||||
$user = $this
|
||||
->getUser($socialiteUser, $this->driver);
|
||||
$user->load("socialCredentials");
|
||||
|
||||
auth()->login($user);
|
||||
|
||||
return $user;
|
||||
}
|
||||
|
||||
protected function getUser(AbstractUser $socialiteUser): Model
|
||||
{
|
||||
return $this
|
||||
->createCredentials($socialiteUser)
|
||||
->user;
|
||||
}
|
||||
|
||||
protected function createUser(AbstractUser $socialiteUser): Model
|
||||
{
|
||||
$userClass = config("auth.providers.users.model");
|
||||
|
||||
return (new $userClass)
|
||||
->updateOrCreate([
|
||||
"email" => $socialiteUser->getEmail(),
|
||||
], [
|
||||
"name" => $socialiteUser->getName(),
|
||||
"password" => Str::random(64),
|
||||
]);
|
||||
}
|
||||
|
||||
protected function createCredentials(AbstractUser $socialiteUser): SocialCredentials
|
||||
{
|
||||
$credentialsModel = SocialCredentials::model();
|
||||
$socialiteCredentials = (new $credentialsModel)
|
||||
->with("user")
|
||||
->firstOrNew([
|
||||
"provider_id" => $socialiteUser->getId(),
|
||||
"provider_name" => $this->driver,
|
||||
])
|
||||
->fill([
|
||||
"access_token" => $socialiteUser->token,
|
||||
"avatar" => $socialiteUser->getAvatar(),
|
||||
"email" => $socialiteUser->getEmail(),
|
||||
"expires_at" => (new Carbon)->now()->addSeconds($socialiteUser->expiresIn),
|
||||
"name" => $socialiteUser->getName(),
|
||||
"nickname" => $socialiteUser->getNickname(),
|
||||
"provider_id" => $socialiteUser->getId(),
|
||||
"provider_name" => $this->driver,
|
||||
"refresh_token" => $socialiteUser->refreshToken,
|
||||
]);
|
||||
|
||||
if (! $socialiteCredentials->exists) {
|
||||
$user = $this->createUser($socialiteUser);
|
||||
$socialiteCredentials->user()->associate($user);
|
||||
}
|
||||
|
||||
$socialiteCredentials->save();
|
||||
|
||||
return $socialiteCredentials;
|
||||
}
|
||||
|
||||
public function setConfig($config): self
|
||||
{
|
||||
$this->config = $config;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function stateless(): self
|
||||
{
|
||||
$this->isStateless = true;
|
||||
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
14
vendor/genealabs/laravel-socialiter/src/Traits/SocialCredentials.php
vendored
Normal file
14
vendor/genealabs/laravel-socialiter/src/Traits/SocialCredentials.php
vendored
Normal file
@@ -0,0 +1,14 @@
|
||||
<?php
|
||||
|
||||
namespace GeneaLabs\LaravelSocialiter\Traits;
|
||||
|
||||
use GeneaLabs\LaravelSocialiter\SocialCredentials as GeneaLabsSocialCredentials;
|
||||
use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||
|
||||
trait SocialCredentials
|
||||
{
|
||||
public function socialCredentials(): HasMany
|
||||
{
|
||||
return $this->hasMany(GeneaLabsSocialCredentials::class);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user