1 | <?php |
||
23 | class User extends Model implements AuthenticatableContract, AuthorizableContract |
||
24 | { |
||
25 | use Authenticatable, Authorizable, Eloquence, Mappable; |
||
26 | |||
27 | /** |
||
28 | * Disable Timestamps. |
||
29 | * |
||
30 | * @var bool |
||
31 | */ |
||
32 | public $timestamps = false; |
||
33 | |||
34 | /** |
||
35 | * User Traits. |
||
36 | * |
||
37 | * @var array |
||
38 | */ |
||
39 | public $traits = ['USER']; |
||
40 | |||
41 | /** |
||
42 | * The table associated with the model. |
||
43 | * |
||
44 | * @var string |
||
45 | */ |
||
46 | protected $table = 'users'; |
||
47 | |||
48 | /** |
||
49 | * Primary Key of the Table. |
||
50 | * |
||
51 | * @var string |
||
52 | */ |
||
53 | protected $primaryKey = 'id'; |
||
54 | |||
55 | /** |
||
56 | * The attributes that will be mapped. |
||
57 | * |
||
58 | * @var array |
||
59 | */ |
||
60 | protected $maps = ['uniqueId' => 'id', 'name' => 'username', 'figureString' => 'look', 'lastWebAccess' => 'last_login', 'creationTime' => 'account_created', 'email' => 'mail', 'identityId' => 'id', 'accountId' => 'id']; |
||
61 | |||
62 | /** |
||
63 | * The Appender(s) of the Model. |
||
64 | * |
||
65 | * @var array |
||
66 | */ |
||
67 | protected $appends = ['habboClubMember', 'buildersClubMember', 'sessionLoginId', 'loginLogId', 'identityVerified', 'identityType', 'trusted', 'country', 'traits', |
||
68 | 'uniqueId', 'name', 'figureString', 'lastWebAccess', 'creationTime', 'email', 'identityId', 'emailVerified', 'accountId', 'memberSince', 'isBanned', 'banDetails', 'isStaff', 'realEmail', ]; |
||
69 | |||
70 | /** |
||
71 | * The attributes that are mass assignable. |
||
72 | * |
||
73 | * @var array |
||
74 | */ |
||
75 | protected $fillable = ['mail', 'id', 'username', 'auth_ticket', 'last_login', 'ip_current', 'ip_register', 'mail_verified', 'account_day_of_birth', |
||
76 | 'real_name', 'look', 'gender', 'credits', 'pixels', 'home_room', ]; |
||
77 | |||
78 | /** |
||
79 | * The attributes excluded from the model's JSON form. |
||
80 | * |
||
81 | * @var array |
||
82 | */ |
||
83 | protected $hidden = ['id', 'username', 'mail', 'account_created', 'password', 'mail_verified', 'real_name', 'account_day_of_birth', |
||
84 | 'last_online', 'last_login', 'ip_register', 'auth_ticket', 'home_room', 'points', 'look', 'ip_current', 'online', 'pixels', 'credits', 'gender', 'points', 'rank', ]; |
||
85 | |||
86 | /** |
||
87 | * The attributes that should be casted to native types. |
||
88 | * |
||
89 | * @var array |
||
90 | */ |
||
91 | protected $casts = ['traits' => 'string']; |
||
92 | |||
93 | /** |
||
94 | * Store an User on the Database. |
||
95 | * |
||
96 | * @param string $username |
||
97 | * @param string $email |
||
98 | * @param string $address |
||
99 | * @param bool $newUser |
||
100 | * |
||
101 | * @return User |
||
102 | */ |
||
103 | public function store(string $username, string $email, string $address = '', bool $newUser = true): User |
||
104 | { |
||
105 | $this->attributes['username'] = $username; |
||
106 | $this->attributes['mail'] = $email; |
||
107 | |||
108 | $this->attributes['motto'] = Config::get('chocolatey.motto'); |
||
109 | $this->attributes['look'] = Config::get('chocolatey.figure'); |
||
110 | $this->attributes['auth_ticket'] = ''; |
||
111 | |||
112 | $this->attributes['password'] = hash(Config::get('chocolatey.security.hash'), openssl_random_pseudo_bytes(50)); |
||
113 | $this->attributes['account_created'] = time(); |
||
114 | |||
115 | $this->attributes['ip_current'] = $address; |
||
116 | |||
117 | $this->traits = $newUser ? ['NEW_USER', 'USER'] : ['USER']; |
||
118 | |||
119 | $this->timestamps = false; |
||
120 | |||
121 | $this->save(); |
||
122 | $this->createData(); |
||
123 | |||
124 | return $this; |
||
125 | } |
||
126 | |||
127 | /** |
||
128 | * Get User E-mail. |
||
129 | * |
||
130 | * @return string |
||
131 | */ |
||
132 | public function getRealEmailAttribute() |
||
133 | { |
||
134 | return $this->attributes['mail']; |
||
135 | } |
||
136 | |||
137 | /** |
||
138 | * Get User E-mail. |
||
139 | * |
||
140 | * @return string |
||
141 | */ |
||
142 | public function getMailAttribute() |
||
143 | { |
||
144 | return strpos('-fblogin', $this->attributes['mail']) !== false ? 'fblogin' : $this->attributes['mail']; |
||
145 | } |
||
146 | |||
147 | /** |
||
148 | * Store an User Alias Set on Database. |
||
149 | */ |
||
150 | public function createData() |
||
151 | { |
||
152 | (new UserPreferences())->store($this->attributes['id']); |
||
153 | } |
||
154 | |||
155 | /** |
||
156 | * Get Is User is Banned. |
||
157 | * |
||
158 | * @return bool |
||
159 | */ |
||
160 | public function getIsBannedAttribute(): bool |
||
161 | { |
||
162 | $ban = Ban::where('user_id', $this->attributes['id'])->first(); |
||
163 | |||
164 | if ($ban == null) { |
||
165 | return false; |
||
166 | } |
||
167 | |||
168 | return $ban->ban_expire >= time(); |
||
169 | } |
||
170 | |||
171 | /** |
||
172 | * Check if Is Staff. |
||
173 | * |
||
174 | * @return bool |
||
175 | */ |
||
176 | public function getIsStaffAttribute(): bool |
||
177 | { |
||
178 | return array_key_exists('rank', $this->attributes) ? $this->attributes['rank'] >= 5 : false; |
||
179 | } |
||
180 | |||
181 | /** |
||
182 | * Get Ban Details. |
||
183 | * |
||
184 | * @return Ban |
||
185 | */ |
||
186 | public function getBanDetailsAttribute() |
||
187 | { |
||
188 | return Ban::where('user_id', $this->attributes['id'])->first(); |
||
189 | } |
||
190 | |||
191 | /** |
||
192 | * Get Current User Country. |
||
193 | * |
||
194 | * @TODO: Implement this in a proper way |
||
195 | * |
||
196 | * @return string |
||
197 | */ |
||
198 | public function getCountryAttribute(): string |
||
199 | { |
||
200 | return 'com'; |
||
201 | } |
||
202 | |||
203 | /** |
||
204 | * Set the Trait Attribute. |
||
205 | * |
||
206 | * @param array $accountType |
||
207 | */ |
||
208 | public function setTraitsAttribute(array $accountType) |
||
209 | { |
||
210 | $this->traits = $accountType; |
||
211 | } |
||
212 | |||
213 | /** |
||
214 | * What is this field? |
||
215 | * |
||
216 | * @return array |
||
217 | */ |
||
218 | public function getTraitsAttribute(): array |
||
219 | { |
||
220 | if (array_key_exists('rank', $this->attributes) && $this->attributes['rank'] >= config('chocolatey.minRank')) { |
||
221 | return ['STAFF']; |
||
222 | } |
||
223 | |||
224 | return $this->traits; |
||
225 | } |
||
226 | |||
227 | /** |
||
228 | * We don't care about this? |
||
229 | * |
||
230 | * @return bool |
||
231 | */ |
||
232 | public function getTrustedAttribute(): bool |
||
233 | { |
||
234 | if (UserSecurity::find($this->attributes['id']) == null) { |
||
235 | return true; |
||
236 | } |
||
237 | |||
238 | return in_array($this->attributes['ip_current'], |
||
239 | UserSecurity::find($this->attributes['id'])->trustedDevices); |
||
240 | } |
||
241 | |||
242 | /** |
||
243 | * What is this field? |
||
244 | * |
||
245 | * @return string |
||
246 | */ |
||
247 | public function getIdentityTypeAttribute(): string |
||
248 | { |
||
249 | return strpos('-fblogin', $this->attributes['mail']) !== false ? 'FACEBOOK' : 'HABBO'; |
||
250 | } |
||
251 | |||
252 | /** |
||
253 | * We don't care about this, every user is trusted. |
||
254 | * |
||
255 | * @return bool |
||
256 | */ |
||
257 | public function getIdentityVerifiedAttribute(): bool |
||
261 | |||
262 | /** |
||
263 | * We don't care about this. |
||
264 | * |
||
265 | * @return int |
||
266 | */ |
||
267 | public function getLoginLogIdAttribute(): int |
||
271 | |||
272 | /** |
||
273 | * We don't care about this. |
||
274 | * |
||
275 | * @return int |
||
276 | */ |
||
277 | public function getSessionLoginIdAttribute(): int |
||
281 | |||
282 | /** |
||
283 | * Get the HabboClub Attribute |
||
284 | * In a Retro Habbo everyone is HC, yeah? |
||
285 | * |
||
286 | * @WARNING: This is used for Advertisement |
||
287 | * |
||
288 | * @return bool |
||
289 | */ |
||
290 | public function getHabboClubMemberAttribute(): bool |
||
291 | { |
||
292 | return Config::get('chocolatey.ads.enabled') == false; |
||
293 | } |
||
294 | |||
295 | /** |
||
296 | * Get the Builders Club Attribute |
||
297 | * In a Retro Habbo everyone is BC, yeah? |
||
298 | * |
||
299 | * @WARNING: This is used for Advertisement |
||
300 | * |
||
301 | * @return bool |
||
302 | */ |
||
303 | public function getBuildersClubMemberAttribute(): bool |
||
307 | |||
308 | /** |
||
309 | * Get GTimestamp in Habbo UserCurrency. |
||
310 | * |
||
311 | * @return string |
||
312 | */ |
||
313 | public function getAccountCreatedAttribute(): string |
||
319 | |||
320 | /** |
||
321 | * Get GTimestamp in Habbo UserCurrency. |
||
322 | * |
||
323 | * @return string |
||
324 | */ |
||
325 | public function getMemberSinceAttribute(): string |
||
331 | |||
332 | /** |
||
333 | * Retrieve User Figure String. |
||
334 | * |
||
335 | * @return string |
||
336 | */ |
||
337 | public function getFigureStringAttribute(): string |
||
341 | |||
342 | /** |
||
343 | * Get GTimestamp in Habbo UserCurrency. |
||
344 | * |
||
345 | * @return false|string |
||
346 | */ |
||
347 | public function getLastLoginAttribute(): string |
||
353 | |||
354 | /** |
||
355 | * Get E-Mail Verified Attribute. |
||
356 | * |
||
357 | * @return bool |
||
358 | */ |
||
359 | public function getEmailVerifiedAttribute(): bool |
||
364 | |||
365 | /** |
||
366 | * Get Account Chocolatey Id. |
||
367 | * |
||
368 | * @return ChocolateyId |
||
369 | */ |
||
370 | public function getChocolateyId() |
||
374 | } |
||
375 |