-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add option to link services to user account
- Loading branch information
1 parent
6b8b01d
commit a2cd9dd
Showing
12 changed files
with
172 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
<?php | ||
|
||
namespace App\Http\Controllers; | ||
|
||
use App\Models\Service; | ||
use App\Models\User; | ||
use App\View\Components\Notification; | ||
use Illuminate\Database\Eloquent\Builder; | ||
use Illuminate\Http\RedirectResponse; | ||
use Illuminate\Http\Request; | ||
use Illuminate\Support\Facades\Auth; | ||
use Illuminate\Support\Facades\Lang; | ||
|
||
class ServiceController extends Controller | ||
{ | ||
/** | ||
* Link service to user account. | ||
*/ | ||
public function link(Request $request): RedirectResponse | ||
{ | ||
$request->validate([ | ||
'serviceId' => 'required', | ||
]); | ||
|
||
/** @var User $user */ | ||
$user = Auth::user(); | ||
$service = Service::enabled() | ||
->where('id', '=', $request->serviceId) | ||
->when(!$user?->is_admin, fn (Builder $query) => $query->where('is_public', '=', true)) | ||
->first(); | ||
|
||
if ($user === null || $service === null) { | ||
Notification::push( | ||
Lang::get('notifications.in-app.service-link-failed.title'), | ||
Lang::get('notifications.in-app.service-link-failed.description'), | ||
Notification::DANGER, | ||
); | ||
|
||
return redirect()->back(); | ||
} | ||
|
||
$redirectLink = match ($service->name) { | ||
'EverestCloud' => $service->link . '/apps/sociallogin/custom_oauth2/everestserver', | ||
'EverestGit' => $service->link . '/-/profile/account', | ||
default => null, | ||
}; | ||
|
||
if ($redirectLink !== null) { | ||
return redirect($redirectLink); | ||
} | ||
|
||
$user->services()->save($service); | ||
|
||
Notification::push( | ||
Lang::get('notifications.in-app.service-linked.title'), | ||
Lang::get('notifications.in-app.service-linked.description', ['service' => $service->name]), | ||
Notification::SUCCESS, | ||
); | ||
|
||
return redirect()->back(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
@props(['modal']) | ||
|
||
<button x-data | ||
class="border-2 border-dashed border-gray-300 cursor-pointer flex gap-2 hover:border-gray-400 hover:text-gray-800 items-center p-4 rounded-lg text-gray-600 transition-colors" | ||
@click="$dispatch('open-modal', '{{ $modal }}')" | ||
> | ||
<i class="fa-solid fa-square-plus text-2xl"></i> | ||
<span class="font-medium text-lg"> | ||
{{ $slot }} | ||
</span> | ||
</button> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters