webmoney/backend/app/Models/EmailVerificationToken.php
marco 54cccdd095 refactor: migração para desenvolvimento direto no servidor
- Removido README.md padrão do Laravel (backend)
- Removidos scripts de deploy (não mais necessários)
- Atualizado copilot-instructions.md para novo fluxo
- Adicionada documentação de auditoria do servidor
- Sincronizado código de produção com repositório

Novo workflow:
- Trabalhamos diretamente em /root/webmoney (symlink para /var/www/webmoney)
- Mudanças PHP são instantâneas
- Mudanças React requerem 'npm run build'
- Commit após validação funcional
2025-12-19 11:45:32 +01:00

73 lines
1.5 KiB
PHP
Executable File

<?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()]);
}
}