webmoney/backend/app/Models/EmailVerificationToken.php
marcoitaloesp-ai 6292b62315
feat: complete email system redesign with corporate templates
- Redesigned all email templates with professional corporate style
- Created base layout with dark header, status cards, and footer
- Updated: subscription-cancelled, account-activation, welcome, welcome-new-user, due-payments-alert
- Removed emojis and gradients for cleaner look
- Added multi-language support (ES, PT-BR, EN)
- Fixed email delivery (sync instead of queue)
- Fixed PayPal already-cancelled subscription handling
- Cleaned orphan subscriptions from deleted users
2025-12-18 00:44:37 +00:00

73 lines
1.5 KiB
PHP

<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Support\Str;
class EmailVerificationToken extends Model
{
protected $fillable = [
'user_id',
'token',
'expires_at',
'used_at',
];
protected $casts = [
'expires_at' => 'datetime',
'used_at' => 'datetime',
];
/**
* Relationship: User
*/
public function user(): BelongsTo
{
return $this->belongsTo(User::class);
}
/**
* Create a new verification token for user
*/
public static function createForUser(User $user, int $expiresInHours = 24): self
{
// Invalidate existing tokens
self::where('user_id', $user->id)->whereNull('used_at')->delete();
return self::create([
'user_id' => $user->id,
'token' => Str::random(64),
'expires_at' => now()->addHours($expiresInHours),
]);
}
/**
* Find valid token
*/
public static function findValid(string $token): ?self
{
return self::where('token', $token)
->where('expires_at', '>', now())
->whereNull('used_at')
->first();
}
/**
* Check if token is valid
*/
public function isValid(): bool
{
return $this->expires_at > now() && $this->used_at === null;
}
/**
* Mark token as used
*/
public function markAsUsed(): void
{
$this->update(['used_at' => now()]);
}
}