⚝
One Hat Cyber Team
⚝
Your IP:
216.73.216.77
Server IP:
13.127.59.50
Server:
Linux ip-172-31-46-210 5.15.0-1033-aws #37~20.04.1-Ubuntu SMP Fri Mar 17 11:39:30 UTC 2023 x86_64
Server Software:
Apache/2.4.41 (Ubuntu)
PHP Version:
7.4.3-4ubuntu2.29
Buat File
|
Buat Folder
Eksekusi
Dir :
~
/
var
/
www
/
ecommerce_pg
/
app
/
Http
/
Middleware
/
View File Name :
CheckIfAdmin.php
<?php namespace App\Http\Middleware; use Closure; class CheckIfAdmin { /** * Checked that the logged in user is an administrator. * * -------------- * VERY IMPORTANT * -------------- * If you have both regular users and admins inside the same table, change * the contents of this method to check that the logged in user * is an admin, and not a regular user. * * Additionally, in Laravel 7+, you should change app/Providers/RouteServiceProvider::HOME * which defines the route where a logged in user (but not admin) gets redirected * when trying to access an admin route. By default it's '/home' but Backpack * does not have a '/home' route, use something you've built for your users * (again - users, not admins). * * @param [type] $user [description] * * @return bool [description] */ private function checkIfUserIsAdmin($user) { // return ($user->is_admin == 1); return true; } /** * Answer to unauthorized access request. * * @param [type] $request [description] * * @return [type] [description] */ private function respondToUnauthorizedRequest($request) { if ($request->ajax() || $request->wantsJson()) { return response(trans('backpack::base.unauthorized'), 401); } else { return redirect()->guest(backpack_url('login')); } } /** * Handle an incoming request. * * @param \Illuminate\Http\Request $request * @param \Closure $next * * @return mixed */ public function handle($request, Closure $next) { if (backpack_auth()->guest()) { return $this->respondToUnauthorizedRequest($request); } if (! $this->checkIfUserIsAdmin(backpack_user())) { return $this->respondToUnauthorizedRequest($request); } return $next($request); } }