2015-12-13 04:42:28 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Providers;
|
|
|
|
|
2015-12-14 16:27:26 +00:00
|
|
|
use App\Models\User;
|
2020-09-07 20:43:23 +00:00
|
|
|
use App\Services\TokenManager;
|
2024-02-25 19:32:53 +00:00
|
|
|
use Illuminate\Auth\Notifications\ResetPassword;
|
2015-12-13 04:42:28 +00:00
|
|
|
use Illuminate\Foundation\Support\Providers\AuthServiceProvider as ServiceProvider;
|
2020-09-07 20:43:23 +00:00
|
|
|
use Illuminate\Http\Request;
|
|
|
|
use Illuminate\Support\Facades\Auth;
|
2021-05-21 17:14:00 +00:00
|
|
|
use Illuminate\Validation\Rules\Password;
|
2015-12-13 04:42:28 +00:00
|
|
|
|
|
|
|
class AuthServiceProvider extends ServiceProvider
|
|
|
|
{
|
2020-12-22 20:11:22 +00:00
|
|
|
public function boot(): void
|
2015-12-13 04:42:28 +00:00
|
|
|
{
|
2016-09-26 06:30:00 +00:00
|
|
|
$this->registerPolicies();
|
2020-09-07 20:43:23 +00:00
|
|
|
|
|
|
|
Auth::viaRequest('token-via-query-parameter', static function (Request $request): ?User {
|
2022-11-16 17:57:38 +00:00
|
|
|
$token = $request->get('api_token') ?: $request->get('t');
|
|
|
|
|
2024-04-24 21:58:19 +00:00
|
|
|
return app(TokenManager::class)->getUserFromPlainTextToken($token ?: '');
|
2020-09-07 20:43:23 +00:00
|
|
|
});
|
2021-05-21 17:14:00 +00:00
|
|
|
|
|
|
|
$this->setPasswordDefaultRules();
|
2024-02-25 19:32:53 +00:00
|
|
|
|
|
|
|
ResetPassword::createUrlUsing(static function (User $user, string $token): string {
|
|
|
|
$payload = base64_encode($user->getEmailForPasswordReset() . "|$token");
|
|
|
|
|
|
|
|
return url("/#/reset-password/$payload");
|
|
|
|
});
|
2021-05-21 17:14:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
private function setPasswordDefaultRules(): void
|
|
|
|
{
|
2021-06-05 10:47:56 +00:00
|
|
|
Password::defaults(fn (): Password => $this->app->isProduction()
|
|
|
|
? Password::min(10)->letters()->numbers()->symbols()->uncompromised()
|
|
|
|
: Password::min(6));
|
2015-12-13 04:42:28 +00:00
|
|
|
}
|
|
|
|
}
|