|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace App\Models; |
|
4
|
|
|
|
|
5
|
|
|
use Illuminate\Foundation\Auth\User as Authenticatable; |
|
6
|
|
|
|
|
7
|
|
|
/** |
|
8
|
|
|
* @property string $username |
|
9
|
|
|
* @property string $realname |
|
10
|
|
|
* @property string $password |
|
11
|
|
|
* @property string $email |
|
12
|
|
|
* @property int $level |
|
13
|
|
|
*/ |
|
14
|
|
|
class User extends Authenticatable |
|
15
|
|
|
{ |
|
16
|
|
|
/** |
|
17
|
|
|
* The attributes that are mass assignable. |
|
18
|
|
|
* |
|
19
|
|
|
* @var array |
|
20
|
|
|
*/ |
|
21
|
|
|
protected $fillable = [ |
|
22
|
|
|
'realname', 'username', 'password', 'email', 'level', |
|
23
|
|
|
]; |
|
24
|
|
|
protected $primaryKey = 'user_id'; |
|
25
|
|
|
|
|
26
|
|
|
/** |
|
27
|
|
|
* The attributes excluded from the model's JSON form. |
|
28
|
|
|
* |
|
29
|
|
|
* @var array |
|
30
|
|
|
*/ |
|
31
|
|
|
protected $hidden = [ |
|
32
|
|
|
'password', 'remember_token', |
|
33
|
|
|
]; |
|
34
|
|
|
|
|
35
|
|
|
|
|
36
|
|
|
// ---- Define Convience Functions ---- |
|
37
|
|
|
|
|
38
|
|
|
/** |
|
39
|
|
|
* Test if the User is an admin or demo. |
|
40
|
|
|
* |
|
41
|
|
|
* @return boolean |
|
42
|
|
|
*/ |
|
43
|
6 |
|
public function isAdmin() |
|
44
|
|
|
{ |
|
45
|
6 |
|
return $this->level >= 10; |
|
46
|
|
|
} |
|
47
|
|
|
|
|
48
|
|
|
/** |
|
49
|
|
|
* Test if this user has global read access |
|
50
|
|
|
* these users have a level of 5, 10 or 11 (demo). |
|
51
|
|
|
* |
|
52
|
|
|
* @return boolean |
|
53
|
|
|
*/ |
|
54
|
6 |
|
public function hasGlobalRead() |
|
55
|
|
|
{ |
|
56
|
6 |
|
return $this->isAdmin() || $this->level == 5; |
|
57
|
|
|
} |
|
58
|
|
|
|
|
59
|
|
|
|
|
60
|
|
|
// ---- Define Reletionships ---- |
|
61
|
|
|
|
|
62
|
|
|
/** |
|
63
|
|
|
* Returns a list of devices this user has access to |
|
64
|
|
|
*/ |
|
65
|
4 |
|
public function devices() { |
|
66
|
4 |
|
return $this->belongsToMany('App\Models\Device', 'devices_perms', 'user_id', 'device_id'); |
|
67
|
|
|
} |
|
68
|
|
|
|
|
69
|
|
|
/** |
|
70
|
|
|
* Returns a list of ports this user has access to |
|
71
|
|
|
*/ |
|
72
|
2 |
|
public function ports() { |
|
73
|
2 |
|
return $this->belongsToMany('App\Models\Port', 'ports_perms', 'user_id', 'port_id'); |
|
74
|
|
|
} |
|
75
|
|
|
|
|
76
|
|
|
/** |
|
77
|
|
|
* Returns a list of dashboards this user has access to |
|
78
|
|
|
*/ |
|
79
|
|
|
public function dashboards() { |
|
80
|
|
|
return $this->hasMany('App\Models\Dashboard'); |
|
81
|
|
|
} |
|
82
|
|
|
} |
|
83
|
|
|
|