From: Vincent Vanwaelscappel Date: Mon, 11 Feb 2019 16:30:30 +0000 (+0100) Subject: wip #2562 @0.5 X-Git-Url: http://git.cubedesigners.com/?a=commitdiff_plain;h=0ff98c479025e293cfc7ed52ae687ca863e7a644;p=pmi.git wip #2562 @0.5 --- diff --git a/app/Http/Middleware/CheckIfAdmin.php b/app/Http/Middleware/CheckIfAdmin.php new file mode 100644 index 0000000..f39a48e --- /dev/null +++ b/app/Http/Middleware/CheckIfAdmin.php @@ -0,0 +1,65 @@ +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); + } +} diff --git a/app/Models/BackpackUser.php b/app/Models/BackpackUser.php new file mode 100644 index 0000000..e27c646 --- /dev/null +++ b/app/Models/BackpackUser.php @@ -0,0 +1,36 @@ +notify(new ResetPasswordNotification($token)); + } + + /** + * Get the e-mail address where password reset links are sent. + * + * @return string + */ + public function getEmailForPasswordReset() + { + return $this->email; + } +}