|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* CreateUser.php |
|
4
|
|
|
* |
|
5
|
|
|
* Authorize and validate requests to create users. |
|
6
|
|
|
* |
|
7
|
|
|
* This program is free software: you can redistribute it and/or modify |
|
8
|
|
|
* it under the terms of the GNU General Public License as published by |
|
9
|
|
|
* the Free Software Foundation, either version 3 of the License, or |
|
10
|
|
|
* (at your option) any later version. |
|
11
|
|
|
* |
|
12
|
|
|
* This program is distributed in the hope that it will be useful, |
|
13
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
14
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.See the |
|
15
|
|
|
* GNU General Public License for more details. |
|
16
|
|
|
* |
|
17
|
|
|
* You should have received a copy of the GNU General Public License |
|
18
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>. |
|
19
|
|
|
* |
|
20
|
|
|
* @package LibreNMS |
|
21
|
|
|
* @link http://librenms.org |
|
22
|
|
|
* @copyright 2016 Tony Murray |
|
23
|
|
|
* @author Tony Murray <[email protected]> |
|
24
|
|
|
*/ |
|
25
|
|
|
|
|
26
|
|
|
namespace App\Http\Requests; |
|
27
|
|
|
|
|
28
|
|
|
use Auth; |
|
29
|
|
|
|
|
30
|
|
|
class CreateUserRequest extends Request |
|
31
|
|
|
{ |
|
32
|
|
|
/** |
|
33
|
|
|
* Determine if the user is authorized to make this request. |
|
34
|
|
|
* |
|
35
|
|
|
* @return bool |
|
36
|
|
|
*/ |
|
37
|
|
|
public function authorize() |
|
38
|
|
|
{ |
|
39
|
|
|
if (Auth::user()->isAdmin()) { |
|
|
|
|
|
|
40
|
|
|
return true; |
|
41
|
|
|
} |
|
42
|
|
|
return false; |
|
43
|
|
|
} |
|
44
|
|
|
|
|
45
|
|
|
/** |
|
46
|
|
|
* Get the validation rules that apply to the request. |
|
47
|
|
|
* |
|
48
|
|
|
* @return array |
|
49
|
|
|
*/ |
|
50
|
|
|
public function rules() |
|
51
|
|
|
{ |
|
52
|
|
|
return [ |
|
53
|
|
|
'username' => 'required|unique:users|max:255', |
|
54
|
|
|
'email' => 'required|email|max:255', |
|
55
|
|
|
'realname' => 'required|max:255', |
|
56
|
|
|
'description' => 'max:255', |
|
57
|
|
|
'level' => 'required|numeric', |
|
58
|
|
|
'password' => 'required|min:8|max:255', |
|
59
|
|
|
'password_confirmation' => 'required|same:password', |
|
60
|
|
|
]; |
|
61
|
|
|
} |
|
62
|
|
|
} |
|
63
|
|
|
|