Created
May 10, 2021 05:59
-
-
Save muhajirinlpu/e861789988a9e77a84a1abff6bbb13f9 to your computer and use it in GitHub Desktop.
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
<?php | |
namespace App\Http\Routes; | |
use Jalameta\Router\BaseRoute; | |
use Laravel\Fortify\Features; | |
use Laravel\Fortify\Http\Controllers\AuthenticatedSessionController; | |
use Laravel\Fortify\Http\Controllers\ConfirmablePasswordController; | |
use Laravel\Fortify\Http\Controllers\ConfirmedPasswordStatusController; | |
use Laravel\Fortify\Http\Controllers\EmailVerificationNotificationController; | |
use Laravel\Fortify\Http\Controllers\EmailVerificationPromptController; | |
use Laravel\Fortify\Http\Controllers\NewPasswordController; | |
use Laravel\Fortify\Http\Controllers\PasswordController; | |
use Laravel\Fortify\Http\Controllers\PasswordResetLinkController; | |
use Laravel\Fortify\Http\Controllers\ProfileInformationController; | |
use Laravel\Fortify\Http\Controllers\RecoveryCodeController; | |
use Laravel\Fortify\Http\Controllers\RegisteredUserController; | |
use Laravel\Fortify\Http\Controllers\TwoFactorAuthenticatedSessionController; | |
use Laravel\Fortify\Http\Controllers\TwoFactorAuthenticationController; | |
use Laravel\Fortify\Http\Controllers\TwoFactorQrCodeController; | |
use Laravel\Fortify\Http\Controllers\VerifyEmailController; | |
class FortifyRoute extends BaseRoute | |
{ | |
public function __construct() | |
{ | |
parent::__construct(); | |
$this->domain = config('fortify.domain'); | |
$this->prefix = config('fortify.prefix'); | |
$this->middleware = config('fortify.middleware', ['web']); | |
} | |
/** | |
* Register routes handled by this class. | |
* | |
* @return void | |
*/ | |
public function register() | |
{ | |
$enableViews = config('fortify.views', true); | |
//== AUTHENTICATION | |
if ($enableViews) { | |
$this->router->get($this->prefix('login'), [ | |
'as' => $this->name('login'), | |
'uses' => $this->uses('create', AuthenticatedSessionController::class), | |
'middleware' => ['guest:'.config('fortify.guard')], | |
]); | |
} | |
$limiter = config('fortify.limiters.login'); | |
$this->router->post($this->prefix('login'), [ | |
'uses' => $this->uses('store', AuthenticatedSessionController::class), | |
'middleware' => array_filter([ | |
'guest:' . config('fortify.guard'), | |
$limiter ? 'throttle:' . $limiter : null, | |
]), | |
]); | |
$this->router->post($this->prefix('logout'), [ | |
'as' => $this->name('logout'), | |
'uses' => $this->uses('destroy', AuthenticatedSessionController::class), | |
]); | |
//== PASSWORD RESET | |
if (Features::enabled(Features::resetPasswords())) { | |
if ($enableViews) { | |
$this->router->get($this->prefix('forgot-password'), [ | |
'as' => $this->name('password.request'), | |
'uses' => $this->uses('create', PasswordResetLinkController::class), | |
'middleware' => ['guest:'.config('fortify.guard')], | |
]); | |
$this->router->get($this->prefix('reset-password/{token}'), [ | |
'as' => $this->name('password.reset'), | |
'uses' => $this->uses('create', NewPasswordController::class), | |
'middleware' => ['guest:'.config('fortify.guard')], | |
]); | |
} | |
$this->router->post($this->prefix('forgot-password'), [ | |
'as' => $this->name('password.email'), | |
'uses' => $this->uses('store', PasswordResetLinkController::class), | |
'middleware' => ['guest:'.config('fortify.guard')], | |
]); | |
$this->router->post($this->prefix('reset-password'), [ | |
'as' => $this->name('password.update'), | |
'uses' => $this->uses('store', NewPasswordController::class), | |
'middleware' => ['guest:'.config('fortify.guard')], | |
]); | |
} | |
//== REGISTER | |
if (Features::enabled(Features::registration())) { | |
$this->router->get($this->prefix('register'), [ | |
'as' => $this->name('register'), | |
'uses' => $this->uses('create', RegisteredUserController::class), | |
'middleware' => ['guest:'.config('fortify.guard')], | |
]); | |
$this->router->post($this->prefix('register'), [ | |
'uses' => $this->uses('store', RegisteredUserController::class), | |
'middleware' => ['guest:'.config('fortify.guard')], | |
]); | |
} | |
//== EMAIL VERIFICATION | |
if (Features::enabled(Features::emailVerification())) { | |
if ($enableViews) { | |
$this->router->get($this->prefix('email/verify'), [ | |
'as' => 'verification.notice', | |
'uses' => $this->uses('__invoke', EmailVerificationPromptController::class), | |
'middleware' => ['auth'], | |
]); | |
} | |
$this->router->get($this->prefix('email/verify/{id}/{hash}'), [ | |
'as' => $this->name('verification.verify'), | |
'uses' => $this->uses('__invoke', VerifyEmailController::class), | |
'middleware' => ['auth', 'signed', 'throttle:6,1'], | |
]); | |
$this->router->post($this->prefix('email/verification-notification'), [ | |
'as' => $this->name('verification.send'), | |
'uses' => $this->uses('store', EmailVerificationNotificationController::class), | |
'middleware' => ['auth', 'throttle:6,1'], | |
]); | |
} | |
//== PROFILE INFORMATION | |
if (Features::enabled(Features::updateProfileInformation())) { | |
$this->router->put($this->prefix('user/profile-information'), [ | |
'as' => $this->name('user-profile-information.update'), | |
'uses' => $this->uses('update', ProfileInformationController::class), | |
'middleware' => ['auth'], | |
]); | |
} | |
//== PASSWORD | |
if (Features::enabled(Features::updatePasswords())) { | |
$this->router->put($this->prefix('user/password'), [ | |
'as' => $this->name('user-password.update'), | |
'uses' => $this->uses('update', PasswordController::class), | |
'middleware' => ['auth'], | |
]); | |
} | |
//== PASSWORD CONFIRMATION | |
if ($enableViews) { | |
$this->router->get($this->prefix('user/confirm-password'), [ | |
'as' => $this->name('password.confirm'), | |
'uses' => $this->uses('show', ConfirmablePasswordController::class), | |
'middleware' => ['auth'], | |
]); | |
} | |
$this->router->get($this->prefix('user/confirmed-password-status'), [ | |
'as' => $this->name('password.confirmation'), | |
'uses' => $this->uses('show', ConfirmedPasswordStatusController::class), | |
'middleware' => ['auth'], | |
]); | |
$this->router->post($this->prefix('user/confirm-password'), [ | |
'uses' => $this->uses('store', ConfirmablePasswordController::class), | |
'middleware' => ['auth'], | |
]); | |
//== TWO FACTOR AUTHENTICATED | |
if (Features::enabled(Features::twoFactorAuthentication())) { | |
$twoFactorLimiter = config('fortify.limiters.two-factor'); | |
if ($enableViews) { | |
$this->router->get($this->prefix('two-factor-challenge'), [ | |
'as' => $this->name('two-factor.login'), | |
'uses' => $this->uses('create', TwoFactorAuthenticatedSessionController::class), | |
'middleware' => ['guest:'.config('fortify.guard')], | |
]); | |
} | |
$this->router->post($this->prefix('two-factor-challenge'), [ | |
'uses' => $this->uses('store', TwoFactorAuthenticatedSessionController::class), | |
'middleware' => array_filter([ | |
'guest:'.config('fortify.guard'), | |
$twoFactorLimiter ? 'throttle:'.$twoFactorLimiter : null, | |
]), | |
]); | |
$twoFactorMiddleware = Features::optionEnabled(Features::twoFactorAuthentication(), 'confirmPassword') | |
? ['auth', 'password.confirm'] | |
: ['auth']; | |
$this->router->post($this->prefix('user/two-factor-authentication'), [ | |
'uses' => $this->uses('store', TwoFactorAuthenticationController::class), | |
'middleware' => $twoFactorMiddleware, | |
]); | |
$this->router->delete($this->prefix('user/two-factor-authentication'), [ | |
'uses' => $this->uses('destroy', TwoFactorAuthenticationController::class), | |
'middleware' => $twoFactorMiddleware, | |
]); | |
$this->router->get($this->prefix('user/two-factor-qr-code'), [ | |
'uses' => $this->uses('show', TwoFactorQrCodeController::class), | |
'middleware' => $twoFactorMiddleware, | |
]); | |
$this->router->get($this->prefix('user/two-factor-recovery-codes'), [ | |
'uses' => $this->uses('index', RecoveryCodeController::class), | |
'middleware' => $twoFactorMiddleware, | |
]); | |
$this->router->post($this->prefix('user/two-factor-recovery-codes'), [ | |
'uses' => $this->uses('store', RecoveryCodeController::class), | |
'middleware' => $twoFactorMiddleware, | |
]); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment