Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
L
laravel-adminpanel
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Administrator
laravel-adminpanel
Commits
6aff3764
Commit
6aff3764
authored
Mar 15, 2018
by
Viral Solani
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add authorization exception
parent
f8026b32
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
17 additions
and
4 deletions
+17
-4
Handler.php
app/Exceptions/Handler.php
+6
-0
UsersController.php
app/Http/Controllers/Api/V1/UsersController.php
+5
-4
Request.php
app/Http/Requests/Request.php
+6
-0
No files found.
app/Exceptions/Handler.php
View file @
6aff3764
...
...
@@ -11,6 +11,7 @@ use Illuminate\Validation\ValidationException;
use
Symfony\Component\HttpKernel\Exception\MethodNotAllowedHttpException
;
use
Symfony\Component\HttpKernel\Exception\NotFoundHttpException
;
use
Symfony\Component\HttpKernel\Exception\UnauthorizedHttpException
;
use
Illuminate\Auth\Access\AuthorizationException
;
class
Handler
extends
ExceptionHandler
{
...
...
@@ -52,9 +53,14 @@ class Handler extends ExceptionHandler
*/
public
function
render
(
$request
,
Exception
$exception
)
{
//dd($exception);
if
(
strpos
(
$request
->
url
(),
'/api/'
)
!==
false
)
{
\Log
::
debug
(
'API Request Exception - '
.
$request
->
url
()
.
' - '
.
$exception
->
getMessage
()
.
(
!
empty
(
$request
->
all
())
?
' - '
.
json_encode
(
$request
->
except
([
'password'
]))
:
''
));
if
(
$exception
instanceof
AuthorizationException
)
{
return
$this
->
setStatusCode
(
403
)
->
respondWithError
(
$exception
->
getMessage
());
}
if
(
$exception
instanceof
MethodNotAllowedHttpException
)
{
return
$this
->
setStatusCode
(
403
)
->
respondWithError
(
'Please check HTTP Request Method. - MethodNotAllowedHttpException'
);
}
...
...
app/Http/Controllers/Api/V1/UsersController.php
View file @
6aff3764
...
...
@@ -2,11 +2,12 @@
namespace
App\Http\Controllers\Api\V1
;
use
App\Http\Resources\UserResource
;
use
Validator
;
use
Illuminate\Http\Request
;
use
App\Models\Access\User\User
;
use
App\Http\Resources\UserResource
;
use
App\Repositories\Backend\Access\User\UserRepository
;
use
Illuminate\Http\Request
;
use
Validator
;
use
App\Http\Requests\Backend\Access\User\ManageUserRequest
;
class
UsersController
extends
APIController
{
...
...
@@ -29,7 +30,7 @@ class UsersController extends APIController
*
* @return \Illuminate\Http\JsonResponse
*/
public
function
index
(
Request
$request
)
public
function
index
(
ManageUser
Request
$request
)
{
$limit
=
$request
->
get
(
'paginate'
)
?
$request
->
get
(
'paginate'
)
:
25
;
...
...
app/Http/Requests/Request.php
View file @
6aff3764
...
...
@@ -3,6 +3,7 @@
namespace
App\Http\Requests
;
use
Illuminate\Foundation\Http\FormRequest
;
use
Illuminate\Auth\Access\AuthorizationException
;
/**
* Class Request.
...
...
@@ -25,4 +26,9 @@ abstract class Request extends FormRequest
return
redirect
()
->
back
()
->
withErrors
(
$this
->
error
);
}
protected
function
failedAuthorization
()
{
throw
new
AuthorizationException
(
'This action is unauthorized.'
);
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment