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'
|
'password' => 'required|min:6|max:32'
|
||||||
]);
|
]);
|
||||||
|
|
||||||
|
if ($user->isAdmin())
|
||||||
|
return json(trans('user.profile.delete.admin'), 1);
|
||||||
|
|
||||||
if (! $user->verifyPassword($request->input('password')))
|
if (! $user->verifyPassword($request->input('password')))
|
||||||
return json(trans('user.profile.delete.wrong-password'), 1);
|
return json(trans('user.profile.delete.wrong-password'), 1);
|
||||||
|
|
||||||
Auth::logout();
|
Auth::logout();
|
||||||
|
|
||||||
if ($user->delete()) {
|
if ($user->delete()) {
|
||||||
session()->flush();
|
session()->flush();
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -382,6 +382,16 @@ class UserControllerTest extends TestCase
|
||||||
'msg' => trans('user.profile.delete.success')
|
'msg' => trans('user.profile.delete.success')
|
||||||
]);
|
]);
|
||||||
$this->assertNull(User::find($user->uid));
|
$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()
|
public function testSetAvatar()
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user