initial commit
This commit is contained in:
48
app/Http/Middleware/AccessControlMiddleware.php
Normal file
48
app/Http/Middleware/AccessControlMiddleware.php
Normal file
@@ -0,0 +1,48 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Middleware;
|
||||
|
||||
use Closure;
|
||||
use App\Model\ProcessLog;
|
||||
use Carbon\Carbon;
|
||||
use App\Classes\Constant;
|
||||
use Illuminate\Auth\AuthenticationException;
|
||||
use App\Model\Client;
|
||||
use App\Model\JsToken;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use App\User;
|
||||
|
||||
class AccessControlMiddleware
|
||||
{
|
||||
/**
|
||||
* Handle an incoming request.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @param \Closure $next
|
||||
* @return mixed
|
||||
*/
|
||||
public function handle($request, Closure $next)
|
||||
{
|
||||
$key = false;
|
||||
$pass = false;
|
||||
|
||||
|
||||
header("Access-Control-Allow-Origin: *");
|
||||
|
||||
$headers = [
|
||||
'Access-Control-Allow-Methods' => 'POST,GET,OPTIONS,PUT,DELETE',
|
||||
'Access-Control-Allow-Headers' => 'Content-Type, X-Auth-Token, Origin, Authorization',
|
||||
];
|
||||
if ($request->getMethod() == "OPTIONS") {
|
||||
|
||||
return response()->json('OK',200,$headers);
|
||||
}
|
||||
$response = $next($request);
|
||||
foreach ($headers as $key => $value) {
|
||||
$response->header($key, $value);
|
||||
}
|
||||
|
||||
return $response;
|
||||
}
|
||||
|
||||
}
|
30
app/Http/Middleware/AdminAuth.php
Normal file
30
app/Http/Middleware/AdminAuth.php
Normal file
@@ -0,0 +1,30 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Middleware;
|
||||
|
||||
use Closure;
|
||||
use App\Model\ProcessLog;
|
||||
use Carbon\Carbon;
|
||||
use App\Classes\Constant;
|
||||
use Illuminate\Auth\AuthenticationException;
|
||||
use App\Model\Client;
|
||||
use App\Model\JsToken;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use App\User;
|
||||
|
||||
class AdminAuth
|
||||
{
|
||||
/**
|
||||
* Handle an incoming request.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @param \Closure $next
|
||||
* @return mixed
|
||||
*/
|
||||
public function handle($request, Closure $next)
|
||||
{
|
||||
Auth::setDefaultDriver('admin');
|
||||
return $next($request);
|
||||
}
|
||||
|
||||
}
|
58
app/Http/Middleware/AdminRedirectAuthenticated.php
Normal file
58
app/Http/Middleware/AdminRedirectAuthenticated.php
Normal file
@@ -0,0 +1,58 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Middleware;
|
||||
|
||||
use Closure;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Tymon\JWTAuth\Facades\JWTAuth;
|
||||
use Tymon\JWTAuth\Exceptions\JWTException;
|
||||
use Tymon\JWTAuth\Exceptions\TokenExpiredException;
|
||||
use Tymon\JWTAuth\Exceptions\TokenInvalidException;
|
||||
|
||||
|
||||
class AdminRedirectAuthenticated
|
||||
{
|
||||
/**
|
||||
* Handle an incoming request.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @param \Closure $next
|
||||
* @param string|null $guard
|
||||
* @return mixed
|
||||
*/
|
||||
public function handle(Request $request, Closure $next, $guard = null)
|
||||
{
|
||||
try {
|
||||
$user = JWTAuth::parseToken()->authenticate();
|
||||
} catch (TokenExpiredException $e) {
|
||||
return response()->json(['error' => 'Token has expired'], 401);
|
||||
} catch (TokenInvalidException $e) {
|
||||
return response()->json(['error' => 'Token is invalid'], 401);
|
||||
} catch (JWTException $e) {
|
||||
return response()->json(['error' => 'Token is missing or invalid'], 401);
|
||||
} catch (TokenExpiredException $e) {
|
||||
// Invalidate the old token
|
||||
$token = JWTAuth::getToken();
|
||||
JWTAuth::invalidate($token);
|
||||
|
||||
|
||||
|
||||
|
||||
// Return an error response with instructions for obtaining a new token
|
||||
return response()->json([
|
||||
'error' => 'Token has expired',
|
||||
'message' => 'Please obtain a new token from the authentication endpoint.'
|
||||
], 401);
|
||||
}
|
||||
|
||||
|
||||
|
||||
// // Check if the user has the required role or permissions
|
||||
// if (!$user->hasRole('admin') && !$user->hasPermission('access_admin_panel')) {
|
||||
// return response()->json(['error' => 'Unauthorized'], 403);
|
||||
// }
|
||||
|
||||
return $next($request);
|
||||
}
|
||||
}
|
30
app/Http/Middleware/AgentAuth.php
Normal file
30
app/Http/Middleware/AgentAuth.php
Normal file
@@ -0,0 +1,30 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Middleware;
|
||||
|
||||
use Closure;
|
||||
use App\Model\ProcessLog;
|
||||
use Carbon\Carbon;
|
||||
use App\Classes\Constant;
|
||||
use Illuminate\Auth\AuthenticationException;
|
||||
use App\Model\Client;
|
||||
use App\Model\JsToken;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use App\User;
|
||||
|
||||
class AgentAuth
|
||||
{
|
||||
/**
|
||||
* Handle an incoming request.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @param \Closure $next
|
||||
* @return mixed
|
||||
*/
|
||||
public function handle($request, Closure $next)
|
||||
{
|
||||
Auth::setDefaultDriver('agent');
|
||||
return $next($request);
|
||||
}
|
||||
|
||||
}
|
28
app/Http/Middleware/AgentRedirectAuthenticated.php
Normal file
28
app/Http/Middleware/AgentRedirectAuthenticated.php
Normal file
@@ -0,0 +1,28 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Middleware;
|
||||
|
||||
use Closure;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
|
||||
class AgentRedirectAuthenticated
|
||||
{
|
||||
/**
|
||||
* Handle an incoming request.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @param \Closure $next
|
||||
* @param string|null $guard
|
||||
* @return mixed
|
||||
*/
|
||||
public function handle($request, Closure $next, $guard = null)
|
||||
{
|
||||
if (Auth::user() && Auth::guard('agent')->check()) {
|
||||
return $next($request);
|
||||
}
|
||||
|
||||
return redirect('/agent/login');
|
||||
|
||||
|
||||
}
|
||||
}
|
17
app/Http/Middleware/Authenticate.php
Normal file
17
app/Http/Middleware/Authenticate.php
Normal file
@@ -0,0 +1,17 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Middleware;
|
||||
|
||||
use Illuminate\Auth\Middleware\Authenticate as Middleware;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class Authenticate extends Middleware
|
||||
{
|
||||
/**
|
||||
* Get the path the user should be redirected to when they are not authenticated.
|
||||
*/
|
||||
protected function redirectTo(Request $request): ?string
|
||||
{
|
||||
return $request->expectsJson() ? null : route('login');
|
||||
}
|
||||
}
|
30
app/Http/Middleware/DoctorAuth.php
Normal file
30
app/Http/Middleware/DoctorAuth.php
Normal file
@@ -0,0 +1,30 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Middleware;
|
||||
|
||||
use Closure;
|
||||
use App\Model\ProcessLog;
|
||||
use Carbon\Carbon;
|
||||
use App\Classes\Constant;
|
||||
use Illuminate\Auth\AuthenticationException;
|
||||
use App\Model\Client;
|
||||
use App\Model\JsToken;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use App\User;
|
||||
|
||||
class DoctorAuth
|
||||
{
|
||||
/**
|
||||
* Handle an incoming request.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @param \Closure $next
|
||||
* @return mixed
|
||||
*/
|
||||
public function handle($request, Closure $next)
|
||||
{
|
||||
Auth::setDefaultDriver('doctor');
|
||||
return $next($request);
|
||||
}
|
||||
|
||||
}
|
28
app/Http/Middleware/DoctorRedirectAuthenticated.php
Normal file
28
app/Http/Middleware/DoctorRedirectAuthenticated.php
Normal file
@@ -0,0 +1,28 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Middleware;
|
||||
|
||||
use Closure;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
|
||||
class DoctorRedirectAuthenticated
|
||||
{
|
||||
/**
|
||||
* Handle an incoming request.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @param \Closure $next
|
||||
* @param string|null $guard
|
||||
* @return mixed
|
||||
*/
|
||||
public function handle($request, Closure $next, $guard = null)
|
||||
{
|
||||
if (Auth::user() && Auth::guard('doctor')->check()) {
|
||||
return $next($request);
|
||||
}
|
||||
|
||||
return redirect('/doctor/login');
|
||||
|
||||
|
||||
}
|
||||
}
|
17
app/Http/Middleware/EncryptCookies.php
Normal file
17
app/Http/Middleware/EncryptCookies.php
Normal file
@@ -0,0 +1,17 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Middleware;
|
||||
|
||||
use Illuminate\Cookie\Middleware\EncryptCookies as Middleware;
|
||||
|
||||
class EncryptCookies extends Middleware
|
||||
{
|
||||
/**
|
||||
* The names of the cookies that should not be encrypted.
|
||||
*
|
||||
* @var array<int, string>
|
||||
*/
|
||||
protected $except = [
|
||||
//
|
||||
];
|
||||
}
|
36
app/Http/Middleware/PatientAuth.php
Normal file
36
app/Http/Middleware/PatientAuth.php
Normal file
@@ -0,0 +1,36 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Middleware;
|
||||
|
||||
use Closure;
|
||||
use App\Model\ProcessLog;
|
||||
use Carbon\Carbon;
|
||||
use App\Classes\Constant;
|
||||
use Illuminate\Auth\AuthenticationException;
|
||||
use App\Model\Client;
|
||||
use App\Model\JsToken;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use App\User;
|
||||
|
||||
class PatientAuth
|
||||
{
|
||||
/**
|
||||
* Handle an incoming request.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @param \Closure $next
|
||||
* @return mixed
|
||||
*/
|
||||
public function handle($request, Closure $next)
|
||||
{
|
||||
Auth::setDefaultDriver('patient');
|
||||
if (!Auth::guard('patient')->check()) {
|
||||
// If not authenticated, return unauthorized response
|
||||
return response()->json([
|
||||
'message' => 'Unauthorized'
|
||||
], 401);
|
||||
}
|
||||
return $next($request);
|
||||
}
|
||||
|
||||
}
|
36
app/Http/Middleware/PatientAuthenticated.php
Normal file
36
app/Http/Middleware/PatientAuthenticated.php
Normal file
@@ -0,0 +1,36 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Middleware;
|
||||
|
||||
use Closure;
|
||||
use App\Model\ProcessLog;
|
||||
use Carbon\Carbon;
|
||||
use App\Classes\Constant;
|
||||
use Illuminate\Auth\AuthenticationException;
|
||||
use App\Model\Client;
|
||||
use App\Model\JsToken;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use App\User;
|
||||
|
||||
class PatientAuthenticated
|
||||
{
|
||||
/**
|
||||
* Handle an incoming request.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @param \Closure $next
|
||||
* @return mixed
|
||||
*/
|
||||
public function handle($request, Closure $next)
|
||||
{
|
||||
Auth::setDefaultDriver('patient');
|
||||
if (!Auth::guard('patient')->check()) {
|
||||
// If not authenticated, return unauthorized response
|
||||
return response()->json([
|
||||
'message' => 'Unauthorized'
|
||||
], 401);
|
||||
}
|
||||
return $next($request);
|
||||
}
|
||||
|
||||
}
|
17
app/Http/Middleware/PreventRequestsDuringMaintenance.php
Normal file
17
app/Http/Middleware/PreventRequestsDuringMaintenance.php
Normal file
@@ -0,0 +1,17 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Middleware;
|
||||
|
||||
use Illuminate\Foundation\Http\Middleware\PreventRequestsDuringMaintenance as Middleware;
|
||||
|
||||
class PreventRequestsDuringMaintenance extends Middleware
|
||||
{
|
||||
/**
|
||||
* The URIs that should be reachable while maintenance mode is enabled.
|
||||
*
|
||||
* @var array<int, string>
|
||||
*/
|
||||
protected $except = [
|
||||
//
|
||||
];
|
||||
}
|
30
app/Http/Middleware/RedirectIfAuthenticated.php
Normal file
30
app/Http/Middleware/RedirectIfAuthenticated.php
Normal file
@@ -0,0 +1,30 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Middleware;
|
||||
|
||||
use App\Providers\RouteServiceProvider;
|
||||
use Closure;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
|
||||
class RedirectIfAuthenticated
|
||||
{
|
||||
/**
|
||||
* 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(RouteServiceProvider::HOME);
|
||||
}
|
||||
}
|
||||
|
||||
return $next($request);
|
||||
}
|
||||
}
|
19
app/Http/Middleware/TrimStrings.php
Normal file
19
app/Http/Middleware/TrimStrings.php
Normal file
@@ -0,0 +1,19 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Middleware;
|
||||
|
||||
use Illuminate\Foundation\Http\Middleware\TrimStrings as Middleware;
|
||||
|
||||
class TrimStrings extends Middleware
|
||||
{
|
||||
/**
|
||||
* The names of the attributes that should not be trimmed.
|
||||
*
|
||||
* @var array<int, string>
|
||||
*/
|
||||
protected $except = [
|
||||
'current_password',
|
||||
'password',
|
||||
'password_confirmation',
|
||||
];
|
||||
}
|
20
app/Http/Middleware/TrustHosts.php
Normal file
20
app/Http/Middleware/TrustHosts.php
Normal file
@@ -0,0 +1,20 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Middleware;
|
||||
|
||||
use Illuminate\Http\Middleware\TrustHosts as Middleware;
|
||||
|
||||
class TrustHosts extends Middleware
|
||||
{
|
||||
/**
|
||||
* Get the host patterns that should be trusted.
|
||||
*
|
||||
* @return array<int, string|null>
|
||||
*/
|
||||
public function hosts(): array
|
||||
{
|
||||
return [
|
||||
$this->allSubdomainsOfApplicationUrl(),
|
||||
];
|
||||
}
|
||||
}
|
28
app/Http/Middleware/TrustProxies.php
Normal file
28
app/Http/Middleware/TrustProxies.php
Normal file
@@ -0,0 +1,28 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Middleware;
|
||||
|
||||
use Illuminate\Http\Middleware\TrustProxies as Middleware;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class TrustProxies extends Middleware
|
||||
{
|
||||
/**
|
||||
* The trusted proxies for this application.
|
||||
*
|
||||
* @var array<int, string>|string|null
|
||||
*/
|
||||
protected $proxies;
|
||||
|
||||
/**
|
||||
* The headers that should be used to detect proxies.
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
protected $headers =
|
||||
Request::HEADER_X_FORWARDED_FOR |
|
||||
Request::HEADER_X_FORWARDED_HOST |
|
||||
Request::HEADER_X_FORWARDED_PORT |
|
||||
Request::HEADER_X_FORWARDED_PROTO |
|
||||
Request::HEADER_X_FORWARDED_AWS_ELB;
|
||||
}
|
22
app/Http/Middleware/ValidateSignature.php
Normal file
22
app/Http/Middleware/ValidateSignature.php
Normal file
@@ -0,0 +1,22 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Middleware;
|
||||
|
||||
use Illuminate\Routing\Middleware\ValidateSignature as Middleware;
|
||||
|
||||
class ValidateSignature extends Middleware
|
||||
{
|
||||
/**
|
||||
* The names of the query string parameters that should be ignored.
|
||||
*
|
||||
* @var array<int, string>
|
||||
*/
|
||||
protected $except = [
|
||||
// 'fbclid',
|
||||
// 'utm_campaign',
|
||||
// 'utm_content',
|
||||
// 'utm_medium',
|
||||
// 'utm_source',
|
||||
// 'utm_term',
|
||||
];
|
||||
}
|
25
app/Http/Middleware/VerifyCsrfToken.php
Normal file
25
app/Http/Middleware/VerifyCsrfToken.php
Normal file
@@ -0,0 +1,25 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Middleware;
|
||||
|
||||
use Illuminate\Foundation\Http\Middleware\VerifyCsrfToken as Middleware;
|
||||
|
||||
class VerifyCsrfToken extends Middleware
|
||||
{
|
||||
/**
|
||||
* The URIs that should be excluded from CSRF verification.
|
||||
*
|
||||
* @var array<int, string>
|
||||
*/
|
||||
protected $except = [
|
||||
'api/*',
|
||||
'api/admin/*',
|
||||
'agent/api/*',
|
||||
'agent/login-agent',
|
||||
'agent/registerPost',
|
||||
'api/admin/*',
|
||||
'broadcasting/auth',
|
||||
'calendly/*'
|
||||
|
||||
];
|
||||
}
|
Reference in New Issue
Block a user