first commit

This commit is contained in:
benjibennn
2023-12-22 12:35:55 +08:00
commit 9f89a732d6
872 changed files with 156291 additions and 0 deletions

View File

@@ -0,0 +1,40 @@
<?php
declare(strict_types=1);
namespace App\Http\Middleware;
use App\Models\Role;
use Closure;
use Illuminate\Http\Request;
use Symfony\Component\HttpFoundation\Response;
class CheckIfUserRole
{
/**
* Handle an incoming request.
*
* @param \Closure(\Illuminate\Http\Request): (\Symfony\Component\HttpFoundation\Response) $next
*/
public function handle(Request $request, Closure $next): Response
{
// Check status
if (auth()->user()->status == 'inactive') {
$redirectUrl = auth()->user()->getRedirectRoute();
auth()->logout();
return redirect($redirectUrl);
}
// Check role
$roles = [
Role::OWNER_ROLE,
Role::ADMINISTRATOR_ROLE,
Role::BOOKKEEPER_ROLE,
Role::COMPANY_SECRETARY_ROLE,
];
if (in_array(auth()->user()->role_id, $roles)) {
return $next($request);
}
return abort(Response::HTTP_FORBIDDEN, '403 Access Forbidden');
}
}