EnsureProCanAccessPatient.php 867 B

12345678910111213141516171819202122232425262728293031323334353637
  1. <?php
  2. namespace App\Http\Middleware;
  3. use App\Models\AppSession;
  4. use Closure;
  5. class EnsureProCanAccessPatient
  6. {
  7. /**
  8. * Handle an incoming request.
  9. *
  10. * @param \Illuminate\Http\Request $request
  11. * @param \Closure $next
  12. * @return mixed
  13. */
  14. public function handle($request, Closure $next)
  15. {
  16. $sessionKey = $request->cookie('sessionKey');
  17. $appSession = AppSession::where('session_key', $sessionKey)->where('is_active', true)->first();
  18. $authenticated = $sessionKey && $appSession && $appSession->pro;
  19. if (!$authenticated) {
  20. abort(403);
  21. }
  22. $patient = \request()->route('patient');
  23. if(!!$patient) {
  24. if(!$appSession->pro->canAccess($patient->uid)) {
  25. abort(403);
  26. }
  27. }
  28. return $next($request);
  29. }
  30. }