🆙 Add fixed cms 🆙

This commit is contained in:
Remco
2026-02-02 19:30:21 +01:00
parent b1a2cab62d
commit b67e0ec2b9
3982 changed files with 193682 additions and 0 deletions
+334
View File
@@ -0,0 +1,334 @@
<?php
namespace App\Models;
use App\Models\Articles\WebsiteArticle;
use App\Models\Articles\WebsiteArticleComment;
use App\Models\Community\Staff\WebsiteStaffApplications;
use App\Models\Community\Staff\WebsiteTeam;
use App\Models\Game\Furniture\Item;
use App\Models\Game\Permission;
use App\Models\Game\Player\MessengerFriendship;
use App\Models\Game\Player\UserBadge;
use App\Models\Game\Player\UserCurrency;
use App\Models\Game\Player\UserSetting;
use App\Models\Game\Player\UserSubscription;
use App\Models\Game\Room;
use App\Models\Help\WebsiteHelpCenterTicket;
use App\Models\Miscellaneous\CameraWeb;
use App\Models\Miscellaneous\WebsiteBetaCode;
use App\Models\Shop\WebsitePaypalTransaction;
use App\Models\Shop\WebsiteUsedShopVoucher;
use App\Models\User\Ban;
use App\Models\User\ClaimedReferralLog;
use App\Models\User\Referral;
use App\Models\User\UserReferral;
use App\Models\User\WebsiteUserGuestbook;
use Filament\Models\Contracts\FilamentUser;
use Filament\Models\Contracts\HasName;
use Filament\Panel;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\Relations\HasMany;
use Illuminate\Database\Eloquent\Relations\HasOne;
use Illuminate\Foundation\Auth\User as Authenticatable;
use Illuminate\Notifications\Notifiable;
use Illuminate\Support\Facades\Hash;
use Illuminate\Support\Str;
use Laravel\Fortify\TwoFactorAuthenticatable;
use Laravel\Fortify\TwoFactorAuthenticationProvider;
use Laravel\Sanctum\HasApiTokens;
use Spatie\Activitylog\LogOptions;
use Spatie\Activitylog\Traits\LogsActivity;
/**
* @property int $id
* @property string $username
* @property string $mail
* @property string $password
* @property string $account_created
* @property string|null $last_login
* @property string|null $last_online
* @property string|null $motto
* @property string $look
* @property int $credits
* @property int $rank
* @property bool $online
* @property string $auth_ticket
* @property string $ip_register
* @property string $ip_current
* @property int $home_room
* @property string|null $referral_code
* @property-read \App\Models\Game\Player\UserSetting|null $settings
* @property-read \Illuminate\Database\Eloquent\Collection $currencies
* @property-read \App\Models\User\Ban|null $ban
* @property-read \App\Models\Game\Permission $rank
*/
class User extends Authenticatable implements FilamentUser, HasName
{
use HasApiTokens, HasFactory, LogsActivity, Notifiable, TwoFactorAuthenticatable;
public $timestamps = false;
protected $guarded = ['id'];
protected $hidden = ['id', 'password', 'remember_token'];
protected function casts(): array
{
return [
'email_verified_at' => 'datetime',
'password' => 'hashed',
'hidden_staff' => 'boolean',
'online' => 'boolean',
];
}
public function currencies(): HasMany
{
return $this->hasMany(UserCurrency::class, 'user_id');
}
public function sessions()
{
return $this->hasMany(Session::class);
}
public function currency(string $currency)
{
if (! $this->relationLoaded('currencies')) {
$this->load('currencies');
}
$type = match ($currency) {
'duckets' => 0,
'diamonds' => 5,
'points' => 101,
default => 0,
};
return $this->currencies->where('type', $type)->first()->amount ?? 0;
}
public function permission(): HasOne
{
return $this->hasOne(Permission::class, 'id', 'rank');
}
public function articles(): HasMany
{
return $this->hasMany(WebsiteArticle::class);
}
public function referrals(): HasOne
{
return $this->hasOne(UserReferral::class);
}
public function userReferrals(): HasMany
{
return $this->hasMany(Referral::class);
}
public function claimedReferralLog(): HasMany
{
return $this->hasMany(ClaimedReferralLog::class);
}
public function badges(): HasMany
{
return $this->hasMany(UserBadge::class);
}
public function rooms(): HasMany
{
return $this->hasMany(Room::class, 'owner_id');
}
public function friends(): HasMany
{
return $this->hasMany(MessengerFriendship::class, 'user_one_id');
}
public function referralsNeeded()
{
$referrals = 0;
if (! is_null($this->referrals)) {
$referrals = $this->referrals->referrals_total;
}
return setting('referrals_needed') - $referrals;
}
public function ban()
{
return $this->hasOne(Ban::class, 'user_id')->where('ban_expire', '>', time())->whereIn('type', ['account', 'super']);
}
public function settings(): HasOne
{
return $this->hasOne(UserSetting::class);
}
public function ssoTicket(): string
{
$sso = sprintf('%s-%s', Str::replace(' ', '', setting('hotel_name')), Str::uuid());
if (User::where('auth_ticket', $sso)->exists()) {
return $this->ssoTicket();
}
$this->update([
'auth_ticket' => $sso,
]);
return $sso;
}
public function betaCode(): HasOne
{
return $this->hasOne(WebsiteBetaCode::class);
}
public function team(): BelongsTo
{
return $this->belongsTo(WebsiteTeam::class, 'team_id');
}
public function applications(): HasMany
{
return $this->hasMany(WebsiteStaffApplications::class, 'user_id');
}
public function hcSubscription(): HasOne
{
return $this->hasOne(UserSubscription::class);
}
public function articleComments(): HasMany
{
return $this->hasMany(WebsiteArticleComment::class);
}
public function transactions(): HasMany
{
return $this->hasMany(WebsitePaypalTransaction::class);
}
public function usedShopVouchers(): HasMany
{
return $this->hasMany(WebsiteUsedShopVoucher::class);
}
public function items(): HasMany
{
return $this->hasMany(Item::class, 'user_id');
}
public function tickets(): HasMany
{
return $this->hasMany(WebsiteHelpCenterTicket::class);
}
public function photos(): HasMany
{
return $this->hasMany(CameraWeb::class);
}
public function profileGuestbook(): HasMany
{
return $this->hasMany(WebsiteUserGuestbook::class, 'profile_id');
}
public function guestbook(): HasMany
{
return $this->hasMany(WebsiteUserGuestbook::class, 'user_id');
}
public function chatLogs()
{
return $this->hasMany(ChatlogRoom::class, 'user_from_id');
}
public function chatLogsPrivate()
{
return $this->hasMany(ChatlogPrivate::class, 'user_from_id');
}
public function getOnlineFriends(int $total = 10)
{
return $this->friends()
->select(['user_two_id', 'users.id', 'users.username', 'users.look', 'users.motto', 'users.last_online'])
->join('users', 'users.id', '=', 'user_two_id')
->where('users.online', '1')
->inRandomOrder()
->limit($total)
->get();
}
public function confirmTwoFactorAuthentication($code)
{
$codeIsValid = app(TwoFactorAuthenticationProvider::class)
->verify(decrypt($this->two_factor_secret), $code);
if (! $codeIsValid) {
return false;
}
$this->update([
'two_factor_confirmed' => true,
]);
return true;
}
public function hasAppliedForPosition(int $rankId)
{
return $this->applications()->where('rank_id', '=', $rankId)->exists();
}
public function changePassword(string $newPassword): void
{
$this->password = Hash::make($newPassword);
$this->save();
}
public function getFilamentName(): string
{
return $this->username ?? 'Guest';
}
public function canAccessPanel(Panel $panel): bool
{
return hasHousekeepingPermission('can_access_housekeeping');
}
public function getActivitylogOptions(): LogOptions
{
return LogOptions::defaults()
->logOnly(['id', 'username', 'motto', 'rank', 'credits'])
->logOnlyDirty()
->dontSubmitEmptyLogs();
}
public function save(array $options = [])
{
if (! $this->isDirty()) {
return false;
}
return parent::save($options);
}
public function hasAppliedForTeam(int $teamId): bool
{
if (! $teamId) {
return false;
}
return $this->applications()
->where('team_id', $teamId)
->exists();
}
}