refactor: susun semula struktur folder — Laravel source ke src/
This commit is contained in:
131
vendor/laravel/framework/src/Illuminate/Auth/Middleware/Authenticate.php
vendored
Normal file
131
vendor/laravel/framework/src/Illuminate/Auth/Middleware/Authenticate.php
vendored
Normal file
@@ -0,0 +1,131 @@
|
||||
<?php
|
||||
|
||||
namespace Illuminate\Auth\Middleware;
|
||||
|
||||
use Closure;
|
||||
use Illuminate\Auth\AuthenticationException;
|
||||
use Illuminate\Contracts\Auth\Factory as Auth;
|
||||
use Illuminate\Contracts\Auth\Middleware\AuthenticatesRequests;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class Authenticate implements AuthenticatesRequests
|
||||
{
|
||||
/**
|
||||
* The authentication factory instance.
|
||||
*
|
||||
* @var \Illuminate\Contracts\Auth\Factory
|
||||
*/
|
||||
protected $auth;
|
||||
|
||||
/**
|
||||
* The callback that should be used to generate the authentication redirect path.
|
||||
*
|
||||
* @var callable
|
||||
*/
|
||||
protected static $redirectToCallback;
|
||||
|
||||
/**
|
||||
* Create a new middleware instance.
|
||||
*
|
||||
* @param \Illuminate\Contracts\Auth\Factory $auth
|
||||
*/
|
||||
public function __construct(Auth $auth)
|
||||
{
|
||||
$this->auth = $auth;
|
||||
}
|
||||
|
||||
/**
|
||||
* Specify the guards for the middleware.
|
||||
*
|
||||
* @param string $guard
|
||||
* @param string $others
|
||||
* @return string
|
||||
*/
|
||||
public static function using($guard, ...$others)
|
||||
{
|
||||
return static::class.':'.implode(',', [$guard, ...$others]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle an incoming request.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @param \Closure $next
|
||||
* @param string ...$guards
|
||||
* @return mixed
|
||||
*
|
||||
* @throws \Illuminate\Auth\AuthenticationException
|
||||
*/
|
||||
public function handle($request, Closure $next, ...$guards)
|
||||
{
|
||||
$this->authenticate($request, $guards);
|
||||
|
||||
return $next($request);
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine if the user is logged in to any of the given guards.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @param array $guards
|
||||
* @return void
|
||||
*
|
||||
* @throws \Illuminate\Auth\AuthenticationException
|
||||
*/
|
||||
protected function authenticate($request, array $guards)
|
||||
{
|
||||
if (empty($guards)) {
|
||||
$guards = [null];
|
||||
}
|
||||
|
||||
foreach ($guards as $guard) {
|
||||
if ($this->auth->guard($guard)->check()) {
|
||||
return $this->auth->shouldUse($guard);
|
||||
}
|
||||
}
|
||||
|
||||
$this->unauthenticated($request, $guards);
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle an unauthenticated user.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @param array $guards
|
||||
* @return never
|
||||
*
|
||||
* @throws \Illuminate\Auth\AuthenticationException
|
||||
*/
|
||||
protected function unauthenticated($request, array $guards)
|
||||
{
|
||||
throw new AuthenticationException(
|
||||
'Unauthenticated.',
|
||||
$guards,
|
||||
$request->expectsJson() ? null : $this->redirectTo($request),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the path the user should be redirected to when they are not authenticated.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @return string|null
|
||||
*/
|
||||
protected function redirectTo(Request $request)
|
||||
{
|
||||
if (static::$redirectToCallback) {
|
||||
return call_user_func(static::$redirectToCallback, $request);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Specify the callback that should be used to generate the redirect path.
|
||||
*
|
||||
* @param callable $redirectToCallback
|
||||
* @return void
|
||||
*/
|
||||
public static function redirectUsing(callable $redirectToCallback)
|
||||
{
|
||||
static::$redirectToCallback = $redirectToCallback;
|
||||
}
|
||||
}
|
||||
58
vendor/laravel/framework/src/Illuminate/Auth/Middleware/AuthenticateWithBasicAuth.php
vendored
Normal file
58
vendor/laravel/framework/src/Illuminate/Auth/Middleware/AuthenticateWithBasicAuth.php
vendored
Normal file
@@ -0,0 +1,58 @@
|
||||
<?php
|
||||
|
||||
namespace Illuminate\Auth\Middleware;
|
||||
|
||||
use Closure;
|
||||
use Illuminate\Contracts\Auth\Factory as AuthFactory;
|
||||
|
||||
class AuthenticateWithBasicAuth
|
||||
{
|
||||
/**
|
||||
* The guard factory instance.
|
||||
*
|
||||
* @var \Illuminate\Contracts\Auth\Factory
|
||||
*/
|
||||
protected $auth;
|
||||
|
||||
/**
|
||||
* Create a new middleware instance.
|
||||
*
|
||||
* @param \Illuminate\Contracts\Auth\Factory $auth
|
||||
*/
|
||||
public function __construct(AuthFactory $auth)
|
||||
{
|
||||
$this->auth = $auth;
|
||||
}
|
||||
|
||||
/**
|
||||
* Specify the guard and field for the middleware.
|
||||
*
|
||||
* @param string|null $guard
|
||||
* @param string|null $field
|
||||
* @return string
|
||||
*
|
||||
* @named-arguments-supported
|
||||
*/
|
||||
public static function using($guard = null, $field = null)
|
||||
{
|
||||
return static::class.':'.implode(',', func_get_args());
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle an incoming request.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @param \Closure $next
|
||||
* @param string|null $guard
|
||||
* @param string|null $field
|
||||
* @return mixed
|
||||
*
|
||||
* @throws \Symfony\Component\HttpKernel\Exception\UnauthorizedHttpException
|
||||
*/
|
||||
public function handle($request, Closure $next, $guard = null, $field = null)
|
||||
{
|
||||
$this->auth->guard($guard)->basic($field ?: 'email');
|
||||
|
||||
return $next($request);
|
||||
}
|
||||
}
|
||||
107
vendor/laravel/framework/src/Illuminate/Auth/Middleware/Authorize.php
vendored
Normal file
107
vendor/laravel/framework/src/Illuminate/Auth/Middleware/Authorize.php
vendored
Normal file
@@ -0,0 +1,107 @@
|
||||
<?php
|
||||
|
||||
namespace Illuminate\Auth\Middleware;
|
||||
|
||||
use Closure;
|
||||
use Illuminate\Contracts\Auth\Access\Gate;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Support\Collection;
|
||||
|
||||
use function Illuminate\Support\enum_value;
|
||||
|
||||
class Authorize
|
||||
{
|
||||
/**
|
||||
* The gate instance.
|
||||
*
|
||||
* @var \Illuminate\Contracts\Auth\Access\Gate
|
||||
*/
|
||||
protected $gate;
|
||||
|
||||
/**
|
||||
* Create a new middleware instance.
|
||||
*
|
||||
* @param \Illuminate\Contracts\Auth\Access\Gate $gate
|
||||
*/
|
||||
public function __construct(Gate $gate)
|
||||
{
|
||||
$this->gate = $gate;
|
||||
}
|
||||
|
||||
/**
|
||||
* Specify the ability and models for the middleware.
|
||||
*
|
||||
* @param \UnitEnum|string $ability
|
||||
* @param string ...$models
|
||||
* @return string
|
||||
*/
|
||||
public static function using($ability, ...$models)
|
||||
{
|
||||
return static::class.':'.implode(',', [enum_value($ability), ...$models]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle an incoming request.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @param \Closure $next
|
||||
* @param string $ability
|
||||
* @param array|null ...$models
|
||||
* @return mixed
|
||||
*
|
||||
* @throws \Illuminate\Auth\AuthenticationException
|
||||
* @throws \Illuminate\Auth\Access\AuthorizationException
|
||||
*/
|
||||
public function handle($request, Closure $next, $ability, ...$models)
|
||||
{
|
||||
$this->gate->authorize($ability, $this->getGateArguments($request, $models));
|
||||
|
||||
return $next($request);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the arguments parameter for the gate.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @param array|null $models
|
||||
* @return array
|
||||
*/
|
||||
protected function getGateArguments($request, $models)
|
||||
{
|
||||
if (is_null($models)) {
|
||||
return [];
|
||||
}
|
||||
|
||||
return (new Collection($models))
|
||||
->map(fn ($model) => $model instanceof Model ? $model : $this->getModel($request, $model))
|
||||
->all();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the model to authorize.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @param string $model
|
||||
* @return \Illuminate\Database\Eloquent\Model|string
|
||||
*/
|
||||
protected function getModel($request, $model)
|
||||
{
|
||||
if ($this->isClassName($model)) {
|
||||
return trim($model);
|
||||
}
|
||||
|
||||
return $request->route($model, null) ??
|
||||
((preg_match("/^['\"](.*)['\"]$/", trim($model), $matches)) ? $matches[1] : null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if the given string looks like a fully-qualified class name.
|
||||
*
|
||||
* @param string $value
|
||||
* @return bool
|
||||
*/
|
||||
protected function isClassName($value)
|
||||
{
|
||||
return str_contains($value, '\\');
|
||||
}
|
||||
}
|
||||
43
vendor/laravel/framework/src/Illuminate/Auth/Middleware/EnsureEmailIsVerified.php
vendored
Normal file
43
vendor/laravel/framework/src/Illuminate/Auth/Middleware/EnsureEmailIsVerified.php
vendored
Normal file
@@ -0,0 +1,43 @@
|
||||
<?php
|
||||
|
||||
namespace Illuminate\Auth\Middleware;
|
||||
|
||||
use Closure;
|
||||
use Illuminate\Contracts\Auth\MustVerifyEmail;
|
||||
use Illuminate\Support\Facades\Redirect;
|
||||
use Illuminate\Support\Facades\URL;
|
||||
|
||||
class EnsureEmailIsVerified
|
||||
{
|
||||
/**
|
||||
* Specify the redirect route for the middleware.
|
||||
*
|
||||
* @param string $route
|
||||
* @return string
|
||||
*/
|
||||
public static function redirectTo($route)
|
||||
{
|
||||
return static::class.':'.$route;
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle an incoming request.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @param \Closure $next
|
||||
* @param string|null $redirectToRoute
|
||||
* @return \Illuminate\Http\Response|\Illuminate\Http\RedirectResponse|null
|
||||
*/
|
||||
public function handle($request, Closure $next, $redirectToRoute = null)
|
||||
{
|
||||
if (! $request->user() ||
|
||||
($request->user() instanceof MustVerifyEmail &&
|
||||
! $request->user()->hasVerifiedEmail())) {
|
||||
return $request->expectsJson()
|
||||
? abort(403, 'Your email address is not verified.')
|
||||
: Redirect::guest(URL::route($redirectToRoute ?: 'verification.notice'));
|
||||
}
|
||||
|
||||
return $next($request);
|
||||
}
|
||||
}
|
||||
92
vendor/laravel/framework/src/Illuminate/Auth/Middleware/RedirectIfAuthenticated.php
vendored
Normal file
92
vendor/laravel/framework/src/Illuminate/Auth/Middleware/RedirectIfAuthenticated.php
vendored
Normal file
@@ -0,0 +1,92 @@
|
||||
<?php
|
||||
|
||||
namespace Illuminate\Auth\Middleware;
|
||||
|
||||
use Closure;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Illuminate\Support\Facades\Route;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
|
||||
class RedirectIfAuthenticated
|
||||
{
|
||||
/**
|
||||
* The callback that should be used to generate the authentication redirect path.
|
||||
*
|
||||
* @var callable|null
|
||||
*/
|
||||
protected static $redirectToCallback;
|
||||
|
||||
/**
|
||||
* Specify the guards for the middleware.
|
||||
*
|
||||
* @param string $guard
|
||||
* @param string $others
|
||||
* @return string
|
||||
*/
|
||||
public static function using($guard, ...$others)
|
||||
{
|
||||
return static::class.':'.implode(',', [$guard, ...$others]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle an incoming request.
|
||||
*
|
||||
* @param \Closure(\Illuminate\Http\Request): (\Symfony\Component\HttpFoundation\Response) $next
|
||||
*/
|
||||
public function handle(Request $request, Closure $next, string ...$guards): Response
|
||||
{
|
||||
$guards = empty($guards) ? [null] : $guards;
|
||||
|
||||
foreach ($guards as $guard) {
|
||||
if (Auth::guard($guard)->check()) {
|
||||
return redirect($this->redirectTo($request));
|
||||
}
|
||||
}
|
||||
|
||||
return $next($request);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the path the user should be redirected to when they are authenticated.
|
||||
*/
|
||||
protected function redirectTo(Request $request): ?string
|
||||
{
|
||||
return static::$redirectToCallback
|
||||
? call_user_func(static::$redirectToCallback, $request)
|
||||
: $this->defaultRedirectUri();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the default URI the user should be redirected to when they are authenticated.
|
||||
*/
|
||||
protected function defaultRedirectUri(): string
|
||||
{
|
||||
foreach (['dashboard', 'home'] as $uri) {
|
||||
if (Route::has($uri)) {
|
||||
return route($uri);
|
||||
}
|
||||
}
|
||||
|
||||
$routes = Route::getRoutes()->get('GET');
|
||||
|
||||
foreach (['dashboard', 'home'] as $uri) {
|
||||
if (isset($routes[$uri])) {
|
||||
return '/'.$uri;
|
||||
}
|
||||
}
|
||||
|
||||
return '/';
|
||||
}
|
||||
|
||||
/**
|
||||
* Specify the callback that should be used to generate the redirect path.
|
||||
*
|
||||
* @param callable $redirectToCallback
|
||||
* @return void
|
||||
*/
|
||||
public static function redirectUsing(callable $redirectToCallback)
|
||||
{
|
||||
static::$redirectToCallback = $redirectToCallback;
|
||||
}
|
||||
}
|
||||
100
vendor/laravel/framework/src/Illuminate/Auth/Middleware/RequirePassword.php
vendored
Normal file
100
vendor/laravel/framework/src/Illuminate/Auth/Middleware/RequirePassword.php
vendored
Normal file
@@ -0,0 +1,100 @@
|
||||
<?php
|
||||
|
||||
namespace Illuminate\Auth\Middleware;
|
||||
|
||||
use Closure;
|
||||
use Illuminate\Contracts\Routing\ResponseFactory;
|
||||
use Illuminate\Contracts\Routing\UrlGenerator;
|
||||
use Illuminate\Support\Facades\Date;
|
||||
|
||||
class RequirePassword
|
||||
{
|
||||
/**
|
||||
* The response factory instance.
|
||||
*
|
||||
* @var \Illuminate\Contracts\Routing\ResponseFactory
|
||||
*/
|
||||
protected $responseFactory;
|
||||
|
||||
/**
|
||||
* The URL generator instance.
|
||||
*
|
||||
* @var \Illuminate\Contracts\Routing\UrlGenerator
|
||||
*/
|
||||
protected $urlGenerator;
|
||||
|
||||
/**
|
||||
* The password timeout.
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
protected $passwordTimeout;
|
||||
|
||||
/**
|
||||
* Create a new middleware instance.
|
||||
*
|
||||
* @param \Illuminate\Contracts\Routing\ResponseFactory $responseFactory
|
||||
* @param \Illuminate\Contracts\Routing\UrlGenerator $urlGenerator
|
||||
* @param int|null $passwordTimeout
|
||||
*/
|
||||
public function __construct(ResponseFactory $responseFactory, UrlGenerator $urlGenerator, $passwordTimeout = null)
|
||||
{
|
||||
$this->responseFactory = $responseFactory;
|
||||
$this->urlGenerator = $urlGenerator;
|
||||
$this->passwordTimeout = $passwordTimeout ?: 10800;
|
||||
}
|
||||
|
||||
/**
|
||||
* Specify the redirect route and timeout for the middleware.
|
||||
*
|
||||
* @param string|null $redirectToRoute
|
||||
* @param string|int|null $passwordTimeoutSeconds
|
||||
* @return string
|
||||
*
|
||||
* @named-arguments-supported
|
||||
*/
|
||||
public static function using($redirectToRoute = null, $passwordTimeoutSeconds = null)
|
||||
{
|
||||
return static::class.':'.implode(',', func_get_args());
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle an incoming request.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @param \Closure $next
|
||||
* @param string|null $redirectToRoute
|
||||
* @param string|int|null $passwordTimeoutSeconds
|
||||
* @return mixed
|
||||
*/
|
||||
public function handle($request, Closure $next, $redirectToRoute = null, $passwordTimeoutSeconds = null)
|
||||
{
|
||||
if ($this->shouldConfirmPassword($request, $passwordTimeoutSeconds)) {
|
||||
if ($request->expectsJson()) {
|
||||
return $this->responseFactory->json([
|
||||
'message' => 'Password confirmation required.',
|
||||
], 423);
|
||||
}
|
||||
|
||||
return $this->responseFactory->redirectGuest(
|
||||
$this->urlGenerator->route($redirectToRoute ?: 'password.confirm')
|
||||
);
|
||||
}
|
||||
|
||||
return $next($request);
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine if the confirmation timeout has expired.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @param int|null $passwordTimeoutSeconds
|
||||
* @return bool
|
||||
*/
|
||||
protected function shouldConfirmPassword($request, $passwordTimeoutSeconds = null)
|
||||
{
|
||||
$confirmedAt = Date::now()->unix() - $request->session()->get('auth.password_confirmed_at', 0);
|
||||
|
||||
return $confirmedAt > ($passwordTimeoutSeconds ?? $this->passwordTimeout);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user