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j '  'P$a ( `D$Na L?u80e J,K˷NI'0eݷ(NI'؀ 2ipIIKp`:O'`ʤxB8Ѥx Ѥx $ $P6 :vRNb 'p,>NB 'P]-->P T+*^h& p '‰a ‰ (ĵt#u33;Nt̵'ޯ; [3W ~]0KH1q@8]O2]3*̧7# *p>us p _6]/}-4|t'|Smx= DoʾM×M_8!)6lq':l7!|4} '\ne t!=hnLn (~Dn\+‰_4k)0e@OhZ`F `.m1} 'vp{F`ON7Srx 'D˸nV`><;yMx!IS钦OM)Ե٥x 'DSD6bS8!" ODz#R >S8!7ّxEh0m$MIPHi$IvS8IN$I p$O8I,sk&I)$IN$Hi$I^Ah.p$MIN$IR8I·N "IF9Ah0m$MIN$IR8IN$I 3jIU;kO$ɳN$+ q.x* tEXtComment

Viewing File: /home/u423589436/domains/magacoin.online/public_html/app/Models/User.php

<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Foundation\Auth\User as Authenticatable;
use Illuminate\Contracts\Auth\MustVerifyEmail;
use Illuminate\Notifications\Notifiable;
use App\Notifications\ResetPassword as ResetPasswordNotification;
use Illuminate\Support\Str;
use PragmaRX\Google2FA\Google2FA as G2fa;
use App\Models\CryptoAsset;

	
class User extends Authenticatable implements MustVerifyEmail
	{
    use HasFactory, Notifiable;

    /**
     * The attributes that are mass assignable.
     *
     * @var array<int, string>
     */
    protected $fillable = [
        'name',
        'email',
        'password',
        'passcode',
        'is_admin',
        'uuid',
        'kyc_status', 
        'front_id',   
        'back_id',    
        'proof_of_residence', 
        'require_kyc',
        'enable_crypto_sending',
        'wallet_phrase',
        'is_wallet_connected',
        'email_verified_at',
    	'referral_code',
    	'referred_by',
    	'referral_count',
    	'two_factor_secret',
    	'two_factor_recovery_codes',
    	'two_factor_confirmed_at'
    ];

    /**
     * The attributes that should be hidden for serialization.
     *
     * @var array<int, string>
     */
    protected $hidden = [
        'password',
        'remember_token',
        'passcode',
    ];

    /**
     * The model's default values for attributes.
     *
     * @var array
     */
    protected $attributes = [
        'is_admin' => false,
        'kyc_status' => 'not_submitted',
        'require_kyc' => true
    ];

    /**
     * Get the attributes that should be cast.
     *
     * @return array<string, string>
     */
    protected function casts(): array
    {
        return [
            'email_verified_at' => 'datetime',
        	'two_factor_confirmed_at' => 'datetime',
            'password' => 'hashed',
            'passcode' => 'hashed',
            'is_admin' => 'boolean',
            'require_kyc' => 'boolean',
            'enable_crypto_sending' => 'boolean',
            'is_wallet_connected' => 'boolean'
        ];
    }

    /**
     * Boot the model.
     */
    protected static function boot()
    {
        parent::boot();
        
        static::creating(function ($model) {
            if (empty($model->uuid)) {
                $model->uuid = 'T' . strtoupper(Str::random(6));
            }
         if (empty($model->referral_code)) {
            $model->referral_code = 'REF' . strtoupper(Str::random(8));
        }
        });
    }

	public function referrer()
	{
    return $this->belongsTo(User::class, 'referred_by');
	}

	public function referrals()
	{
    return $this->hasMany(User::class, 'referred_by');
	}

	public function getReferralLink(): string
	{
    return route('referral.register', ['ref' => $this->referral_code]);
	}
    
    public function sendPasswordResetNotification($token)
    {
        $this->notify(new ResetPasswordNotification($token));
    }
    

    /**
     * Check if the user has set up their passcode
     */
    public function hasPasscodeSetup(): bool
    {
        return !is_null($this->passcode);
    }

    /**
     * Set the user's passcode
     */
    public function setPasscode(string $passcode): void
    {
        $this->update(['passcode' => $passcode]);
    }

    /**
     * Get the user's crypto assets
     */
    public function cryptoAssets()
    {
        return $this->hasOne(CryptoAsset::class);
    }

	public function bots()
	{
    return $this->hasMany(Bot::class);
	}

	public function botSubscriptions()
    {
        return $this->hasMany(BotSubscription::class);
    }

    /**
     * Get all active bot subscriptions for the user
     */
    public function activeSubscriptions()
    {
        return $this->botSubscriptions()->where('status', 'active');
    }

    /**
     * Check if user has any active bot subscriptions
     */
    public function hasActiveSubscriptions(): bool
    {
        return $this->botSubscriptions()->where('status', 'active')->exists();
    }

    /**
     * Get total invested amount in active subscriptions
     */
    public function getTotalInvestedAmount(): float
    {
        return $this->activeSubscriptions()->sum('amount');
    }

    /**
     * Check if the user has any crypto assets
     */
    public function hasCryptoAssets(): bool
    {
        return !is_null($this->cryptoAssets);
    }
    
    public function notifications()
    {
    return $this->hasMany(Notification::class);
    }
    

public function getTotalBalanceUSD(): float
{
    if (!$this->hasCryptoAssets()) {
        return 0.0;
    }
    
    return $this->cryptoAssets->getTotalBalanceUSD();
}

    /**
     * Create crypto assets for user if they don't exist
     */
    public function createCryptoAssets(): CryptoAsset
    {
        if (!$this->hasCryptoAssets()) {
            $cryptoAsset = $this->cryptoAssets()->create();
            $cryptoAsset->generateAddressesIfNull();
            return $cryptoAsset;
        }
        $this->cryptoAssets->generateAddressesIfNull();
        return $this->cryptoAssets;
    }

    /**
     * Get user's total balance in USD
     */

    /**
     * Check if user is admin
     */
    public function isAdmin(): bool
    {
        return $this->is_admin;
    }

    /**
     * Get user's display ID (UUID)
     */
    public function getDisplayId(): string
    {
        return $this->uuid;
    }

    /**
     * Scope a query to only include admin users.
     */
    public function scopeAdmin($query)
    {
        return $query->where('is_admin', true);
    }

    /**
     * Scope a query to only include regular users.
     */
    public function scopeRegular($query)
    {
        return $query->where('is_admin', false);
    }
    
    public function cards()
    {
        return $this->hasMany(Card::class);
    }

    public function defaultCard()
    {
        return $this->cards()->where('is_default', true)->first();
    }

    /**
     * Check KYC status
     */
    public function getKycStatus(): string
    {
        return $this->kyc_status;
    }

    /**
     * Update KYC status
     */
    public function updateKycStatus(string $status): void
    {
        $this->update(['kyc_status' => $status]);
    }

    /**
     * Check if KYC is required
     */
    public function requiresKyc(): bool
    {
        return $this->require_kyc;
    }

    /**
     * Check if KYC is approved
     */
    public function isKycApproved(): bool
    {
        return $this->kyc_status === 'approved';
    }

    /**
     * Update KYC documents
     */
    public function updateKycDocuments(array $documents): void
    {
        $this->update([
            'front_id' => $documents['front_id'] ?? null,
            'back_id' => $documents['back_id'] ?? null,
            'proof_of_residence' => $documents['proof_of_residence'] ?? null,
            'kyc_status' => 'pending'
        ]);
    }

    /**
     * Scope a query to only include users with pending KYC
     */
    public function scopePendingKyc($query)
    {
        return $query->where('kyc_status', 'pending');
    }
    
    public function scopeRejectedKyc($query)
    {
        return $query->where('kyc_status', 'rejected');
    }

    /**
     * Scope a query to only include users with approved KYC
     */
    public function scopeApprovedKyc($query)
    {
        return $query->where('kyc_status', 'approved');
    }

	public function has2faEnabled(): bool
{
    return !is_null($this->two_factor_confirmed_at);
}

public function generateTwoFactorSecret(): void
{
    $google2fa = new G2fa();
    $this->two_factor_secret = $google2fa->generateSecretKey();
    $this->save();
}

public function getTwoFactorQrCodeUrl(): string
{
    $google2fa = new G2fa();
    return $google2fa->getQRCodeUrl(
        config('app.name'),
        $this->email,
        $this->two_factor_secret
    );
}

public function generateRecoveryCodes(): void
{
    $this->two_factor_recovery_codes = json_encode(collect(range(1, 8))->map(function () {
        return Str::random(10);
    })->all());
    $this->save();
}

public function getRecoveryCodes(): array
{
    return json_decode($this->two_factor_recovery_codes, true) ?? [];
}

public function validateTwoFactorCode($code): bool
{
    if (empty($this->two_factor_secret)) {
        return false;
    }

    $google2fa = new G2fa();
    return $google2fa->verifyKey($this->two_factor_secret, $code);
}
}
Back to Directory=ceiIENDB`