|
1
|
|
|
<?php |
|
2
|
|
|
/* |
|
3
|
|
|
* Copyright (C) 2016 Paul Heinrichs <[email protected]> |
|
4
|
|
|
* This program is free software: you can redistribute it and/or modify |
|
5
|
|
|
* it under the terms of the GNU General Public License as published by |
|
6
|
|
|
* the Free Software Foundation, either version 3 of the License, or |
|
7
|
|
|
* (at your option) any later version. |
|
8
|
|
|
* |
|
9
|
|
|
* This program is distributed in the hope that it will be useful, |
|
10
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
11
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.See the |
|
12
|
|
|
* GNU General Public License for more details. |
|
13
|
|
|
* |
|
14
|
|
|
* You should have received a copy of the GNU General Public License |
|
15
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>. |
|
16
|
|
|
*/ |
|
17
|
|
|
|
|
18
|
|
|
/** |
|
19
|
|
|
* DeleteUser.php |
|
20
|
|
|
* |
|
21
|
|
|
* @package LibreNMS |
|
22
|
|
|
* @author Paul Heinrichs <[email protected]> |
|
23
|
|
|
* @copyright 2016 Paul Heinrichs |
|
24
|
|
|
* @license @license http://opensource.org/licenses/GPL-3.0 GNU Public License v3 or later |
|
25
|
|
|
*/ |
|
26
|
|
|
|
|
27
|
|
|
namespace App\Console\Commands; |
|
28
|
|
|
|
|
29
|
|
|
use App\Models\User; |
|
30
|
|
|
use Illuminate\Console\Command; |
|
31
|
|
|
|
|
32
|
|
|
class DeleteUser extends Command |
|
33
|
|
|
{ |
|
34
|
|
|
/** |
|
35
|
|
|
* The name and signature of the console command. |
|
36
|
|
|
* |
|
37
|
|
|
* @var string |
|
38
|
|
|
*/ |
|
39
|
|
|
protected $signature = 'user:delete |
|
40
|
|
|
{user : The user to search}'; |
|
41
|
|
|
|
|
42
|
|
|
/** |
|
43
|
|
|
* The console command description. |
|
44
|
|
|
* |
|
45
|
|
|
* @var string |
|
46
|
|
|
*/ |
|
47
|
|
|
protected $description = 'Remove a user'; |
|
48
|
|
|
|
|
49
|
|
|
/** |
|
50
|
|
|
* Create a new command instance. |
|
51
|
|
|
*/ |
|
52
|
|
|
public function __construct() |
|
53
|
|
|
{ |
|
54
|
|
|
parent::__construct(); |
|
55
|
|
|
} |
|
56
|
|
|
|
|
57
|
|
|
/** |
|
58
|
|
|
* Execute the console command. |
|
59
|
|
|
* |
|
60
|
|
|
* @return mixed |
|
61
|
|
|
*/ |
|
62
|
|
|
public function handle() |
|
63
|
|
|
{ |
|
64
|
|
|
$user = $this->argument('user'); |
|
65
|
|
|
$user_list = User::select('username')->where('username', 'like', '%'.$user.'%')->orWhere('realname', 'like', '%'.$user.'%')->get(); |
|
66
|
|
|
$names = []; |
|
67
|
|
|
|
|
68
|
|
|
if (count($user_list) < 1) { |
|
69
|
|
|
$this->info('No user found.'); |
|
70
|
|
|
return; |
|
71
|
|
|
} |
|
72
|
|
|
foreach ($user_list as $i) { |
|
73
|
|
|
array_push($names, $i->username); |
|
74
|
|
|
} |
|
75
|
|
|
if (count($names) > 1) { |
|
76
|
|
|
$name = $this->choice('Who would you like to remove?', $names); |
|
77
|
|
|
} |
|
78
|
|
|
else { |
|
79
|
|
|
$name = $names[0]; |
|
80
|
|
|
} |
|
81
|
|
|
if ($this->confirm('Do you wish to remove '.$name.'?')) { |
|
82
|
|
|
User::where('username', $name)->delete(); |
|
83
|
|
|
$this->info('User deleted.'); |
|
84
|
|
|
} |
|
85
|
|
|
} |
|
86
|
|
|
} |
|
87
|
|
|
|