'datetime', 'last_login' => 'datetime' ]; public function getJWTIdentifier() { return $this->getKey(); } public function getJWTCustomClaims() { return []; } public function hasVerifiedEmail() { return $this->email_verif == 1; } public function markEmailAsVerified() { return $this->forceFill(['email_verif' => 1])->save(); } public function hasSubscribed() { return Subscribe::whereEmail($this->email)->first() || $this->email_sub == 1; } public function attemptLogin($password) { $username = strtoupper($this->username); $password = strtoupper($password); $passwordHash = sha1("$username:$password"); return strcasecmp($this->sha_pass_hash, $passwordHash) === 0; } public function sendPasswordResetNotification($token) { $resetPasswordUrl = url(route('password.reset')) . "?token=" . $token; $data['type'] = 'EmailResetPassword'; $data['url'] = url('/'); $data['email'] = $this->email; $data['username'] = $this->name; $data['resetPasswordUrl'] = $resetPasswordUrl; $data['subscribe'] = $this->hasSubscribed(); $data['body'] = view('email.reset-password')->with(['data' => $data])->render(); dispatch(new \App\Jobs\Email($data)); } public function sendEmailVerificationNotification($newAccount = false) { if ($newAccount) { $data['type'] = 'NewAccount'; } else { $data['type'] = 'EmailVerify'; } $data['email'] = $this->email; $data['username'] = $this->username; $data['joinDate'] = $this->joindate; $data['keyword'] = $this->email_keyword; $data['subscribe'] = $this->hasSubscribed(); $verificationUrl = URL::temporarySignedRoute( 'verification.verify', Carbon::now()->addMinutes(Config::get('auth.verification.expire', 60)), [ 'id' => $this->getKey(), 'hash' => sha1($this->getEmailForVerification()) ] ); $data['verificationUrl'] = $verificationUrl; $data['body'] = view('email.verify')->with(['data' => $data])->render(); dispatch(new \App\Jobs\Email($data)); } public function sendEmailChangeNotification($newEmail) { $token = JWTAuth::customClaims([ 'newEmail' => $newEmail ])->fromUser($this); $changeEmailUrl = URL::temporarySignedRoute( 'verification.change.email', Carbon::now()->addMinutes(Config::get('auth.verification.expire', 60)), [ 'token' => $token ] ); $data['type'] = 'EmailChange'; $data['email'] = $newEmail; $data['username'] = $this->username; $data['changeEmailUrl'] = $changeEmailUrl; $data['subscribe'] = $this->hasSubscribed(); $data['body'] = view('email.change-email')->with(['data' => $data])->render(); dispatch(new \App\Jobs\Email($data)); } public function hiddenEmail() { return preg_replace_callback('/(?<=^.).*(?=@)/', function($match) { return str_repeat('*', strlen($match[0])); }, $this->email); } public function changeEmail($newEmail) { if ($this->email == $newEmail) { return "ALREADY_CHANGED"; } if (Account::where('email', '=', $newEmail)->first()) { return "ALREADY_TOOK"; } if ($this->forceFill(['email' => $newEmail])->save()) { return "DONE"; } return "FAILED"; } public function ban() { return $this->hasMany(AccountBanned::class, 'id', 'id'); } public function latestBan() { return $this->ban()->orderBy('bandate', 'DESC')->first(); } public function shopCoins() { return $this->hasOne(ShopCoin::class, 'id', 'id'); } public function characters($database) { return $this->setConnection($database)->hasMany(Character::class, 'account', 'id'); } public function deletedCharacters($database) { return $this->setConnection($database)->hasMany(Character::class, 'deleteInfos_Account', 'id'); } public function enable2fa($secretKey, $recoveryCode) { return $this->forceFill([ 'security' => $secretKey, 'locked' => 2, 'recovery_code' => $recoveryCode ])->save(); } public function disable2fa() { return $this->forceFill([ 'security' => '', 'locked' => 0, 'recovery_code' => null ])->save(); } public function twoFactorAllowed() { return $this->hasOne(AccountTwofactorAllowed::class, 'account_id', 'id'); } public function shopCoinsHistory() { return $this->hasMany(ShopCoinsHistory::class, 'account_id', 'id'); } public function shopLog() { return $this->hasMany(ShopLog::class, 'account', 'id'); } public function getLastUnseenBugTrackerMessage() { $lastUnseenMessage = BugTrackerMessageStatus::where('account_id', $this->id) ->where('seen', false) ->orderBy('created_at', 'desc') ->first(); if ($lastUnseenMessage) { return BugTrackerMessage::find($lastUnseenMessage->bug_tracker_message_id); } return null; } public function getAllUnseenBugTrackerMessages() { $unseenMessages = BugTrackerMessageStatus::where('account_id', $this->id) ->where('seen', false) ->get(); $messageIds = $unseenMessages->pluck('bug_tracker_message_id'); return BugTrackerMessage::whereIn('id', $messageIds)->get(); } public function markBugTrackerMessageAsSeen($messageId) { BugTrackerMessageStatus::updateOrCreate( ['account_id' => $this->id, 'bug_tracker_message_id' => $messageId], ['seen' => true] ); } public function markBugTrackerMessageAsUnseen($messageId) { BugTrackerMessageStatus::updateOrCreate( ['account_id' => $this->id, 'bug_tracker_message_id' => $messageId], ['seen' => false] ); } public function getCoinsAttribute() { $shopCoin = $this->hasOne(ShopCoin::class, 'id', 'id')->first(); return $shopCoin ? $shopCoin->coins : 0; } public function latestShopAppeal() { return $this->setConnection('mysql')->hasOne(ShopAppeal::class, 'account_id', 'id')->orderBy('id', 'DESC')->first(); } public function votes() { return $this->setConnection('mysql')->hasMany(BugTrackerVote::class, 'account_id', 'id'); } public function bugReports() { return $this->setConnection('mysql')->hasMany(BugTracker::class, 'account_id', 'id'); } public function canInitTransfer() { $targetDate = Carbon::createFromFormat('Y-m-d H:i:s', '2023-10-01 00:00:00'); return $this->joindate < $targetDate; } }