Skip to content

Commit

Permalink
Добавлены новые проверки для FunctionTrait GuardTrait
Browse files Browse the repository at this point in the history
  • Loading branch information
Sashagm committed Jun 21, 2023
1 parent b5e773d commit 810f728
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 2 deletions.
5 changes: 4 additions & 1 deletion src/Http/Controllers/LoginController.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,16 @@ class LoginController extends Controller

public function redirectToProvider($provider)
{
$this->checkGateProvider($provider);

return Socialite::driver($provider)->redirect();
}


public function handleProviderCallback($provider)
{

$this->checkGateProvider($provider);

$socialUser = Socialite::driver($provider)->user();

$user = User::where(config('socials.user.email_colum'), $socialUser->getEmail())->first();
Expand Down
19 changes: 19 additions & 0 deletions src/Traits/FunctionTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,22 @@ private function feedback($method)
}

foreach ($feedback as $item) {
if (!isset($item['class']) || !isset($item['method'])) {
throw new Exception("Social auth configuration error: class or method not set!");
}

$class = $item['class'];
$method = $item['method'];
$params = $item['params'];

if (!class_exists($class)) {
throw new Exception("Class {$class} not found.");
}

if (!method_exists($class, $method)) {
throw new Exception("Method {$method} not found in class {$class}.");
}

call_user_func_array([$class, $method], $params);
}
}
Expand Down Expand Up @@ -63,6 +76,10 @@ private function cast_fields($socialUser, $provider)

private function updateUser($user, $socialUser) {

if (!config('socials.user.auto_update')) {
throw new Exception("Social auth configuration error: auto_update not set!");
}

if(config('socials.user.auto_update')) {

$update = config('socials.user.update_colum');
Expand All @@ -81,5 +98,7 @@ private function updateUser($user, $socialUser) {
}
}




}
10 changes: 10 additions & 0 deletions src/Traits/GuardTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace Sashagm\Social\Traits;


use Exception;
use App\Models\User;
use Illuminate\Database\Eloquent\Relations\MorphToMany;

Expand Down Expand Up @@ -70,5 +71,14 @@ private function checkProvider($user, $provider)
}
}

private function checkGateProvider($provider)
{
$allowedProviders = config('socials.providers');

if (!in_array($provider, $allowedProviders)) {
throw new Exception('Invalid social provider.');
}
}


}
8 changes: 7 additions & 1 deletion src/config/socials.php
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,13 @@
],
*/
],
],

'providers' => [



],


];

0 comments on commit 810f728

Please sign in to comment.