Updated Google Scholar Integration,Updated Admin and HOD Dashboard, Added Google Auth: Login Controller and Routes
This commit is contained in:
@@ -15,7 +15,9 @@ class GoogleController extends Controller
|
||||
*/
|
||||
public function redirectToGoogle()
|
||||
{
|
||||
return Socialite::driver('google')->redirect();
|
||||
// Prefer to hint Google to show accounts from the somaiya.edu domain.
|
||||
// This is only a UI hint — always validate the domain on the callback.
|
||||
return Socialite::driver('google')->with(['hd' => 'somaiya.edu'])->redirect();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -26,10 +28,20 @@ class GoogleController extends Controller
|
||||
try {
|
||||
$googleUser = Socialite::driver('google')->user();
|
||||
|
||||
// Validate that the user belongs to the somaiya.edu domain.
|
||||
// Google may return a 'hd' (hosted domain) claim; fall back to parsing the email.
|
||||
$email = $googleUser->getEmail();
|
||||
$hostedDomain = data_get($googleUser->user, 'hd');
|
||||
$domain = $hostedDomain ?: (strpos($email, '@') !== false ? substr(strrchr($email, "@"), 1) : null);
|
||||
|
||||
if ($domain !== 'somaiya.edu') {
|
||||
return redirect()->route('login')->withErrors(['error' => 'Please sign in using a somaiya.edu account.']);
|
||||
}
|
||||
|
||||
$user = User::firstOrCreate(
|
||||
['email' => $googleUser->getEmail()],
|
||||
['email' => $email],
|
||||
[
|
||||
'name' => $googleUser->getName(),
|
||||
'name' => $googleUser->getName() ?: $email,
|
||||
'password' => bcrypt(Str::random(16)), // Generate a random password
|
||||
]
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user