mirror of
https://github.com/bs-community/blessing-skin-server.git
synced 2024-12-03 05:50:25 +08:00
Disallow to delete administrator
This commit is contained in:
parent
7e72e3c01b
commit
5788fb93c1
@ -167,9 +167,14 @@ class UserController extends Controller
|
||||
'password' => 'required|min:6|max:32'
|
||||
]);
|
||||
|
||||
if ($user->isAdmin())
|
||||
return json(trans('user.profile.delete.admin'), 1);
|
||||
|
||||
if (! $user->verifyPassword($request->input('password')))
|
||||
return json(trans('user.profile.delete.wrong-password'), 1);
|
||||
|
||||
Auth::logout();
|
||||
|
||||
if ($user->delete()) {
|
||||
session()->flush();
|
||||
|
||||
|
@ -382,6 +382,16 @@ class UserControllerTest extends TestCase
|
||||
'msg' => trans('user.profile.delete.success')
|
||||
]);
|
||||
$this->assertNull(User::find($user->uid));
|
||||
|
||||
// Administrator cannot be deleted
|
||||
$this->actAs('admin')
|
||||
->postJson('/user/profile', [
|
||||
'action' => 'delete',
|
||||
'password' => '87654321'
|
||||
])->assertJson([
|
||||
'errno' => 1,
|
||||
'msg' => trans('user.profile.delete.admin')
|
||||
]);
|
||||
}
|
||||
|
||||
public function testSetAvatar()
|
||||
|
Loading…
Reference in New Issue
Block a user