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
23b20325
Commit
23b20325
authored
Mar 14, 2018
by
Viral Solani
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
delete all api for user
refactor exception handeling
parent
191033ca
Changes
7
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
74 additions
and
79 deletions
+74
-79
Handler.php
app/Exceptions/Handler.php
+30
-55
UsersController.php
app/Http/Controllers/Api/V1/UsersController.php
+14
-2
User.php
app/Models/Access/User/User.php
+0
-1
UserRepository.php
app/Repositories/Backend/Access/User/UserRepository.php
+14
-5
admin.js
public/js/backend/admin.js
+13
-14
exceptions.php
resources/lang/en/exceptions.php
+1
-0
api.php
routes/api.php
+2
-2
No files found.
app/Exceptions/Handler.php
View file @
23b20325
...
@@ -51,61 +51,6 @@ class Handler extends ExceptionHandler
...
@@ -51,61 +51,6 @@ class Handler extends ExceptionHandler
*/
*/
public
function
render
(
$request
,
Exception
$exception
)
public
function
render
(
$request
,
Exception
$exception
)
{
{
/*
* Redirect if token mismatch error
* Usually because user stayed on the same screen too long and their session expired
*/
if
(
$exception
instanceof
\Symfony\Component\HttpKernel\Exception\UnauthorizedHttpException
)
{
switch
(
get_class
(
$exception
->
getPrevious
()))
{
case
\App\Exceptions\Handler
::
class
:
return
response
()
->
json
([
'status'
=>
'error'
,
'error'
=>
'Token has not been provided'
,
'data'
=>
json_decode
(
'{}'
),
],
$exception
->
getStatusCode
());
case
\Tymon\JWTAuth\Exceptions\TokenExpiredException
::
class
:
return
response
()
->
json
([
'status'
=>
'error'
,
'error'
=>
'Token has expired'
,
'data'
=>
json_decode
(
'{}'
),
],
$exception
->
getStatusCode
());
case
\Tymon\JWTAuth\Exceptions\TokenInvalidException
::
class
:
case
\Tymon\JWTAuth\Exceptions\TokenBlacklistedException
::
class
:
return
response
()
->
json
([
'status'
=>
'error'
,
'error'
=>
'Token is invalid'
,
'data'
=>
json_decode
(
'{}'
),
],
$exception
->
getStatusCode
());
default
:
break
;
}
}
/*
* Redirect if token mismatch error
* Usually because user stayed on the same screen too long and their session expired
*/
if
(
$exception
instanceof
TokenMismatchException
)
{
return
redirect
()
->
route
(
'frontend.auth.login'
);
}
/*
* All instances of GeneralException redirect back with a flash message to show a bootstrap alert-error
*/
if
(
$exception
instanceof
GeneralException
)
{
//Note:Below code is required when we use an extra class as api request then we need to pass accept:application/json in the header also
//if the header has accept application/json then $request->wantsJson() returns true
// if ($request->ajax() || $request->wantsJson()){
// $json = [
// 'success' => false,
// 'error' => [
// 'message' => $exception->getMessage(),
// ],
// ];
// return response()->json($json, 400);
// }
return
redirect
()
->
back
()
->
withInput
()
->
withFlashDanger
(
$exception
->
getMessage
());
}
if
(
strpos
(
$request
->
url
(),
'/api/'
)
!==
false
)
{
if
(
strpos
(
$request
->
url
(),
'/api/'
)
!==
false
)
{
\Log
::
debug
(
'API Request Exception - '
.
$request
->
url
()
.
' - '
.
$exception
->
getMessage
()
.
(
!
empty
(
$request
->
all
())
?
' - '
.
json_encode
(
$request
->
except
([
'password'
]))
:
''
));
\Log
::
debug
(
'API Request Exception - '
.
$request
->
url
()
.
' - '
.
$exception
->
getMessage
()
.
(
!
empty
(
$request
->
all
())
?
' - '
.
json_encode
(
$request
->
except
([
'password'
]))
:
''
));
...
@@ -131,6 +76,36 @@ class Handler extends ExceptionHandler
...
@@ -131,6 +76,36 @@ class Handler extends ExceptionHandler
return
$this
->
setStatusCode
(
422
)
->
respondWithError
(
$exception
->
validator
->
messages
());
return
$this
->
setStatusCode
(
422
)
->
respondWithError
(
$exception
->
validator
->
messages
());
}
}
}
}
/*
* Redirect if token mismatch error
* Usually because user stayed on the same screen too long and their session expired
*/
if
(
$exception
instanceof
\Symfony\Component\HttpKernel\Exception\UnauthorizedHttpException
)
{
switch
(
get_class
(
$exception
->
getPrevious
()))
{
case
\App\Exceptions\Handler
::
class
:
return
$this
->
setStatusCode
(
$exception
->
getStatusCode
())
->
respondWithError
(
'Token has not been provided.'
);
case
\Tymon\JWTAuth\Exceptions\TokenExpiredException
::
class
:
return
$this
->
setStatusCode
(
$exception
->
getStatusCode
())
->
respondWithError
(
'Token has expired.'
);
case
\Tymon\JWTAuth\Exceptions\TokenInvalidException
::
class
:
case
\Tymon\JWTAuth\Exceptions\TokenBlacklistedException
::
class
:
return
$this
->
setStatusCode
(
$exception
->
getStatusCode
())
->
respondWithError
(
'Token is invalid.'
);
}
}
/*
* Redirect if token mismatch error
* Usually because user stayed on the same screen too long and their session expired
*/
if
(
$exception
instanceof
TokenMismatchException
)
{
return
redirect
()
->
route
(
'frontend.auth.login'
);
}
/*
* All instances of GeneralException redirect back with a flash message to show a bootstrap alert-error
*/
if
(
$exception
instanceof
GeneralException
)
{
return
redirect
()
->
back
()
->
withInput
()
->
withFlashDanger
(
$exception
->
getMessage
());
}
return
parent
::
render
(
$request
,
$exception
);
return
parent
::
render
(
$request
,
$exception
);
}
}
...
...
app/Http/Controllers/Api/V1/UsersController.php
View file @
23b20325
...
@@ -117,12 +117,24 @@ class UsersController extends APIController
...
@@ -117,12 +117,24 @@ class UsersController extends APIController
*
*
* @return mixed
* @return mixed
*/
*/
public
function
delteAll
(
Request
$request
)
public
function
del
e
teAll
(
Request
$request
)
{
{
$ids
=
$request
->
get
(
'ids'
);
$ids
=
$request
->
get
(
'ids'
);
if
(
isset
(
$ids
)
&&
!
empty
(
$ids
))
{
if
(
isset
(
$ids
)
&&
!
empty
(
$ids
))
{
$this
->
repository
->
deleteAll
(
$ids
);
$result
=
$this
->
repository
->
deleteAll
(
$ids
);
}
if
(
$result
)
{
return
$this
->
respond
([
'message'
=>
trans
(
'alerts.backend.users.deleted'
),
]);
}
}
return
$this
->
respond
([
'message'
=>
trans
(
'exceptions.backend.access.users.not_found'
),
]);
}
}
/**
/**
...
...
app/Models/Access/User/User.php
View file @
23b20325
...
@@ -40,7 +40,6 @@ class User extends Authenticatable implements JWTSubject
...
@@ -40,7 +40,6 @@ class User extends Authenticatable implements JWTSubject
'first_name'
,
'first_name'
,
'last_name'
,
'last_name'
,
'email'
,
'email'
,
'password'
,
'status'
,
'status'
,
'confirmation_code'
,
'confirmation_code'
,
'confirmed'
,
'confirmed'
,
...
...
app/Repositories/Backend/Access/User/UserRepository.php
View file @
23b20325
...
@@ -189,7 +189,7 @@ class UserRepository extends BaseRepository
...
@@ -189,7 +189,7 @@ class UserRepository extends BaseRepository
}
}
/**
/**
* Delete User
.
* Delete User
*
*
* @param Model $user
* @param Model $user
*
*
...
@@ -213,9 +213,9 @@ class UserRepository extends BaseRepository
...
@@ -213,9 +213,9 @@ class UserRepository extends BaseRepository
}
}
/**
/**
* Delete All User
.
* Delete All User
s
*
*
* @param
$ids
* @param
Model $user
*
*
* @throws GeneralException
* @throws GeneralException
*
*
...
@@ -227,9 +227,18 @@ class UserRepository extends BaseRepository
...
@@ -227,9 +227,18 @@ class UserRepository extends BaseRepository
throw
new
GeneralException
(
trans
(
'exceptions.backend.access.users.cant_delete_self'
));
throw
new
GeneralException
(
trans
(
'exceptions.backend.access.users.cant_delete_self'
));
}
}
$result
=
DB
::
table
(
'users'
)
->
whereIn
(
'id'
,
explode
(
','
,
$ids
))
->
delete
();
if
(
in_array
(
1
,
$ids
))
{
throw
new
GeneralException
(
trans
(
'exceptions.backend.access.users.cant_delete_admin'
));
}
$result
=
DB
::
table
(
'users'
)
->
whereIn
(
'id'
,
$ids
)
->
delete
();
if
(
$result
)
{
return
true
;
}
dd
(
$result
)
;
return
false
;
}
}
/**
/**
...
...
public/js/backend/admin.js
View file @
23b20325
...
@@ -110,11 +110,9 @@ var Backend = {}; // common variable used in all the files of the backend
...
@@ -110,11 +110,9 @@ var Backend = {}; // common variable used in all the files of the backend
associated_container
:
document
.
getElementById
(
"
#available-permissions
"
),
associated_container
:
document
.
getElementById
(
"
#available-permissions
"
),
},
},
init
(
page
)
{
init
(
page
)
{
this
.
setSelectors
();
this
.
setSelectors
();
this
.
setRolepermission
(
page
);
this
.
setRolepermission
(
page
);
this
.
addHandlers
();
this
.
addHandlers
();
},
},
setSelectors
:
function
()
{
setSelectors
:
function
()
{
this
.
selectors
.
associated
=
document
.
querySelector
(
"
select[name='associated_permissions']
"
);
this
.
selectors
.
associated
=
document
.
querySelector
(
"
select[name='associated_permissions']
"
);
...
@@ -477,17 +475,17 @@ var Backend = {}; // common variable used in all the files of the backend
...
@@ -477,17 +475,17 @@ var Backend = {}; // common variable used in all the files of the backend
*/
*/
Faq
:
Faq
:
{
{
selectors
:
selectors
:
{
{
},
},
init
:
function
()
{
init
:
function
()
{
// this.addHandlers();
// this.addHandlers();
Backend
.
tinyMCE
.
init
();
Backend
.
tinyMCE
.
init
();
},
},
addHandlers
:
function
()
{
addHandlers
:
function
()
{
}
}
},
},
/**
/**
...
@@ -515,7 +513,6 @@ var Backend = {}; // common variable used in all the files of the backend
...
@@ -515,7 +513,6 @@ var Backend = {}; // common variable used in all the files of the backend
if
(
this
.
selectors
.
cities
!=
null
)
{
if
(
this
.
selectors
.
cities
!=
null
)
{
this
.
selectors
.
cities
.
select2
();
this
.
selectors
.
cities
.
select2
();
}
}
}
}
},
},
...
@@ -622,6 +619,10 @@ var Backend = {}; // common variable used in all the files of the backend
...
@@ -622,6 +619,10 @@ var Backend = {}; // common variable used in all the files of the backend
},
},
/**
* Settings
*
*/
Settings
:
Settings
:
{
{
selectors
:
{
selectors
:
{
...
@@ -678,9 +679,7 @@ var Backend = {}; // common variable used in all the files of the backend
...
@@ -678,9 +679,7 @@ var Backend = {}; // common variable used in all the files of the backend
Backend
.
Utils
.
ajaxrequest
(
route
,
"
POST
"
,
{
data
:
value
,
_token
:
Backend
.
Utils
.
csrf
},
Backend
.
Utils
.
csrf
,
callback
);
Backend
.
Utils
.
ajaxrequest
(
route
,
"
POST
"
,
{
data
:
value
,
_token
:
Backend
.
Utils
.
csrf
},
Backend
.
Utils
.
csrf
,
callback
);
}
}
});
});
};
};
}
}
}
}
};
};
...
...
resources/lang/en/exceptions.php
View file @
23b20325
...
@@ -37,6 +37,7 @@ return [
...
@@ -37,6 +37,7 @@ return [
'users'
=>
[
'users'
=>
[
'cant_deactivate_self'
=>
'You can not do that to yourself.'
,
'cant_deactivate_self'
=>
'You can not do that to yourself.'
,
'cant_delete_self'
=>
'You can not delete yourself.'
,
'cant_delete_self'
=>
'You can not delete yourself.'
,
'cant_delete_admin'
=>
'You can not delete Admin.'
,
'cant_delete_own_session'
=>
'You can not delete your own session.'
,
'cant_delete_own_session'
=>
'You can not delete your own session.'
,
'cant_delete_own_session'
=>
'You can not delete your own session.'
,
'cant_delete_own_session'
=>
'You can not delete your own session.'
,
'cant_restore'
=>
'This user is not deleted so it can not be restored.'
,
'cant_restore'
=>
'This user is not deleted so it can not be restored.'
,
...
...
routes/api.php
View file @
23b20325
<?php
<?php
/*
/*
...
@@ -29,7 +29,7 @@ Route::group(['namespace' => 'Api\V1', 'prefix' => 'v1', 'as' => 'v1.'], functio
...
@@ -29,7 +29,7 @@ Route::group(['namespace' => 'Api\V1', 'prefix' => 'v1', 'as' => 'v1.'], functio
});
});
// Users
// Users
Route
::
resource
(
'users'
,
'UsersController'
,
[
'except'
=>
[
'create'
,
'edit'
]]);
Route
::
resource
(
'users'
,
'UsersController'
,
[
'except'
=>
[
'create'
,
'edit'
]]);
Route
::
post
(
'users/delete-all'
,
'UsersController@delteAll'
);
Route
::
post
(
'users/delete-all'
,
'UsersController@del
e
teAll'
);
//@todo need to change the route name and related changes
//@todo need to change the route name and related changes
/*Route::get('deactivatedUsers', 'DeactivatedUsersController@index');
/*Route::get('deactivatedUsers', 'DeactivatedUsersController@index');
Route::get('deletedUsers', 'DeletedUsersController@index');*/
Route::get('deletedUsers', 'DeletedUsersController@index');*/
...
...
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