1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace DavideCasiraghi\LaravelEventsCalendar\Models; |
4
|
|
|
|
5
|
|
|
use Illuminate\Support\Facades\Auth; |
6
|
|
|
use Illuminate\Notifications\Notifiable; |
7
|
|
|
use Illuminate\Foundation\Auth\User as Authenticatable; |
8
|
|
|
|
9
|
|
|
class User extends Authenticatable |
10
|
|
|
{ |
11
|
|
|
/***************************************************************************/ |
12
|
|
|
/** |
13
|
|
|
* The table associated with the model. |
14
|
|
|
* |
15
|
|
|
* @var string |
16
|
|
|
*/ |
17
|
|
|
protected $table = 'users'; |
18
|
|
|
|
19
|
|
|
/***************************************************************************/ |
20
|
|
|
|
21
|
|
|
use Notifiable; |
|
|
|
|
22
|
|
|
|
23
|
|
|
/** |
24
|
|
|
* The attributes that are mass assignable. |
25
|
|
|
* |
26
|
|
|
* @var array |
27
|
|
|
*/ |
28
|
|
|
protected $fillable = [ |
29
|
|
|
'name', 'email', 'password', 'group', 'country_id', 'description', 'status', 'activation_code', 'accept_terms', |
30
|
|
|
]; |
31
|
|
|
|
32
|
|
|
/** |
33
|
|
|
* The attributes that should be hidden for arrays. |
34
|
|
|
* |
35
|
|
|
* @var array |
36
|
|
|
*/ |
37
|
|
|
protected $hidden = [ |
38
|
|
|
'password', 'remember_token', |
39
|
|
|
]; |
40
|
|
|
|
41
|
|
|
/* |
42
|
|
|
To recognize admin - https://laracasts.com/discuss/channels/laravel/user-admin-authentication |
43
|
|
|
*/ |
44
|
|
|
protected $casts = [ |
45
|
|
|
'group' => 'int', |
46
|
|
|
]; |
47
|
|
|
|
48
|
|
|
public function isSuperAdmin() |
49
|
|
|
{ |
50
|
|
|
if ($this->group == 1) { |
|
|
|
|
51
|
|
|
return true; |
52
|
|
|
} else { |
53
|
|
|
return false; |
54
|
|
|
} |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
public function isAdmin() |
58
|
|
|
{ |
59
|
|
|
if ($this->group == 2) { |
|
|
|
|
60
|
|
|
return true; |
61
|
|
|
} else { |
62
|
|
|
return false; |
63
|
|
|
} |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
/***************************************************************************/ |
67
|
|
|
|
68
|
|
|
/** |
69
|
|
|
* Return the user group string. |
70
|
|
|
* |
71
|
|
|
* @param \App\User $post |
|
|
|
|
72
|
|
|
* @return string $ret - the user role description string |
73
|
|
|
*/ |
74
|
|
|
public static function getUserGroupString($group_id) |
75
|
|
|
{ |
76
|
|
|
switch ($group_id) { |
77
|
|
|
case null: |
78
|
|
|
$ret = 'Manager'; |
79
|
|
|
break; |
80
|
|
|
|
81
|
|
|
case 2: |
82
|
|
|
$ret = 'Administrator'; |
83
|
|
|
break; |
84
|
|
|
|
85
|
|
|
case 1: |
86
|
|
|
$ret = 'Super Administrator'; |
87
|
|
|
break; |
88
|
|
|
} |
89
|
|
|
|
90
|
|
|
return $ret; |
|
|
|
|
91
|
|
|
} |
92
|
|
|
|
93
|
|
|
/***************************************************************************/ |
94
|
|
|
|
95
|
|
|
/** |
96
|
|
|
* Return true if the user is logged as super admin. |
97
|
|
|
* |
98
|
|
|
* @param none |
99
|
|
|
* @return string $ret - true if the user is super admin |
100
|
|
|
*/ |
101
|
|
|
public static function loggedAsSuperAdmin() |
102
|
|
|
{ |
103
|
|
|
$user = Auth::user(); |
104
|
|
|
if (! $user) { |
105
|
|
|
return false; |
106
|
|
|
} elseif ($user->group == 1) { |
|
|
|
|
107
|
|
|
return true; |
108
|
|
|
} else { |
109
|
|
|
return false; |
110
|
|
|
} |
111
|
|
|
} |
112
|
|
|
|
113
|
|
|
/***************************************************************************/ |
114
|
|
|
|
115
|
|
|
/** |
116
|
|
|
* Return true if the user is logged as admin. |
117
|
|
|
* |
118
|
|
|
* @param none |
119
|
|
|
* @return string $ret - true if the user is admin |
120
|
|
|
*/ |
121
|
|
|
public static function loggedAsAdmin() |
122
|
|
|
{ |
123
|
|
|
$user = Auth::user(); |
124
|
|
|
if (! $user) { |
125
|
|
|
return false; |
126
|
|
|
} elseif ($user->group == 2) { |
|
|
|
|
127
|
|
|
return true; |
128
|
|
|
} else { |
129
|
|
|
return false; |
130
|
|
|
} |
131
|
|
|
} |
132
|
|
|
} |
133
|
|
|
|