@@ -8,32 +8,29 @@ use Illuminate\Support\Facades\Http;
|
||||
use Illuminate\Support\ServiceProvider;
|
||||
use Illuminate\Validation\Rules\Password;
|
||||
use Laravel\Sanctum\Sanctum;
|
||||
use Laravel\Telescope\TelescopeServiceProvider;
|
||||
use SocialiteProviders\Authentik\Provider;
|
||||
use SocialiteProviders\Manager\SocialiteWasCalled;
|
||||
|
||||
class AppServiceProvider extends ServiceProvider
|
||||
{
|
||||
public function register(): void
|
||||
{
|
||||
if ($this->app->environment('local')) {
|
||||
$this->app->register(TelescopeServiceProvider::class);
|
||||
$this->app->register(\Laravel\Telescope\TelescopeServiceProvider::class);
|
||||
}
|
||||
}
|
||||
|
||||
public function boot(): void
|
||||
{
|
||||
Event::listen(function (SocialiteWasCalled $socialiteWasCalled) {
|
||||
$socialiteWasCalled->extendSocialite('authentik', Provider::class);
|
||||
Event::listen(function (\SocialiteProviders\Manager\SocialiteWasCalled $event) {
|
||||
$event->extendSocialite('authentik', \SocialiteProviders\Authentik\Provider::class);
|
||||
});
|
||||
Sanctum::usePersonalAccessTokenModel(PersonalAccessToken::class);
|
||||
|
||||
Password::defaults(function () {
|
||||
$password = Password::min(8);
|
||||
$rule = Password::min(8);
|
||||
|
||||
return $this->app->isProduction()
|
||||
? $password->mixedCase()->letters()->numbers()->symbols()
|
||||
: $password;
|
||||
? $rule->mixedCase()->letters()->numbers()->symbols()
|
||||
: $rule;
|
||||
});
|
||||
|
||||
Http::macro('github', function (string $api_url, ?string $github_access_token = null) {
|
||||
@@ -43,11 +40,11 @@ class AppServiceProvider extends ServiceProvider
|
||||
'Accept' => 'application/vnd.github.v3+json',
|
||||
'Authorization' => "Bearer $github_access_token",
|
||||
])->baseUrl($api_url);
|
||||
} else {
|
||||
return Http::withHeaders([
|
||||
'Accept' => 'application/vnd.github.v3+json',
|
||||
])->baseUrl($api_url);
|
||||
}
|
||||
|
||||
return Http::withHeaders([
|
||||
'Accept' => 'application/vnd.github.v3+json',
|
||||
])->baseUrl($api_url);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,7 +3,6 @@
|
||||
namespace App\Providers;
|
||||
|
||||
use Illuminate\Support\ServiceProvider;
|
||||
use Laravel\Dusk\Browser;
|
||||
|
||||
class DuskServiceProvider extends ServiceProvider
|
||||
{
|
||||
@@ -12,7 +11,7 @@ class DuskServiceProvider extends ServiceProvider
|
||||
*/
|
||||
public function boot(): void
|
||||
{
|
||||
Browser::macro('loginWithRootUser', function () {
|
||||
\Laravel\Dusk\Browser::macro('loginWithRootUser', function () {
|
||||
return $this->visit('/login')
|
||||
->type('email', 'test@example.com')
|
||||
->type('password', 'password')
|
||||
|
||||
@@ -8,7 +8,6 @@ use App\Actions\Fortify\UpdateUserPassword;
|
||||
use App\Actions\Fortify\UpdateUserProfileInformation;
|
||||
use App\Models\OauthSetting;
|
||||
use App\Models\User;
|
||||
use Illuminate\Auth\Events\Login;
|
||||
use Illuminate\Cache\RateLimiting\Limit;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Hash;
|
||||
@@ -45,7 +44,7 @@ class FortifyServiceProvider extends ServiceProvider
|
||||
{
|
||||
Fortify::createUsersUsing(CreateNewUser::class);
|
||||
Fortify::registerView(function () {
|
||||
$isFirstUser = User::query()->count() === 0;
|
||||
$isFirstUser = User::count() === 0;
|
||||
|
||||
$settings = instanceSettings();
|
||||
if (! $settings->is_registration_enabled) {
|
||||
@@ -59,14 +58,14 @@ class FortifyServiceProvider extends ServiceProvider
|
||||
|
||||
Fortify::loginView(function () {
|
||||
$settings = instanceSettings();
|
||||
$enabled_oauth_providers = OauthSetting::query()->where('enabled', true)->get();
|
||||
$users = User::query()->count();
|
||||
$enabled_oauth_providers = OauthSetting::where('enabled', true)->get();
|
||||
$users = User::count();
|
||||
if ($users == 0) {
|
||||
// If there are no users, redirect to registration
|
||||
return redirect()->route('register');
|
||||
}
|
||||
|
||||
return view(Login::class, [
|
||||
return view('auth.login', [
|
||||
'is_registration_enabled' => $settings->is_registration_enabled,
|
||||
'enabled_oauth_providers' => $enabled_oauth_providers,
|
||||
]);
|
||||
@@ -74,7 +73,7 @@ class FortifyServiceProvider extends ServiceProvider
|
||||
|
||||
Fortify::authenticateUsing(function (Request $request) {
|
||||
$email = strtolower($request->email);
|
||||
$user = User::query()->where('email', $email)->with('teams')->first();
|
||||
$user = User::where('email', $email)->with('teams')->first();
|
||||
if (
|
||||
$user &&
|
||||
Hash::check($request->password, $user->password)
|
||||
|
||||
@@ -31,9 +31,11 @@ class HorizonServiceProvider extends HorizonApplicationServiceProvider
|
||||
protected function gate(): void
|
||||
{
|
||||
Gate::define('viewHorizon', function ($user) {
|
||||
$root_user = User::query()->find(0);
|
||||
$root_user = User::find(0);
|
||||
|
||||
return $user->email == $root_user->email;
|
||||
return in_array($user->email, [
|
||||
$root_user->email,
|
||||
]);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -21,24 +21,13 @@ class TelescopeServiceProvider extends TelescopeApplicationServiceProvider
|
||||
|
||||
$isLocal = $this->app->environment('local');
|
||||
|
||||
Telescope::filter(function (IncomingEntry $incomingEntry) use ($isLocal) {
|
||||
if ($isLocal) {
|
||||
return true;
|
||||
}
|
||||
if ($incomingEntry->isReportableException()) {
|
||||
return true;
|
||||
}
|
||||
if ($incomingEntry->isFailedRequest()) {
|
||||
return true;
|
||||
}
|
||||
if ($incomingEntry->isFailedJob()) {
|
||||
return true;
|
||||
}
|
||||
if ($incomingEntry->isScheduledTask()) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return $incomingEntry->hasMonitoredTag();
|
||||
Telescope::filter(function (IncomingEntry $entry) use ($isLocal) {
|
||||
return $isLocal ||
|
||||
$entry->isReportableException() ||
|
||||
$entry->isFailedRequest() ||
|
||||
$entry->isFailedJob() ||
|
||||
$entry->isScheduledTask() ||
|
||||
$entry->hasMonitoredTag();
|
||||
});
|
||||
}
|
||||
|
||||
@@ -68,9 +57,11 @@ class TelescopeServiceProvider extends TelescopeApplicationServiceProvider
|
||||
protected function gate(): void
|
||||
{
|
||||
Gate::define('viewTelescope', function ($user) {
|
||||
$root_user = User::query()->find(0);
|
||||
$root_user = User::find(0);
|
||||
|
||||
return $user->email == $root_user->email;
|
||||
return in_array($user->email, [
|
||||
$root_user->email,
|
||||
]);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user