Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
1 parent
d87383672c
commit
fc4579c47d
8 files changed
+673
-3
No files matched your search
@@ -0,0 +1,34 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\Models\User;
|
||||
use Illuminate\Http\RedirectResponse;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Illuminate\Support\Str;
|
||||
use Laravel\Socialite\Facades\Socialite;
|
||||
|
||||
class OAuthController extends Controller
|
||||
{
|
||||
public function redirect(): RedirectResponse
|
||||
{
|
||||
return Socialite::driver('nextcloud')->redirect();
|
||||
}
|
||||
|
||||
public function callback(): RedirectResponse
|
||||
{
|
||||
$socialUser = Socialite::driver('nextcloud')->user();
|
||||
|
||||
$user = User::firstOrCreate(
|
||||
['email' => $socialUser->getEmail()],
|
||||
[
|
||||
'name' => $socialUser->getName() ?? $socialUser->getNickname() ?? $socialUser->getEmail(),
|
||||
'password' => Str::random(40),
|
||||
]
|
||||
);
|
||||
|
||||
Auth::login($user, remember: true);
|
||||
|
||||
return redirect('/dashboard');
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user