1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Pratiksh\Adminetic\Http\Controllers\Admin; |
4
|
|
|
|
5
|
|
|
use App\Http\Controllers\Controller; |
|
|
|
|
6
|
|
|
use App\Models\User; |
|
|
|
|
7
|
|
|
use Illuminate\Support\Facades\Auth; |
8
|
|
|
use Illuminate\Support\Facades\Hash; |
9
|
|
|
use Illuminate\Support\Str; |
10
|
|
|
use Laravel\Socialite\Facades\Socialite; |
11
|
|
|
use Pratiksh\Adminetic\Models\Admin\Preference; |
12
|
|
|
use Pratiksh\Adminetic\Models\Admin\Role; |
13
|
|
|
|
14
|
|
|
class SocialiteController extends Controller |
15
|
|
|
{ |
16
|
|
|
public function github() |
17
|
|
|
{ |
18
|
|
|
return Socialite::driver('github')->stateless()->redirect(); |
|
|
|
|
19
|
|
|
} |
20
|
|
|
|
21
|
|
|
public function githubRedirect() |
22
|
|
|
{ |
23
|
|
|
return $this->redirectSocialite('github'); |
24
|
|
|
} |
25
|
|
|
|
26
|
|
|
public function facebook() |
27
|
|
|
{ |
28
|
|
|
return Socialite::driver('facebook')->stateless()->redirect(); |
29
|
|
|
} |
30
|
|
|
|
31
|
|
|
public function facebookRedirect() |
32
|
|
|
{ |
33
|
|
|
return $this->redirectSocialite('facebook'); |
34
|
|
|
} |
35
|
|
|
|
36
|
|
|
public function google() |
37
|
|
|
{ |
38
|
|
|
return Socialite::driver('google')->stateless()->redirect(); |
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
public function googleRedirect() |
42
|
|
|
{ |
43
|
|
|
return $this->redirectSocialite('google'); |
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
private function redirectSocialite($driver) |
47
|
|
|
{ |
48
|
|
|
$socialiteuser = Socialite::driver($driver)->stateless()->user(); |
49
|
|
|
|
50
|
|
|
$user = User::where('email', $socialiteuser->email)->first(); |
51
|
|
|
|
52
|
|
|
if (! isset($user)) { |
53
|
|
|
$user = User::create([ |
54
|
|
|
'name' => $socialiteuser->name, |
55
|
|
|
'email' => $socialiteuser->email, |
56
|
|
|
'password' => Hash::make(Str::random(24)), |
57
|
|
|
]); |
58
|
|
|
// Assigning Default Role to New User |
59
|
|
|
$default_user_role = config('adminetic.default_user_role', 'user'); |
60
|
|
|
$default_user_role_level = config('adminetic.default_user_role_level', 1); |
61
|
|
|
$role = Role::where('name', $default_user_role)->first(); |
62
|
|
|
if ($role) { |
63
|
|
|
$user->roles()->attach($role); |
64
|
|
|
} else { |
65
|
|
|
Role::create([ |
66
|
|
|
'name' => $default_user_role, |
67
|
|
|
'description' => 'Default role for newly registered user.', |
68
|
|
|
'level' => $default_user_role_level, |
69
|
|
|
]); |
70
|
|
|
} |
71
|
|
|
// Creating Profile |
72
|
|
|
$user->profile()->create([ |
73
|
|
|
'username' => $socialiteuser->user->nickname ?? 'N/A', |
74
|
|
|
'address' => $socialiteuser->location ?? 'N/A', |
75
|
|
|
'profile_pic' => $socialiteuser->getAvatar(), |
76
|
|
|
]); |
77
|
|
|
|
78
|
|
|
// Creating Preference |
79
|
|
|
$preferences = Preference::all(); |
80
|
|
|
if (isset($preferences)) { |
81
|
|
|
foreach ($preferences as $preference) { |
82
|
|
|
if (! isset($preference->roles)) { |
83
|
|
|
$user->preferences()->attach($preference->id, [ |
84
|
|
|
'enabled' => $preference->active, |
85
|
|
|
]); |
86
|
|
|
} else { |
87
|
|
|
if (array_intersect($user->roles->pluck('id')->toArray(), $preference->roles) != null) { |
88
|
|
|
$user->preferences()->attach($preference->id, [ |
89
|
|
|
'enabled' => $preference->active, |
90
|
|
|
]); |
91
|
|
|
} |
92
|
|
|
} |
93
|
|
|
} |
94
|
|
|
} |
95
|
|
|
Auth::login($user, true); |
96
|
|
|
|
97
|
|
|
return redirect(adminRedirectRoute(config('adminetic.oauth_redirect_route_name', 'dashboard'))); |
98
|
|
|
} else { |
99
|
|
|
Auth::login($user, true); |
100
|
|
|
|
101
|
|
|
return redirect(adminRedirectRoute(config('adminetic.oauth_redirect_route_name', 'dashboard'))); |
102
|
|
|
} |
103
|
|
|
} |
104
|
|
|
} |
105
|
|
|
|
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"]
, you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths