1 | <?php namespace Arcanedev\LaravelAuth\Models; |
||
40 | class User extends Authenticatable implements UserContract |
||
|
|||
41 | { |
||
42 | /* ------------------------------------------------------------------------------------------------ |
||
43 | | Traits |
||
44 | | ------------------------------------------------------------------------------------------------ |
||
45 | */ |
||
46 | use AuthUserTrait, Activatable, SoftDeletes; |
||
47 | |||
48 | /* ------------------------------------------------------------------------------------------------ |
||
49 | | Properties |
||
50 | | ------------------------------------------------------------------------------------------------ |
||
51 | */ |
||
52 | /** |
||
53 | * The attributes that are mass assignable. |
||
54 | * |
||
55 | * @var array |
||
56 | */ |
||
57 | protected $fillable = [ |
||
58 | 'username', 'first_name', 'last_name', 'email', 'password', |
||
59 | ]; |
||
60 | |||
61 | /** |
||
62 | * The attributes excluded from the model's JSON form. |
||
63 | * |
||
64 | * @var array |
||
65 | */ |
||
66 | protected $hidden = [ |
||
67 | 'password', 'remember_token', 'confirmation_code', |
||
68 | ]; |
||
69 | |||
70 | /** |
||
71 | * The attributes that should be casted to native types. |
||
72 | * |
||
73 | * @var array |
||
74 | */ |
||
75 | protected $casts = [ |
||
76 | 'is_admin' => 'boolean', |
||
77 | 'is_active' => 'boolean', |
||
78 | 'is_confirmed' => 'boolean', |
||
79 | ]; |
||
80 | |||
81 | /** |
||
82 | * The attributes that should be mutated to dates. |
||
83 | * |
||
84 | * @var array |
||
85 | */ |
||
86 | protected $dates = [ |
||
87 | 'confirmed_at', 'deleted_at' |
||
88 | ]; |
||
89 | |||
90 | /* ------------------------------------------------------------------------------------------------ |
||
91 | | Constructor |
||
92 | | ------------------------------------------------------------------------------------------------ |
||
93 | */ |
||
94 | /** |
||
95 | * Create a new Eloquent model instance. |
||
96 | * |
||
97 | * @param array $attributes |
||
98 | */ |
||
99 | public function __construct(array $attributes = []) |
||
105 | |||
106 | 528 | /* ------------------------------------------------------------------------------------------------ |
|
107 | | Scopes |
||
108 | 528 | | ------------------------------------------------------------------------------------------------ |
|
109 | */ |
||
110 | 528 | /** |
|
111 | 528 | * Scope unconfirmed users by code. |
|
112 | * |
||
113 | * @param \Illuminate\Database\Eloquent\Builder $query |
||
114 | * @param string $code |
||
115 | * |
||
116 | * @return \Illuminate\Database\Eloquent\Builder |
||
117 | */ |
||
118 | public function scopeUnconfirmed($query, $code) |
||
124 | |||
125 | 32 | /* ------------------------------------------------------------------------------------------------ |
|
126 | | Getters & Setters |
||
127 | 32 | | ------------------------------------------------------------------------------------------------ |
|
128 | 32 | */ |
|
129 | 32 | /** |
|
130 | * Set the `username` attribute. |
||
131 | * |
||
132 | * @param string $username |
||
133 | */ |
||
134 | public function setUsernameAttribute($username) |
||
138 | |||
139 | /** |
||
140 | * Get the `full_name` attribute. |
||
141 | 8 | * |
|
142 | * @return string |
||
143 | 8 | */ |
|
144 | public function getFullNameAttribute() |
||
148 | |||
149 | /** |
||
150 | * Set the `password` attribute. |
||
151 | 160 | * |
|
152 | * @param string $password |
||
153 | 160 | */ |
|
154 | 160 | public function setPasswordAttribute($password) |
|
158 | |||
159 | /* ------------------------------------------------------------------------------------------------ |
||
160 | | CRUD Functions |
||
161 | | ------------------------------------------------------------------------------------------------ |
||
162 | */ |
||
163 | /** |
||
164 | * Confirm the unconfirmed user account by confirmation code. |
||
165 | * |
||
166 | * @param string $code |
||
167 | * |
||
168 | * @return \Arcanesoft\Contracts\Auth\Models\User |
||
169 | 32 | * |
|
170 | * @throws \Arcanedev\LaravelAuth\Exceptions\UserConfirmationException |
||
171 | 32 | */ |
|
172 | public function findUnconfirmed($code) |
||
181 | |||
182 | /** |
||
183 | * Confirm the new user account. |
||
184 | * |
||
185 | * @param \Arcanesoft\Contracts\Auth\Models\User|string $code |
||
186 | * |
||
187 | 16 | * @return \Arcanesoft\Contracts\Auth\Models\User |
|
188 | */ |
||
189 | 16 | public function confirm($code) |
|
198 | |||
199 | /* ------------------------------------------------------------------------------------------------ |
||
200 | | Check Functions |
||
201 | | ------------------------------------------------------------------------------------------------ |
||
202 | */ |
||
203 | /** |
||
204 | * Check if user is an administrator. |
||
205 | * |
||
206 | * @return bool |
||
207 | 40 | */ |
|
208 | public function isAdmin() |
||
212 | |||
213 | /** |
||
214 | * Check if user is a moderator. |
||
215 | * |
||
216 | * @return bool |
||
217 | 24 | */ |
|
218 | public function isModerator() |
||
223 | |||
224 | /** |
||
225 | * Check if user is a member. |
||
226 | * |
||
227 | 16 | * @return bool |
|
228 | */ |
||
229 | 16 | public function isMember() |
|
233 | |||
234 | /** |
||
235 | * Check if user has a confirmed account. |
||
236 | * |
||
237 | * @return bool |
||
238 | */ |
||
239 | public function isConfirmed() |
||
243 | |||
244 | /** |
||
245 | * Check if user is on force deleting. |
||
246 | * |
||
247 | * @return bool |
||
248 | */ |
||
249 | public function isForceDeleting() |
||
253 | |||
254 | /* ------------------------------------------------------------------------------------------------ |
||
255 | | Other Functions |
||
256 | | ------------------------------------------------------------------------------------------------ |
||
257 | */ |
||
258 | /** |
||
259 | * Slugify the value. |
||
260 | * |
||
261 | * @param string $value |
||
262 | * |
||
263 | * @return string |
||
264 | */ |
||
265 | protected function slugify($value) |
||
269 | } |
||
270 |