2023-03-17 15:33:48 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Http\Controllers;
|
|
|
|
|
2023-06-07 15:08:35 +02:00
|
|
|
use App\Models\InstanceSettings;
|
|
|
|
use App\Models\Project;
|
2023-08-08 11:51:36 +02:00
|
|
|
use App\Models\S3Storage;
|
2023-08-11 16:13:53 +02:00
|
|
|
use App\Models\StandalonePostgresql;
|
2023-06-12 12:00:01 +02:00
|
|
|
use App\Models\TeamInvitation;
|
|
|
|
use App\Models\User;
|
2023-09-06 12:07:34 +02:00
|
|
|
use Auth;
|
2023-03-17 15:33:48 +01:00
|
|
|
use Illuminate\Foundation\Auth\Access\AuthorizesRequests;
|
|
|
|
use Illuminate\Foundation\Validation\ValidatesRequests;
|
|
|
|
use Illuminate\Routing\Controller as BaseController;
|
2023-09-06 12:07:34 +02:00
|
|
|
use Illuminate\Support\Facades\Crypt;
|
|
|
|
use Illuminate\Support\Facades\Hash;
|
|
|
|
use Illuminate\Support\Facades\Http;
|
2023-08-08 17:28:36 +02:00
|
|
|
use Throwable;
|
2023-09-06 12:07:34 +02:00
|
|
|
use Str;
|
|
|
|
|
2023-03-17 15:33:48 +01:00
|
|
|
|
|
|
|
class Controller extends BaseController
|
|
|
|
{
|
|
|
|
use AuthorizesRequests, ValidatesRequests;
|
2023-06-07 15:08:35 +02:00
|
|
|
|
2023-09-06 12:07:34 +02:00
|
|
|
public function link()
|
|
|
|
{
|
|
|
|
$token = request()->get('token');
|
|
|
|
if ($token) {
|
|
|
|
$decrypted = Crypt::decryptString($token);
|
|
|
|
$email = Str::of($decrypted)->before('@@@');
|
|
|
|
$password = Str::of($decrypted)->after('@@@');
|
|
|
|
$user = User::whereEmail($email)->first();
|
|
|
|
if (!$user) {
|
|
|
|
return redirect()->route('login');
|
|
|
|
}
|
|
|
|
if (Hash::check($password, $user->password)) {
|
|
|
|
Auth::login($user);
|
|
|
|
$team = $user->teams()->first();
|
|
|
|
session(['currentTeam' => $team]);
|
|
|
|
return redirect()->route('dashboard');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return redirect()->route('login')->with('error', 'Invalid credentials.');
|
|
|
|
}
|
2023-07-14 11:27:08 +02:00
|
|
|
public function subscription()
|
2023-06-22 14:48:47 +02:00
|
|
|
{
|
2023-08-31 09:56:37 +02:00
|
|
|
if (!isCloud()) {
|
2023-07-14 12:09:56 +02:00
|
|
|
abort(404);
|
|
|
|
}
|
2023-08-30 16:01:38 +02:00
|
|
|
return view('subscription.index', [
|
2023-08-11 20:48:52 +02:00
|
|
|
'settings' => InstanceSettings::get(),
|
2023-07-14 11:27:08 +02:00
|
|
|
]);
|
2023-06-22 14:48:47 +02:00
|
|
|
}
|
2023-08-08 11:51:36 +02:00
|
|
|
|
2023-07-14 12:09:56 +02:00
|
|
|
public function license()
|
|
|
|
{
|
2023-08-31 09:56:37 +02:00
|
|
|
if (!isCloud()) {
|
2023-07-14 12:09:56 +02:00
|
|
|
abort(404);
|
|
|
|
}
|
|
|
|
return view('settings.license', [
|
2023-08-11 20:48:52 +02:00
|
|
|
'settings' => InstanceSettings::get(),
|
2023-07-14 12:09:56 +02:00
|
|
|
]);
|
|
|
|
}
|
2023-08-08 11:51:36 +02:00
|
|
|
|
2023-09-06 12:07:34 +02:00
|
|
|
public function force_passoword_reset()
|
|
|
|
{
|
2023-08-15 14:11:38 +02:00
|
|
|
return view('auth.force-password-reset');
|
|
|
|
}
|
2023-09-06 12:07:34 +02:00
|
|
|
public function boarding()
|
|
|
|
{
|
2023-08-27 15:23:47 +02:00
|
|
|
if (currentTeam()->boarding || isDev()) {
|
2023-08-22 17:44:49 +02:00
|
|
|
return view('boarding');
|
|
|
|
} else {
|
|
|
|
return redirect()->route('dashboard');
|
|
|
|
}
|
|
|
|
}
|
2023-08-08 11:51:36 +02:00
|
|
|
|
2023-06-07 15:08:35 +02:00
|
|
|
public function settings()
|
|
|
|
{
|
2023-08-22 17:44:49 +02:00
|
|
|
if (isInstanceAdmin()) {
|
2023-06-07 15:08:35 +02:00
|
|
|
$settings = InstanceSettings::get();
|
2023-08-11 16:13:53 +02:00
|
|
|
$database = StandalonePostgresql::whereName('coolify-db')->first();
|
|
|
|
if ($database) {
|
|
|
|
$s3s = S3Storage::whereTeamId(0)->get();
|
|
|
|
}
|
2023-06-07 22:07:26 +02:00
|
|
|
return view('settings.configuration', [
|
2023-08-11 16:13:53 +02:00
|
|
|
'settings' => $settings,
|
|
|
|
'database' => $database,
|
|
|
|
's3s' => $s3s ?? [],
|
2023-06-07 15:08:35 +02:00
|
|
|
]);
|
|
|
|
} else {
|
|
|
|
return redirect()->route('dashboard');
|
|
|
|
}
|
|
|
|
}
|
2023-08-08 11:51:36 +02:00
|
|
|
|
2023-06-09 15:55:21 +02:00
|
|
|
public function team()
|
|
|
|
{
|
|
|
|
$invitations = [];
|
2023-07-13 22:03:27 +02:00
|
|
|
if (auth()->user()->isAdminFromSession()) {
|
2023-08-22 17:44:49 +02:00
|
|
|
$invitations = TeamInvitation::whereTeamId(currentTeam()->id)->get();
|
2023-06-09 15:55:21 +02:00
|
|
|
}
|
2023-08-30 16:01:38 +02:00
|
|
|
return view('team.index', [
|
2023-06-09 15:55:21 +02:00
|
|
|
'invitations' => $invitations,
|
|
|
|
]);
|
|
|
|
}
|
2023-08-08 11:51:36 +02:00
|
|
|
|
|
|
|
public function storages()
|
|
|
|
{
|
2023-08-07 15:31:42 +02:00
|
|
|
$s3 = S3Storage::ownedByCurrentTeam()->get();
|
|
|
|
return view('team.storages.all', [
|
|
|
|
's3' => $s3,
|
|
|
|
]);
|
|
|
|
}
|
2023-08-08 11:51:36 +02:00
|
|
|
|
|
|
|
public function storages_show()
|
|
|
|
{
|
2023-08-07 15:31:42 +02:00
|
|
|
$storage = S3Storage::ownedByCurrentTeam()->whereUuid(request()->storage_uuid)->firstOrFail();
|
|
|
|
return view('team.storages.show', [
|
|
|
|
'storage' => $storage,
|
|
|
|
]);
|
|
|
|
}
|
2023-08-08 11:51:36 +02:00
|
|
|
|
2023-07-13 22:03:27 +02:00
|
|
|
public function members()
|
|
|
|
{
|
|
|
|
$invitations = [];
|
|
|
|
if (auth()->user()->isAdminFromSession()) {
|
2023-08-22 17:44:49 +02:00
|
|
|
$invitations = TeamInvitation::whereTeamId(currentTeam()->id)->get();
|
2023-07-13 22:03:27 +02:00
|
|
|
}
|
|
|
|
return view('team.members', [
|
|
|
|
'invitations' => $invitations,
|
|
|
|
]);
|
|
|
|
}
|
2023-08-08 11:51:36 +02:00
|
|
|
|
2023-06-15 09:15:41 +02:00
|
|
|
public function acceptInvitation()
|
2023-06-12 12:00:01 +02:00
|
|
|
{
|
|
|
|
try {
|
|
|
|
$invitation = TeamInvitation::whereUuid(request()->route('uuid'))->firstOrFail();
|
|
|
|
$user = User::whereEmail($invitation->email)->firstOrFail();
|
|
|
|
if (is_null(auth()->user())) {
|
|
|
|
return redirect()->route('login');
|
|
|
|
}
|
|
|
|
if (auth()->user()->id !== $user->id) {
|
|
|
|
abort(401);
|
|
|
|
}
|
|
|
|
|
2023-06-15 09:15:41 +02:00
|
|
|
$createdAt = $invitation->created_at;
|
|
|
|
$diff = $createdAt->diffInMinutes(now());
|
2023-06-12 12:00:01 +02:00
|
|
|
if ($diff <= config('constants.invitation.link.expiration')) {
|
|
|
|
$user->teams()->attach($invitation->team->id, ['role' => $invitation->role]);
|
|
|
|
$invitation->delete();
|
2023-08-30 16:01:38 +02:00
|
|
|
return redirect()->route('team.index');
|
2023-06-12 12:00:01 +02:00
|
|
|
} else {
|
|
|
|
$invitation->delete();
|
|
|
|
abort(401);
|
|
|
|
}
|
2023-09-11 17:36:30 +02:00
|
|
|
} catch (Throwable $e) {
|
|
|
|
throw $e;
|
2023-06-12 12:00:01 +02:00
|
|
|
}
|
|
|
|
}
|
2023-08-08 11:51:36 +02:00
|
|
|
|
2023-06-15 09:15:41 +02:00
|
|
|
public function revokeInvitation()
|
2023-06-12 12:00:01 +02:00
|
|
|
{
|
|
|
|
try {
|
|
|
|
$invitation = TeamInvitation::whereUuid(request()->route('uuid'))->firstOrFail();
|
|
|
|
$user = User::whereEmail($invitation->email)->firstOrFail();
|
|
|
|
if (is_null(auth()->user())) {
|
|
|
|
return redirect()->route('login');
|
|
|
|
}
|
|
|
|
if (auth()->user()->id !== $user->id) {
|
|
|
|
abort(401);
|
|
|
|
}
|
|
|
|
$invitation->delete();
|
2023-08-30 16:01:38 +02:00
|
|
|
return redirect()->route('team.index');
|
2023-09-11 17:36:30 +02:00
|
|
|
} catch (Throwable $e) {
|
|
|
|
throw $e;
|
2023-06-12 12:00:01 +02:00
|
|
|
}
|
|
|
|
}
|
2023-08-08 11:51:36 +02:00
|
|
|
}
|