1 | <?php namespace Arcanedev\LaravelAuth\Models; |
||
46 | class User |
||
|
|||
47 | extends Model |
||
48 | implements AuthenticatableContract, AuthorizableContract, CanResetPasswordContract, UserContract |
||
49 | { |
||
50 | /* ------------------------------------------------------------------------------------------------ |
||
51 | | Traits |
||
52 | | ------------------------------------------------------------------------------------------------ |
||
53 | */ |
||
54 | use Activatable, Authenticatable, Authorizable, AuthUserTrait, CanResetPassword, SoftDeletes; |
||
55 | |||
56 | /* ------------------------------------------------------------------------------------------------ |
||
57 | | Properties |
||
58 | | ------------------------------------------------------------------------------------------------ |
||
59 | */ |
||
60 | /** |
||
61 | * The attributes that are mass assignable. |
||
62 | * |
||
63 | * @var array |
||
64 | */ |
||
65 | protected $fillable = [ |
||
66 | 'username', 'first_name', 'last_name', 'email', 'password', |
||
67 | ]; |
||
68 | |||
69 | /** |
||
70 | * The attributes excluded from the model's JSON form. |
||
71 | * |
||
72 | * @var array |
||
73 | */ |
||
74 | protected $hidden = [ |
||
75 | 'password', 'remember_token', 'confirmation_code', |
||
76 | ]; |
||
77 | |||
78 | /** |
||
79 | * The attributes that should be casted to native types. |
||
80 | * |
||
81 | * @var array |
||
82 | */ |
||
83 | protected $casts = [ |
||
84 | 'is_admin' => 'boolean', |
||
85 | 'is_active' => 'boolean', |
||
86 | 'is_confirmed' => 'boolean', |
||
87 | ]; |
||
88 | |||
89 | /** |
||
90 | * The attributes that should be mutated to dates. |
||
91 | * |
||
92 | * @var array |
||
93 | */ |
||
94 | protected $dates = [ |
||
95 | 'confirmed_at', 'deleted_at' |
||
96 | ]; |
||
97 | |||
98 | /* ------------------------------------------------------------------------------------------------ |
||
99 | | Constructor |
||
100 | | ------------------------------------------------------------------------------------------------ |
||
101 | */ |
||
102 | /** |
||
103 | * Create a new Eloquent model instance. |
||
104 | * |
||
105 | * @param array $attributes |
||
106 | 528 | */ |
|
107 | public function __construct(array $attributes = []) |
||
113 | |||
114 | /* ------------------------------------------------------------------------------------------------ |
||
115 | | Scopes |
||
116 | | ------------------------------------------------------------------------------------------------ |
||
117 | */ |
||
118 | /** |
||
119 | * Scope unconfirmed users by code. |
||
120 | * |
||
121 | * @param \Illuminate\Database\Eloquent\Builder $query |
||
122 | * @param string $code |
||
123 | * |
||
124 | * @return \Illuminate\Database\Eloquent\Builder |
||
125 | 32 | */ |
|
126 | public function scopeUnconfirmed($query, $code) |
||
132 | |||
133 | /* ------------------------------------------------------------------------------------------------ |
||
134 | | Getters & Setters |
||
135 | | ------------------------------------------------------------------------------------------------ |
||
136 | */ |
||
137 | /** |
||
138 | * Set the `username` attribute. |
||
139 | * |
||
140 | * @param string $username |
||
141 | 8 | */ |
|
142 | public function setUsernameAttribute($username) |
||
151 | 160 | ||
152 | /** |
||
153 | 160 | * Get the `full_name` attribute. |
|
154 | 160 | * |
|
155 | * @return string |
||
156 | */ |
||
157 | public function getFullNameAttribute() |
||
161 | |||
162 | /** |
||
163 | * Set the `password` attribute. |
||
164 | * |
||
165 | * @param string $password |
||
166 | */ |
||
167 | public function setPasswordAttribute($password) |
||
171 | 32 | ||
172 | /* ------------------------------------------------------------------------------------------------ |
||
173 | 32 | | CRUD Functions |
|
174 | 8 | | ------------------------------------------------------------------------------------------------ |
|
175 | */ |
||
176 | /** |
||
177 | 24 | * Confirm the unconfirmed user account by confirmation code. |
|
178 | * |
||
179 | * @param string $code |
||
180 | * |
||
181 | * @return \Arcanesoft\Contracts\Auth\Models\User |
||
182 | * |
||
183 | * @throws \Arcanedev\LaravelAuth\Exceptions\UserConfirmationException |
||
184 | */ |
||
185 | public function findUnconfirmed($code) |
||
195 | 16 | ||
196 | /** |
||
197 | * Confirm the new user account. |
||
198 | * |
||
199 | * @param \Arcanesoft\Contracts\Auth\Models\User|string $code |
||
200 | * |
||
201 | * @return \Arcanesoft\Contracts\Auth\Models\User |
||
202 | */ |
||
203 | public function confirm($code) |
||
213 | |||
214 | /* ------------------------------------------------------------------------------------------------ |
||
215 | | Check Functions |
||
216 | | ------------------------------------------------------------------------------------------------ |
||
217 | 24 | */ |
|
218 | /** |
||
219 | 24 | * Check if user is an administrator. |
|
220 | * |
||
221 | * @return bool |
||
222 | */ |
||
223 | public function isAdmin() |
||
227 | 16 | ||
228 | /** |
||
229 | 16 | * Check if user is a moderator. |
|
230 | * |
||
231 | * @return bool |
||
232 | */ |
||
233 | public function isModerator() |
||
238 | |||
239 | /** |
||
240 | * Check if user is a member. |
||
241 | * |
||
242 | * @return bool |
||
243 | */ |
||
244 | public function isMember() |
||
248 | |||
249 | /** |
||
250 | * Check if user has a confirmed account. |
||
251 | * |
||
252 | * @return bool |
||
253 | */ |
||
254 | public function isConfirmed() |
||
258 | |||
259 | /** |
||
260 | * Check if user is on force deleting. |
||
261 | * |
||
262 | * @return bool |
||
263 | */ |
||
264 | public function isForceDeleting() |
||
268 | } |
||
269 |