Revert OAuth2.0

This commit is contained in:
2026-06-16 21:35:10 +02:00
parent 69f4d6a602
commit 6001c2e3b8
33 changed files with 56 additions and 1127 deletions
+1
View File
@@ -5,6 +5,7 @@ declare(strict_types=1);
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Facades\File;
use Illuminate\Support\Facades\Schema;
use Illuminate\Support\Facades\Storage;
+1
View File
@@ -4,6 +4,7 @@ namespace App\Models;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Support\Facades\Storage;
class EmailAttachment extends Model
{
+1 -63
View File
@@ -4,8 +4,6 @@ namespace App\Models;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\HasMany;
use App\Enums\GoogleService;
use App\Services\GoogleOAuthService;
use Illuminate\Support\Facades\Crypt;
class EmailSetting extends Model
@@ -16,7 +14,7 @@ class EmailSetting extends Model
'imap_host', 'imap_port', 'imap_encryption', 'imap_username', 'imap_password',
'smtp_host', 'smtp_port', 'smtp_encryption', 'smtp_username', 'smtp_password',
'email_address', 'email_name', 'reply_to', 'sync_interval_minutes',
'last_sync_at', 'is_active', 'signature', 'signature_enabled', 'auth_method'
'last_sync_at', 'is_active', 'signature', 'signature_enabled'
];
protected $casts = [
@@ -43,9 +41,6 @@ class EmailSetting extends Model
public function getDecryptedPassword(): string
{
if ($this->isOauth()) {
return $this->getOAuthAccessToken() ?? '';
}
if (empty($this->imap_password)) {
return '';
}
@@ -58,9 +53,6 @@ class EmailSetting extends Model
public function getDecryptedSmtpPassword(): string
{
if ($this->isOauth()) {
return $this->getOAuthAccessToken() ?? '';
}
if (empty($this->smtp_password)) {
return $this->getDecryptedPassword();
}
@@ -71,26 +63,6 @@ class EmailSetting extends Model
}
}
public function isOauth(): bool
{
return $this->auth_method === 'oauth';
}
public function getOAuthAccessToken(): ?string
{
if (!$this->isOauth()) {
return null;
}
try {
$oauth = app(GoogleOAuthService::class);
return $oauth->getAccessToken(GoogleService::Gmail);
} catch (\Exception $e) {
\Illuminate\Support\Facades\Log::error('OAuth token refresh failed: ' . $e->getMessage());
return null;
}
}
public function getSmtpConfig(): array
{
return [
@@ -108,10 +80,6 @@ class EmailSetting extends Model
return null;
}
if ($this->isOauth()) {
return null;
}
try {
$encryption = match ($this->imap_encryption) {
'ssl' => 'ssl',
@@ -135,10 +103,6 @@ class EmailSetting extends Model
public function testConnection(): array
{
try {
if ($this->isOauth()) {
return $this->testOAuthImapConnection();
}
$mailbox = $this->getImapClient();
if (!$mailbox) {
@@ -161,32 +125,6 @@ class EmailSetting extends Model
}
}
private function testOAuthImapConnection(): array
{
try {
$token = $this->getOAuthAccessToken();
if (!$token) {
return ['success' => false, 'message' => 'Impossibile ottenere il token OAuth. Verifica la connessione Google.'];
}
$client = new \Webklex\PHPIMAP\Client([
'host' => $this->imap_host,
'port' => $this->imap_port ?? 993,
'encryption' => $this->imap_encryption ?? 'ssl',
'validate_cert' => false,
'username' => $this->imap_username,
'password' => $token,
'authentication' => 'oauth',
]);
$client->connect();
$client->disconnect();
return ['success' => true, 'message' => 'Connessione IMAP OAuth riuscita! Server: ' . $this->imap_host];
} catch (\Exception $e) {
return ['success' => false, 'message' => 'Errore connessione IMAP OAuth: ' . $e->getMessage()];
}
}
public static function getActive()
{
return self::where('is_active', true)->first();
+1
View File
@@ -6,6 +6,7 @@ use App\Traits\HasTagsLight;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
use Illuminate\Database\Eloquent\Relations\HasMany;
class Evento extends Model
{
-46
View File
@@ -1,46 +0,0 @@
<?php
declare(strict_types=1);
namespace App\Models;
use App\Enums\GoogleService;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Facades\Crypt;
class GoogleOAuthConnection extends Model
{
protected $fillable = [
'service',
'client_id',
'client_secret',
'refresh_token',
];
protected function casts(): array
{
return [
'service' => GoogleService::class,
];
}
public function getClientSecretAttribute(?string $value): ?string
{
return $value ? Crypt::decryptString($value) : null;
}
public function setClientSecretAttribute(?string $value): void
{
$this->attributes['client_secret'] = $value ? Crypt::encryptString($value) : null;
}
public function getRefreshTokenAttribute(?string $value): ?string
{
return $value ? Crypt::decryptString($value) : null;
}
public function setRefreshTokenAttribute(?string $value): void
{
$this->attributes['refresh_token'] = $value ? Crypt::encryptString($value) : null;
}
}