Compare commits
10
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
0b3144c949 | ||
|
|
c16201ba0d | ||
|
|
9861a74e1e | ||
|
|
f60221d0ef | ||
|
|
2677ee6f39 | ||
|
|
ecac206a6c | ||
|
|
f94f53abbd | ||
|
|
f715bc4552 | ||
|
|
7a24e554b0 | ||
|
|
60259a3655 |
@@ -0,0 +1,34 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Admin;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Models\AiSetting;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class AiSettingController extends Controller
|
||||
{
|
||||
public function show()
|
||||
{
|
||||
$ai = AiSetting::get();
|
||||
$defaultPrompt = AiSetting::DEFAULT_PROMPT;
|
||||
return view('admin.ai.show', compact('ai', 'defaultPrompt'));
|
||||
}
|
||||
|
||||
public function update(Request $request)
|
||||
{
|
||||
$request->validate([
|
||||
'ollama_url' => 'required|url|max:255',
|
||||
'ollama_model' => 'required|string|max:100',
|
||||
'prompt' => 'nullable|string',
|
||||
]);
|
||||
|
||||
$ai = AiSetting::get();
|
||||
$ai->ollama_url = rtrim($request->ollama_url, '/');
|
||||
$ai->ollama_model = $request->ollama_model;
|
||||
$ai->prompt = $request->filled('prompt') ? $request->prompt : null;
|
||||
$ai->save();
|
||||
|
||||
return redirect()->route('admin.ai.show')->with('success', 'KI-Einstellungen gespeichert.');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Admin;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Models\SsoSetting;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class SsoSettingController extends Controller
|
||||
{
|
||||
public function show()
|
||||
{
|
||||
$sso = SsoSetting::get();
|
||||
return view('admin.sso.show', compact('sso'));
|
||||
}
|
||||
|
||||
public function update(Request $request)
|
||||
{
|
||||
$request->validate([
|
||||
'base_url' => 'nullable|url|max:255',
|
||||
'client_id' => 'nullable|string|max:255',
|
||||
'client_secret' => 'nullable|string|max:255',
|
||||
'slug' => 'nullable|string|max:255',
|
||||
]);
|
||||
|
||||
$sso = SsoSetting::get();
|
||||
|
||||
$sso->base_url = rtrim($request->base_url ?? '', '/') ?: null;
|
||||
$sso->client_id = $request->client_id ?: null;
|
||||
$sso->client_secret = $request->client_secret ?: null;
|
||||
$sso->slug = $request->slug ?: null;
|
||||
$sso->enabled = $request->boolean('enabled');
|
||||
$sso->save();
|
||||
|
||||
return redirect()->route('admin.sso.show')->with('success', 'SSO-Einstellungen gespeichert.');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,109 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Auth;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Models\SsoSetting;
|
||||
use App\Models\User;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Illuminate\Support\Facades\Http;
|
||||
use Illuminate\Support\Str;
|
||||
|
||||
class SsoController extends Controller
|
||||
{
|
||||
public function redirect(Request $request)
|
||||
{
|
||||
$sso = SsoSetting::get();
|
||||
|
||||
if (!$sso->isConfigured()) {
|
||||
return redirect()->route('login')->with('error', 'SSO ist nicht konfiguriert.');
|
||||
}
|
||||
|
||||
$state = Str::random(40);
|
||||
session(['sso_state' => $state]);
|
||||
|
||||
$query = http_build_query([
|
||||
'client_id' => $sso->client_id,
|
||||
'redirect_uri' => route('sso.callback'),
|
||||
'response_type' => 'code',
|
||||
'scope' => 'openid email profile',
|
||||
'state' => $state,
|
||||
]);
|
||||
|
||||
return redirect($sso->authorizeUrl() . '?' . $query);
|
||||
}
|
||||
|
||||
public function callback(Request $request)
|
||||
{
|
||||
$sso = SsoSetting::get();
|
||||
|
||||
if (!$sso->isConfigured()) {
|
||||
return redirect()->route('login')->with('error', 'SSO ist nicht konfiguriert.');
|
||||
}
|
||||
|
||||
// State prüfen
|
||||
if ($request->get('state') !== session('sso_state')) {
|
||||
return redirect()->route('login')->with('error', 'Ungültige SSO-Anfrage (state mismatch).');
|
||||
}
|
||||
session()->forget('sso_state');
|
||||
|
||||
if ($request->has('error')) {
|
||||
return redirect()->route('login')->with('error', 'SSO-Anmeldung abgebrochen: ' . $request->get('error_description', $request->get('error')));
|
||||
}
|
||||
|
||||
// Code gegen Token tauschen
|
||||
$tokenResponse = Http::asForm()->post($sso->tokenUrl(), [
|
||||
'grant_type' => 'authorization_code',
|
||||
'client_id' => $sso->client_id,
|
||||
'client_secret' => $sso->client_secret,
|
||||
'redirect_uri' => route('sso.callback'),
|
||||
'code' => $request->get('code'),
|
||||
]);
|
||||
|
||||
if ($tokenResponse->failed()) {
|
||||
return redirect()->route('login')->with('error', 'SSO-Token konnte nicht abgerufen werden.');
|
||||
}
|
||||
|
||||
$accessToken = $tokenResponse->json('access_token');
|
||||
|
||||
// Userinfo abrufen
|
||||
$userInfo = Http::withToken($accessToken)->get($sso->userInfoUrl());
|
||||
|
||||
if ($userInfo->failed()) {
|
||||
return redirect()->route('login')->with('error', 'SSO-Benutzerinformationen konnten nicht abgerufen werden.');
|
||||
}
|
||||
|
||||
$info = $userInfo->json();
|
||||
$providerId = $info['sub'] ?? null;
|
||||
$email = $info['email'] ?? null;
|
||||
$name = $info['name'] ?? $info['preferred_username'] ?? $email;
|
||||
|
||||
if (!$providerId || !$email) {
|
||||
return redirect()->route('login')->with('error', 'Unvollständige Benutzerinformationen vom SSO-Provider.');
|
||||
}
|
||||
|
||||
// User suchen oder anlegen
|
||||
$user = User::where('sso_provider_id', $providerId)->first()
|
||||
?? User::where('email', $email)->first();
|
||||
|
||||
if (!$user) {
|
||||
$user = User::create([
|
||||
'name' => $name,
|
||||
'email' => $email,
|
||||
'password' => bcrypt(Str::random(32)),
|
||||
'sso_provider_id' => $providerId,
|
||||
'is_sso_user' => true,
|
||||
]);
|
||||
} elseif (!$user->sso_provider_id) {
|
||||
// Bestehenden Account mit SSO verknüpfen
|
||||
$user->sso_provider_id = $providerId;
|
||||
$user->is_sso_user = true;
|
||||
$user->save();
|
||||
}
|
||||
|
||||
Auth::login($user, true);
|
||||
|
||||
return redirect()->intended(route('user-nail-polishes.index'));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,88 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\Jobs\ProcessNailPolishImage;
|
||||
use App\Models\NailPolish;
|
||||
use App\Models\NailPolishImport;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
use Intervention\Image\ImageManager;
|
||||
use Intervention\Image\Drivers\Gd\Driver;
|
||||
|
||||
class NailPolishImportController extends Controller
|
||||
{
|
||||
public function index()
|
||||
{
|
||||
$imports = NailPolishImport::where('user_id', auth()->id())
|
||||
->latest()
|
||||
->paginate(20);
|
||||
|
||||
return view('nail-polish-imports.index', compact('imports'));
|
||||
}
|
||||
|
||||
public function create()
|
||||
{
|
||||
return view('nail-polish-imports.create');
|
||||
}
|
||||
|
||||
public function store(Request $request)
|
||||
{
|
||||
$request->validate([
|
||||
'image' => 'required|image|mimes:jpeg,png,jpg,webp|max:10240',
|
||||
]);
|
||||
|
||||
$file = $request->file('image');
|
||||
$filename = 'nail-polish-imports/' . uniqid() . '.jpg';
|
||||
|
||||
$manager = new ImageManager(new Driver());
|
||||
$image = $manager->read($file->getRealPath());
|
||||
|
||||
// Auf max. 1200px skalieren und als JPEG mit 85% Qualität speichern
|
||||
$image->scaleDown(width: 1200, height: 1200);
|
||||
Storage::disk('public')->put($filename, $image->toJpeg(85));
|
||||
|
||||
$path = $filename;
|
||||
|
||||
$import = NailPolishImport::create([
|
||||
'user_id' => auth()->id(),
|
||||
'image_path' => $path,
|
||||
'status' => 'pending',
|
||||
]);
|
||||
|
||||
ProcessNailPolishImage::dispatch($import->id);
|
||||
|
||||
$redirectUrl = route('nail-polish-imports.show', $import);
|
||||
|
||||
if (request()->ajax()) {
|
||||
return response()->json(['redirect' => $redirectUrl]);
|
||||
}
|
||||
|
||||
return redirect($redirectUrl)
|
||||
->with('success', 'Bild hochgeladen! Die KI analysiert es jetzt im Hintergrund.');
|
||||
}
|
||||
|
||||
public function show(NailPolishImport $nailPolishImport)
|
||||
{
|
||||
abort_if($nailPolishImport->user_id !== auth()->id(), 403);
|
||||
|
||||
return view('nail-polish-imports.show', ['import' => $nailPolishImport->load('nailPolish.manufacturer')]);
|
||||
}
|
||||
|
||||
public function rescan(NailPolish $nailPolish)
|
||||
{
|
||||
abort_unless($nailPolish->image_path, 404);
|
||||
|
||||
$import = NailPolishImport::create([
|
||||
'user_id' => auth()->id(),
|
||||
'image_path' => $nailPolish->image_path,
|
||||
'status' => 'pending',
|
||||
'nail_polish_id' => $nailPolish->id,
|
||||
]);
|
||||
|
||||
ProcessNailPolishImage::dispatch($import->id);
|
||||
|
||||
return redirect()->route('nail-polish-imports.show', $import)
|
||||
->with('success', 'KI-Analyse gestartet. Die Daten werden aktualisiert.');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,120 @@
|
||||
<?php
|
||||
|
||||
namespace App\Jobs;
|
||||
|
||||
use App\Models\AiSetting;
|
||||
use App\Models\Manufacturer;
|
||||
use App\Models\NailPolish;
|
||||
use App\Models\NailPolishImport;
|
||||
use Illuminate\Bus\Queueable;
|
||||
use Illuminate\Contracts\Queue\ShouldQueue;
|
||||
use Illuminate\Foundation\Bus\Dispatchable;
|
||||
use Illuminate\Queue\InteractsWithQueue;
|
||||
use Illuminate\Queue\SerializesModels;
|
||||
use Illuminate\Support\Facades\Http;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
|
||||
class ProcessNailPolishImage implements ShouldQueue
|
||||
{
|
||||
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
|
||||
|
||||
public int $timeout = 180;
|
||||
public int $tries = 2;
|
||||
|
||||
public function __construct(private int $importId) {}
|
||||
|
||||
public function handle(): void
|
||||
{
|
||||
$import = NailPolishImport::findOrFail($this->importId);
|
||||
$import->update(['status' => 'processing']);
|
||||
|
||||
try {
|
||||
$ai = AiSetting::get();
|
||||
$imageB64 = base64_encode(Storage::disk('public')->get($import->image_path));
|
||||
|
||||
$prompt = $ai->getActivePrompt();
|
||||
|
||||
$response = Http::timeout(160)->post("{$ai->ollama_url}/api/generate", [
|
||||
'model' => $ai->ollama_model,
|
||||
'prompt' => $prompt,
|
||||
'images' => [$imageB64],
|
||||
'stream' => false,
|
||||
]);
|
||||
|
||||
if ($response->failed()) {
|
||||
throw new \RuntimeException('Ollama API Fehler: ' . $response->status());
|
||||
}
|
||||
|
||||
$raw = $response->json('response', '');
|
||||
$data = $this->parseJson($raw);
|
||||
|
||||
if (!$data) {
|
||||
throw new \RuntimeException('Ollama-Antwort konnte nicht als JSON geparst werden: ' . $raw);
|
||||
}
|
||||
|
||||
// Hersteller suchen oder anlegen
|
||||
$manufacturer = null;
|
||||
if (!empty($data['manufacturer'])) {
|
||||
$manufacturer = Manufacturer::firstOrCreate(
|
||||
['name' => trim($data['manufacturer'])]
|
||||
);
|
||||
}
|
||||
|
||||
// Rescan: bestehenden Lack updaten
|
||||
if ($import->nail_polish_id) {
|
||||
$nailPolish = NailPolish::findOrFail($import->nail_polish_id);
|
||||
$nailPolish->update([
|
||||
'name' => $data['name'] ?? $nailPolish->name,
|
||||
'number' => $data['number'] ?? $nailPolish->number,
|
||||
'manufacturer_id' => $manufacturer?->id ?? $nailPolish->manufacturer_id,
|
||||
]);
|
||||
} else {
|
||||
// Neuen Lack anlegen
|
||||
$number = $data['number'] ?? ('import-' . $this->importId);
|
||||
if (NailPolish::where('number', $number)->exists()) {
|
||||
$number .= '-' . $this->importId;
|
||||
}
|
||||
|
||||
$nailPolish = NailPolish::create([
|
||||
'name' => $data['name'] ?? 'Unbekannt',
|
||||
'number' => $number,
|
||||
'manufacturer_id' => $manufacturer?->id,
|
||||
'image_path' => $import->image_path,
|
||||
]);
|
||||
|
||||
// Zur Sammlung des Users hinzufügen
|
||||
$import->user->nailPolishes()->syncWithoutDetaching([$nailPolish->id]);
|
||||
}
|
||||
|
||||
$import->update([
|
||||
'status' => 'done',
|
||||
'result' => $data,
|
||||
'nail_polish_id' => $nailPolish->id,
|
||||
]);
|
||||
|
||||
} catch (\Throwable $e) {
|
||||
Log::error('ProcessNailPolishImage fehlgeschlagen', [
|
||||
'import_id' => $this->importId,
|
||||
'error' => $e->getMessage(),
|
||||
]);
|
||||
|
||||
$import->update([
|
||||
'status' => 'failed',
|
||||
'error_message' => $e->getMessage(),
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
private function parseJson(string $raw): ?array
|
||||
{
|
||||
// JSON aus der Antwort extrahieren (Ollama kann Text drumherum haben)
|
||||
if (preg_match('/\{.*\}/s', $raw, $matches)) {
|
||||
$decoded = json_decode($matches[0], true);
|
||||
if (json_last_error() === JSON_ERROR_NONE) {
|
||||
return $decoded;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class AiSetting extends Model
|
||||
{
|
||||
protected $table = 'ai_settings';
|
||||
|
||||
protected $fillable = ['ollama_url', 'ollama_model', 'prompt'];
|
||||
|
||||
public const DEFAULT_PROMPT = <<<PROMPT
|
||||
You are analyzing a nail polish or nail product bottle/container image.
|
||||
Extract exactly these three fields and respond ONLY with a valid JSON object, no explanation, no markdown:
|
||||
{
|
||||
"name": "the full product name or color description (e.g. 'Modeling Base Calcium Neutral Pink', 'Ruby Red', 'French White')",
|
||||
"number": "the product code or article number printed on the label or cap (digits, letters, hyphens only — e.g. '12392-7', '123', 'NP-05')",
|
||||
"manufacturer": "the brand or company name (the logo/brand printed on the product — e.g. 'NEONAIL', 'OPI', 'essie', 'Catrice')"
|
||||
}
|
||||
Rules:
|
||||
- manufacturer = the brand/logo name (usually prominent on the label)
|
||||
- name = the descriptive product/color name (NOT the brand)
|
||||
- number = numeric or alphanumeric code (NOT the color name)
|
||||
- If a value is genuinely not visible, use null
|
||||
PROMPT;
|
||||
|
||||
public function getActivePrompt(): string
|
||||
{
|
||||
return !empty($this->prompt) ? $this->prompt : self::DEFAULT_PROMPT;
|
||||
}
|
||||
|
||||
public static function get(): self
|
||||
{
|
||||
return static::firstOrCreate([], [
|
||||
'ollama_url' => 'http://192.168.30.172:11434',
|
||||
'ollama_model' => 'llama3.2-vision',
|
||||
]);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,61 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class NailPolishImport extends Model
|
||||
{
|
||||
protected $fillable = [
|
||||
'user_id',
|
||||
'image_path',
|
||||
'status',
|
||||
'result',
|
||||
'nail_polish_id',
|
||||
'error_message',
|
||||
];
|
||||
|
||||
protected function casts(): array
|
||||
{
|
||||
return [
|
||||
'result' => 'array',
|
||||
];
|
||||
}
|
||||
|
||||
public function user()
|
||||
{
|
||||
return $this->belongsTo(User::class);
|
||||
}
|
||||
|
||||
public function nailPolish()
|
||||
{
|
||||
return $this->belongsTo(NailPolish::class);
|
||||
}
|
||||
|
||||
public function isPending(): bool
|
||||
{
|
||||
return in_array($this->status, ['pending', 'processing']);
|
||||
}
|
||||
|
||||
public function statusLabel(): string
|
||||
{
|
||||
return match ($this->status) {
|
||||
'pending' => 'Warten',
|
||||
'processing' => 'Verarbeitung',
|
||||
'done' => 'Fertig',
|
||||
'failed' => 'Fehler',
|
||||
default => $this->status,
|
||||
};
|
||||
}
|
||||
|
||||
public function statusColor(): string
|
||||
{
|
||||
return match ($this->status) {
|
||||
'pending' => 'warning',
|
||||
'processing' => 'info',
|
||||
'done' => 'success',
|
||||
'failed' => 'danger',
|
||||
default => 'secondary',
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,53 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class SsoSetting extends Model
|
||||
{
|
||||
protected $table = 'sso_settings';
|
||||
|
||||
protected $fillable = [
|
||||
'base_url',
|
||||
'client_id',
|
||||
'client_secret',
|
||||
'slug',
|
||||
'enabled',
|
||||
];
|
||||
|
||||
protected function casts(): array
|
||||
{
|
||||
return [
|
||||
'enabled' => 'boolean',
|
||||
];
|
||||
}
|
||||
|
||||
public static function get(): self
|
||||
{
|
||||
return static::firstOrCreate([]);
|
||||
}
|
||||
|
||||
public function isConfigured(): bool
|
||||
{
|
||||
return $this->enabled
|
||||
&& !empty($this->base_url)
|
||||
&& !empty($this->client_id)
|
||||
&& !empty($this->client_secret);
|
||||
}
|
||||
|
||||
public function authorizeUrl(): string
|
||||
{
|
||||
return rtrim($this->base_url, '/') . '/application/o/authorize/';
|
||||
}
|
||||
|
||||
public function tokenUrl(): string
|
||||
{
|
||||
return rtrim($this->base_url, '/') . '/application/o/token/';
|
||||
}
|
||||
|
||||
public function userInfoUrl(): string
|
||||
{
|
||||
return rtrim($this->base_url, '/') . '/application/o/userinfo/';
|
||||
}
|
||||
}
|
||||
+9
-1
@@ -22,6 +22,8 @@ class User extends Authenticatable
|
||||
'email',
|
||||
'password',
|
||||
'is_admin',
|
||||
'sso_provider_id',
|
||||
'is_sso_user',
|
||||
];
|
||||
|
||||
/**
|
||||
@@ -43,7 +45,8 @@ class User extends Authenticatable
|
||||
{
|
||||
return [
|
||||
'email_verified_at' => 'datetime',
|
||||
'password' => 'hashed',
|
||||
'password' => 'hashed',
|
||||
'is_sso_user' => 'boolean',
|
||||
];
|
||||
}
|
||||
|
||||
@@ -55,6 +58,11 @@ class User extends Authenticatable
|
||||
return $this->belongsToMany(NailPolish::class, 'user_nail_polishes', 'user_id', 'nail_polish_id');
|
||||
}
|
||||
|
||||
public function nailPolishImports()
|
||||
{
|
||||
return $this->hasMany(\App\Models\NailPolishImport::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* Prüft, ob der User ein Admin ist
|
||||
*/
|
||||
|
||||
@@ -0,0 +1,18 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
public function up(): void
|
||||
{
|
||||
// Duplicate of 2025_08_10_162556 — intentionally empty
|
||||
}
|
||||
|
||||
public function down(): void
|
||||
{
|
||||
//
|
||||
}
|
||||
};
|
||||
|
||||
@@ -11,9 +11,11 @@ return new class extends Migration
|
||||
*/
|
||||
public function up(): void
|
||||
{
|
||||
Schema::table('users', function (Blueprint $table) {
|
||||
$table->boolean('is_admin')->default(false)->after('password');
|
||||
});
|
||||
if (!Schema::hasColumn('users', 'is_admin')) {
|
||||
Schema::table('users', function (Blueprint $table) {
|
||||
$table->boolean('is_admin')->default(false)->after('password');
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -0,0 +1,33 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
public function up(): void
|
||||
{
|
||||
Schema::create('sso_settings', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->string('base_url')->nullable();
|
||||
$table->string('client_id')->nullable();
|
||||
$table->string('client_secret')->nullable();
|
||||
$table->string('slug')->nullable()->comment('Authentik Application Slug');
|
||||
$table->boolean('enabled')->default(false);
|
||||
$table->timestamps();
|
||||
});
|
||||
|
||||
// Leere Zeile anlegen, damit immer genau eine Konfiguration existiert
|
||||
DB::table('sso_settings')->insert([
|
||||
'enabled' => false,
|
||||
'created_at' => now(),
|
||||
'updated_at' => now(),
|
||||
]);
|
||||
}
|
||||
|
||||
public function down(): void
|
||||
{
|
||||
Schema::dropIfExists('sso_settings');
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,23 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
public function up(): void
|
||||
{
|
||||
Schema::table('users', function (Blueprint $table) {
|
||||
$table->string('sso_provider_id')->nullable()->unique()->after('email');
|
||||
$table->boolean('is_sso_user')->default(false)->after('sso_provider_id');
|
||||
});
|
||||
}
|
||||
|
||||
public function down(): void
|
||||
{
|
||||
Schema::table('users', function (Blueprint $table) {
|
||||
$table->dropColumn(['sso_provider_id', 'is_sso_user']);
|
||||
});
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,27 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
public function up(): void
|
||||
{
|
||||
Schema::create('nail_polish_imports', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->foreignId('user_id')->constrained()->cascadeOnDelete();
|
||||
$table->string('image_path');
|
||||
$table->enum('status', ['pending', 'processing', 'done', 'failed'])->default('pending');
|
||||
$table->json('result')->nullable();
|
||||
$table->foreignId('nail_polish_id')->nullable()->constrained('nail_polishes')->nullOnDelete();
|
||||
$table->text('error_message')->nullable();
|
||||
$table->timestamps();
|
||||
});
|
||||
}
|
||||
|
||||
public function down(): void
|
||||
{
|
||||
Schema::dropIfExists('nail_polish_imports');
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,30 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
public function up(): void
|
||||
{
|
||||
Schema::create('ai_settings', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->string('ollama_url')->default('http://192.168.30.172:11434');
|
||||
$table->string('ollama_model')->default('llama3.2-vision');
|
||||
$table->timestamps();
|
||||
});
|
||||
|
||||
DB::table('ai_settings')->insert([
|
||||
'ollama_url' => 'http://192.168.30.172:11434',
|
||||
'ollama_model' => 'llama3.2-vision',
|
||||
'created_at' => now(),
|
||||
'updated_at' => now(),
|
||||
]);
|
||||
}
|
||||
|
||||
public function down(): void
|
||||
{
|
||||
Schema::dropIfExists('ai_settings');
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,22 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
public function up(): void
|
||||
{
|
||||
Schema::table('ai_settings', function (Blueprint $table) {
|
||||
$table->text('prompt')->nullable()->after('ollama_model');
|
||||
});
|
||||
}
|
||||
|
||||
public function down(): void
|
||||
{
|
||||
Schema::table('ai_settings', function (Blueprint $table) {
|
||||
$table->dropColumn('prompt');
|
||||
});
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,12 @@
|
||||
[program:neonail-worker]
|
||||
process_name=%(program_name)s_%(process_num)02d
|
||||
command=php /var/www/html/artisan queue:work --sleep=3 --tries=2 --timeout=180
|
||||
autostart=true
|
||||
autorestart=true
|
||||
stopasgroup=true
|
||||
killasgroup=true
|
||||
user=www-data
|
||||
numprocs=1
|
||||
redirect_stderr=true
|
||||
stdout_logfile=/var/www/html/storage/logs/worker.log
|
||||
stopwaitsecs=180
|
||||
@@ -0,0 +1,103 @@
|
||||
@extends('layouts.app')
|
||||
|
||||
@section('title', 'KI-Einstellungen – NeoNail DB')
|
||||
|
||||
@section('content')
|
||||
|
||||
<div class="page-hero mb-4">
|
||||
<h1><i class="fas fa-robot me-2"></i>KI-Einstellungen</h1>
|
||||
<p>Ollama-Konfiguration für den automatischen Foto-Import</p>
|
||||
</div>
|
||||
|
||||
<div class="row g-4">
|
||||
<div class="col-lg-7">
|
||||
<div class="card">
|
||||
<div class="card-header"><i class="fas fa-cog me-2"></i>Ollama Verbindung</div>
|
||||
<div class="card-body p-4">
|
||||
<form method="POST" action="{{ route('admin.ai.update') }}">
|
||||
@csrf
|
||||
@method('PUT')
|
||||
|
||||
<div class="mb-3">
|
||||
<label class="form-label" for="ollama_url">Ollama URL <span class="text-danger">*</span></label>
|
||||
<input type="url" class="form-control @error('ollama_url') is-invalid @enderror"
|
||||
id="ollama_url" name="ollama_url"
|
||||
value="{{ old('ollama_url', $ai->ollama_url) }}"
|
||||
placeholder="http://192.168.30.172:11434">
|
||||
@error('ollama_url')
|
||||
<div class="invalid-feedback">{{ $message }}</div>
|
||||
@enderror
|
||||
<div class="form-text">URL des Ollama-Containers/Servers ohne abschließenden Slash.</div>
|
||||
</div>
|
||||
|
||||
<div class="mb-3">
|
||||
<label class="form-label" for="ollama_model">Modell <span class="text-danger">*</span></label>
|
||||
<input type="text" class="form-control @error('ollama_model') is-invalid @enderror"
|
||||
id="ollama_model" name="ollama_model"
|
||||
value="{{ old('ollama_model', $ai->ollama_model) }}"
|
||||
placeholder="llama3.2-vision">
|
||||
@error('ollama_model')
|
||||
<div class="invalid-feedback">{{ $message }}</div>
|
||||
@enderror
|
||||
<div class="form-text">Muss ein Vision-fähiges Modell sein (z.B. <code>llama3.2-vision</code>, <code>llava</code>).</div>
|
||||
</div>
|
||||
|
||||
<div class="mb-4">
|
||||
<label class="form-label" for="prompt">
|
||||
Erkennungs-Prompt
|
||||
<span class="badge bg-secondary ms-1" style="font-size:.65rem;">optional</span>
|
||||
</label>
|
||||
<textarea class="form-control @error('prompt') is-invalid @enderror"
|
||||
id="prompt" name="prompt" rows="12"
|
||||
placeholder="Leer lassen für Standard-Prompt"
|
||||
style="font-family: monospace; font-size: .82rem;">{{ old('prompt', $ai->prompt) }}</textarea>
|
||||
@error('prompt')
|
||||
<div class="invalid-feedback">{{ $message }}</div>
|
||||
@enderror
|
||||
<div class="form-text">
|
||||
Leer lassen um den Standard-Prompt zu verwenden.
|
||||
<a href="#" onclick="resetPrompt(); return false;">Standard-Prompt einfügen</a>
|
||||
</div>
|
||||
<div class="mt-2 p-3" style="background:#f9fafb; border-radius:10px; border:1px solid #e5e7eb;">
|
||||
<p style="font-size:.75rem; color:#6b7280; margin:0 0 6px; font-weight:600;">AKTUELL AKTIVER PROMPT:</p>
|
||||
<pre style="font-size:.75rem; color:#374151; margin:0; white-space:pre-wrap; word-break:break-word;">{{ $ai->getActivePrompt() }}</pre>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<button type="submit" class="btn btn-primary">
|
||||
<i class="fas fa-save me-2"></i>Speichern
|
||||
</button>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="col-lg-5">
|
||||
<div class="card">
|
||||
<div class="card-header"><i class="fas fa-info-circle me-2"></i>Queue Worker</div>
|
||||
<div class="card-body p-3">
|
||||
<p style="font-size:.83rem; color:#374151; margin-bottom:10px;">
|
||||
Jobs werden über die <strong>Datenbank-Queue</strong> verarbeitet. Auf dem Server muss dauerhaft ein Worker laufen:
|
||||
</p>
|
||||
<code style="display:block; background:#f3f4f6; padding:10px 12px; border-radius:8px; font-size:.78rem; white-space:pre-wrap;">php artisan queue:work \
|
||||
--timeout=180 \
|
||||
--tries=2 \
|
||||
--sleep=3</code>
|
||||
<p style="font-size:.78rem; color:#9ca3af; margin-top:10px; margin-bottom:0;">
|
||||
Empfohlen: Als Supervisor-Dienst einrichten, damit der Worker nach Crashes neu startet.
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@endsection
|
||||
|
||||
@section('scripts')
|
||||
<script>
|
||||
const defaultPrompt = @json($defaultPrompt);
|
||||
function resetPrompt() {
|
||||
document.getElementById('prompt').value = defaultPrompt;
|
||||
}
|
||||
</script>
|
||||
@endsection
|
||||
@@ -0,0 +1,222 @@
|
||||
@extends('layouts.app')
|
||||
|
||||
@section('title', 'SSO-Konfiguration – NeoNail DB')
|
||||
|
||||
@section('content')
|
||||
|
||||
<div class="page-hero d-flex align-items-center justify-content-between flex-wrap gap-3 mb-4">
|
||||
<div>
|
||||
<h1><i class="fas fa-shield-alt me-2"></i>Single Sign-On</h1>
|
||||
<p>Authentik OAuth2/OIDC Konfiguration</p>
|
||||
</div>
|
||||
<span class="count-chip">
|
||||
@if($sso->isConfigured())
|
||||
<i class="fas fa-circle text-success" style="font-size:.6rem"></i> Aktiv
|
||||
@else
|
||||
<i class="fas fa-circle text-danger" style="font-size:.6rem"></i> Nicht konfiguriert
|
||||
@endif
|
||||
</span>
|
||||
</div>
|
||||
|
||||
{{-- Status-Banner --}}
|
||||
@if($sso->isConfigured())
|
||||
<div class="alert alert-success mb-4">
|
||||
<i class="fas fa-check-circle me-2"></i>
|
||||
SSO ist aktiv. Auf der Login-Seite wird der <strong>„Mit Authentik anmelden"</strong>-Button angezeigt.
|
||||
</div>
|
||||
@elseif($sso->enabled && !$sso->isConfigured())
|
||||
<div class="alert alert-warning mb-4">
|
||||
<i class="fas fa-exclamation-triangle me-2"></i>
|
||||
SSO ist aktiviert, aber die Konfiguration ist unvollständig. Bitte alle Felder ausfüllen.
|
||||
</div>
|
||||
@endif
|
||||
|
||||
<div class="row g-4">
|
||||
|
||||
{{-- Konfigurationsformular --}}
|
||||
<div class="col-lg-8">
|
||||
<div class="card">
|
||||
<div class="card-header">
|
||||
<i class="fas fa-cog me-2"></i>Einstellungen
|
||||
</div>
|
||||
<div class="card-body p-4">
|
||||
<form method="POST" action="{{ route('admin.sso.update') }}">
|
||||
@csrf
|
||||
@method('PUT')
|
||||
|
||||
{{-- Aktivieren --}}
|
||||
<div class="mb-4">
|
||||
<div class="form-check form-switch">
|
||||
<input class="form-check-input" type="checkbox" role="switch"
|
||||
name="enabled" id="enabled" value="1"
|
||||
{{ $sso->enabled ? 'checked' : '' }}>
|
||||
<label class="form-check-label fw-semibold" for="enabled">
|
||||
SSO aktivieren
|
||||
</label>
|
||||
</div>
|
||||
<div class="form-text mt-1">
|
||||
Nur wenn aktiviert <em>und</em> alle Felder ausgefüllt sind, erscheint der SSO-Button auf der Login-Seite.
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<hr class="my-4">
|
||||
|
||||
{{-- Base URL --}}
|
||||
<div class="mb-3">
|
||||
<label class="form-label" for="base_url">
|
||||
Authentik Base URL <span class="text-danger">*</span>
|
||||
</label>
|
||||
<input type="url" class="form-control @error('base_url') is-invalid @enderror"
|
||||
id="base_url" name="base_url"
|
||||
value="{{ old('base_url', $sso->base_url) }}"
|
||||
placeholder="https://authentik.example.com">
|
||||
@error('base_url')
|
||||
<div class="invalid-feedback">{{ $message }}</div>
|
||||
@enderror
|
||||
<div class="form-text">Die URL deiner Authentik-Instanz, ohne abschließenden Slash.</div>
|
||||
</div>
|
||||
|
||||
{{-- Client ID --}}
|
||||
<div class="mb-3">
|
||||
<label class="form-label" for="client_id">
|
||||
Client ID <span class="text-danger">*</span>
|
||||
</label>
|
||||
<input type="text" class="form-control @error('client_id') is-invalid @enderror"
|
||||
id="client_id" name="client_id"
|
||||
value="{{ old('client_id', $sso->client_id) }}"
|
||||
placeholder="xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
|
||||
autocomplete="off">
|
||||
@error('client_id')
|
||||
<div class="invalid-feedback">{{ $message }}</div>
|
||||
@enderror
|
||||
</div>
|
||||
|
||||
{{-- Client Secret --}}
|
||||
<div class="mb-3">
|
||||
<label class="form-label" for="client_secret">
|
||||
Client Secret <span class="text-danger">*</span>
|
||||
</label>
|
||||
<div class="input-group">
|
||||
<input type="password" class="form-control @error('client_secret') is-invalid @enderror"
|
||||
id="client_secret" name="client_secret"
|
||||
value="{{ old('client_secret', $sso->client_secret) }}"
|
||||
placeholder="{{ $sso->client_secret ? '••••••••••••••••' : 'Client Secret eingeben' }}"
|
||||
autocomplete="off">
|
||||
<button class="btn btn-outline-secondary" type="button"
|
||||
onclick="toggleSecret()" id="toggleSecretBtn">
|
||||
<i class="fas fa-eye" id="toggleSecretIcon"></i>
|
||||
</button>
|
||||
</div>
|
||||
@error('client_secret')
|
||||
<div class="invalid-feedback d-block">{{ $message }}</div>
|
||||
@enderror
|
||||
</div>
|
||||
|
||||
{{-- Slug --}}
|
||||
<div class="mb-4">
|
||||
<label class="form-label" for="slug">
|
||||
Application Slug
|
||||
<span class="badge bg-secondary ms-1" style="font-size:.65rem">optional</span>
|
||||
</label>
|
||||
<input type="text" class="form-control @error('slug') is-invalid @enderror"
|
||||
id="slug" name="slug"
|
||||
value="{{ old('slug', $sso->slug) }}"
|
||||
placeholder="neonail-db">
|
||||
@error('slug')
|
||||
<div class="invalid-feedback">{{ $message }}</div>
|
||||
@enderror
|
||||
<div class="form-text">Nur zur Dokumentation – wird nicht im OAuth2-Flow verwendet.</div>
|
||||
</div>
|
||||
|
||||
<div class="d-flex gap-2">
|
||||
<button type="submit" class="btn btn-primary">
|
||||
<i class="fas fa-save me-2"></i>Speichern
|
||||
</button>
|
||||
@if($sso->isConfigured())
|
||||
<a href="{{ route('sso.redirect') }}" target="_blank" class="btn btn-outline-secondary">
|
||||
<i class="fas fa-external-link-alt me-2"></i>SSO testen
|
||||
</a>
|
||||
@endif
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{{-- Info-Sidebar --}}
|
||||
<div class="col-lg-4">
|
||||
|
||||
{{-- Callback URL --}}
|
||||
<div class="card mb-3">
|
||||
<div class="card-header">
|
||||
<i class="fas fa-link me-2"></i>Redirect URI
|
||||
</div>
|
||||
<div class="card-body p-3">
|
||||
<p style="font-size:.82rem; color:#6b7280; margin-bottom:8px;">
|
||||
Diese URL musst du in Authentik als <strong>Redirect URI</strong> eintragen:
|
||||
</p>
|
||||
<div class="d-flex align-items-center gap-2">
|
||||
<code style="font-size:.78rem; background:#f3f4f6; padding:8px 10px; border-radius:8px; flex:1; word-break:break-all;">
|
||||
{{ route('sso.callback') }}
|
||||
</code>
|
||||
<button class="btn btn-sm btn-outline-secondary flex-shrink-0"
|
||||
onclick="copyRedirectUri()" title="Kopieren">
|
||||
<i class="fas fa-copy" id="copyIcon"></i>
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{{-- Setup-Anleitung --}}
|
||||
<div class="card">
|
||||
<div class="card-header">
|
||||
<i class="fas fa-book me-2"></i>Setup in Authentik
|
||||
</div>
|
||||
<div class="card-body p-3">
|
||||
<ol style="font-size:.83rem; color:#374151; padding-left:1.2rem; margin:0; line-height:1.8;">
|
||||
<li>In Authentik: <strong>Applications → Create</strong></li>
|
||||
<li>Provider-Typ: <strong>OAuth2/OpenID Provider</strong></li>
|
||||
<li>Authorization flow wählen</li>
|
||||
<li>Redirect URI eintragen (siehe links)</li>
|
||||
<li><strong>Client ID</strong> und <strong>Client Secret</strong> kopieren</li>
|
||||
<li>Hier eintragen und speichern</li>
|
||||
</ol>
|
||||
|
||||
<hr style="margin: 12px 0;">
|
||||
|
||||
<p style="font-size:.78rem; color:#9ca3af; margin:0;">
|
||||
<i class="fas fa-info-circle me-1"></i>
|
||||
Scopes: <code>openid email profile</code>
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@endsection
|
||||
|
||||
@section('scripts')
|
||||
<script>
|
||||
function toggleSecret() {
|
||||
const input = document.getElementById('client_secret');
|
||||
const icon = document.getElementById('toggleSecretIcon');
|
||||
if (input.type === 'password') {
|
||||
input.type = 'text';
|
||||
icon.classList.replace('fa-eye', 'fa-eye-slash');
|
||||
} else {
|
||||
input.type = 'password';
|
||||
icon.classList.replace('fa-eye-slash', 'fa-eye');
|
||||
}
|
||||
}
|
||||
|
||||
function copyRedirectUri() {
|
||||
const uri = @json(route('sso.callback'));
|
||||
const icon = document.getElementById('copyIcon');
|
||||
navigator.clipboard.writeText(uri).then(() => {
|
||||
icon.classList.replace('fa-copy', 'fa-check');
|
||||
setTimeout(() => icon.classList.replace('fa-check', 'fa-copy'), 2000);
|
||||
});
|
||||
}
|
||||
</script>
|
||||
@endsection
|
||||
@@ -74,6 +74,21 @@
|
||||
</button>
|
||||
</form>
|
||||
|
||||
@php $sso = \App\Models\SsoSetting::get(); @endphp
|
||||
@if($sso->isConfigured())
|
||||
<div class="d-flex align-items-center my-4" style="gap:12px;">
|
||||
<hr style="flex:1; border-color:rgba(0,0,0,.12); margin:0;">
|
||||
<span style="font-size:.78rem; color:#9ca3af; white-space:nowrap;">oder</span>
|
||||
<hr style="flex:1; border-color:rgba(0,0,0,.12); margin:0;">
|
||||
</div>
|
||||
<a href="{{ route('sso.redirect') }}" class="btn btn-outline-secondary w-100 btn-lg d-flex align-items-center justify-content-center gap-2">
|
||||
<svg width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
|
||||
<circle cx="12" cy="12" r="10"/><path d="M12 2a14.5 14.5 0 0 0 0 20A14.5 14.5 0 0 0 12 2"/><path d="M2 12h20"/>
|
||||
</svg>
|
||||
Mit Authentik anmelden
|
||||
</a>
|
||||
@endif
|
||||
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
@@ -456,6 +456,12 @@
|
||||
<i class="fas fa-industry me-1"></i>Hersteller
|
||||
</a>
|
||||
</li>
|
||||
<li class="nav-item">
|
||||
<a class="nav-link {{ request()->routeIs('nail-polish-imports.*') ? 'active' : '' }}"
|
||||
href="{{ route('nail-polish-imports.create') }}">
|
||||
<i class="fas fa-camera me-1"></i>Foto importieren
|
||||
</a>
|
||||
</li>
|
||||
@if(auth()->user()->isAdmin())
|
||||
<li class="nav-item dropdown">
|
||||
<a class="nav-link dropdown-toggle {{ request()->routeIs('admin.*') || request()->routeIs('nail-polishes.*') ? 'active' : '' }}"
|
||||
@@ -471,6 +477,11 @@
|
||||
<i class="fas fa-palette me-2"></i>Nagellacke</a></li>
|
||||
<li><a class="dropdown-item" href="{{ route('admin.statistics') }}">
|
||||
<i class="fas fa-chart-bar me-2"></i>Statistiken</a></li>
|
||||
<li><hr class="dropdown-divider" style="border-color:rgba(255,255,255,0.1);"></li>
|
||||
<li><a class="dropdown-item" href="{{ route('admin.sso.show') }}">
|
||||
<i class="fas fa-shield-alt me-2"></i>SSO-Konfiguration</a></li>
|
||||
<li><a class="dropdown-item" href="{{ route('admin.ai.show') }}">
|
||||
<i class="fas fa-robot me-2"></i>KI-Einstellungen</a></li>
|
||||
</ul>
|
||||
</li>
|
||||
@endif
|
||||
|
||||
@@ -0,0 +1,150 @@
|
||||
@extends('layouts.app')
|
||||
|
||||
@section('title', 'Foto importieren – NeoNail DB')
|
||||
|
||||
@section('content')
|
||||
|
||||
<div class="page-hero mb-4">
|
||||
<h1><i class="fas fa-camera me-2"></i>Foto importieren</h1>
|
||||
<p>Lade ein Foto deines Nagellacks hoch – die KI erkennt Name, Nummer und Hersteller automatisch.</p>
|
||||
</div>
|
||||
|
||||
<div class="row justify-content-center">
|
||||
<div class="col-lg-6">
|
||||
<div class="card">
|
||||
<div class="card-body p-4">
|
||||
<div id="errorBox" class="alert alert-danger mb-3 d-none"></div>
|
||||
|
||||
<div class="mb-4">
|
||||
<label class="form-label">Foto des Nagellacks</label>
|
||||
|
||||
<div id="dropzone"
|
||||
style="border: 2px dashed #d1d5db; border-radius: 16px; padding: 48px 20px;
|
||||
text-align: center; cursor: pointer; transition: all .2s;"
|
||||
onclick="document.getElementById('image').click()">
|
||||
<div id="dropzoneContent">
|
||||
<i class="fas fa-cloud-upload-alt" style="font-size: 2.5rem; color: #9ca3af; margin-bottom: 12px; display: block;"></i>
|
||||
<p style="color: #6b7280; margin: 0; font-weight: 500;">Foto hierher ziehen oder klicken</p>
|
||||
<p style="color: #9ca3af; font-size: .8rem; margin: 4px 0 0;">JPG, PNG, WebP – max. 10 MB</p>
|
||||
</div>
|
||||
<img id="preview" src="" alt="" style="display:none; max-height:280px; border-radius:10px; max-width:100%;">
|
||||
</div>
|
||||
|
||||
<input type="file" id="image" name="image" accept="image/*" class="d-none">
|
||||
</div>
|
||||
|
||||
{{-- Upload-Progress --}}
|
||||
<div id="progressWrap" class="d-none mb-3">
|
||||
<div class="d-flex justify-content-between mb-1" style="font-size:.82rem; color:#6b7280;">
|
||||
<span>Wird hochgeladen…</span>
|
||||
<span id="progressPct">0%</span>
|
||||
</div>
|
||||
<div class="progress" style="height:6px; border-radius:3px;">
|
||||
<div id="progressBar" class="progress-bar"
|
||||
style="width:0%; background:linear-gradient(135deg,#7c3aed,#ec4899); transition:width .2s;"></div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<button id="submitBtn" class="btn btn-primary w-100 btn-lg" onclick="startUpload()" disabled>
|
||||
<i class="fas fa-magic me-2"></i>KI-Analyse starten
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="text-center mt-3">
|
||||
<a href="{{ route('nail-polish-imports.index') }}" style="color: rgba(255,255,255,.65); font-size:.85rem;">
|
||||
<i class="fas fa-history me-1"></i>Meine Importe ansehen
|
||||
</a>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@endsection
|
||||
|
||||
@section('scripts')
|
||||
<script>
|
||||
const dropzone = document.getElementById('dropzone');
|
||||
const input = document.getElementById('image');
|
||||
const preview = document.getElementById('preview');
|
||||
const content = document.getElementById('dropzoneContent');
|
||||
const submitBtn = document.getElementById('submitBtn');
|
||||
|
||||
input.addEventListener('change', e => { if (e.target.files[0]) selectFile(e.target.files[0]); });
|
||||
|
||||
dropzone.addEventListener('dragover', e => { e.preventDefault(); dropzone.style.borderColor = '#7c3aed'; });
|
||||
dropzone.addEventListener('dragleave', () => { dropzone.style.borderColor = '#d1d5db'; });
|
||||
dropzone.addEventListener('drop', e => {
|
||||
e.preventDefault();
|
||||
dropzone.style.borderColor = '#d1d5db';
|
||||
const file = e.dataTransfer.files[0];
|
||||
if (file) { input.files = e.dataTransfer.files; selectFile(file); }
|
||||
});
|
||||
|
||||
function selectFile(file) {
|
||||
const reader = new FileReader();
|
||||
reader.onload = e => {
|
||||
preview.src = e.target.result;
|
||||
preview.style.display = 'block';
|
||||
content.style.display = 'none';
|
||||
};
|
||||
reader.readAsDataURL(file);
|
||||
submitBtn.disabled = false;
|
||||
}
|
||||
|
||||
function startUpload() {
|
||||
const file = input.files[0];
|
||||
if (!file) return;
|
||||
|
||||
submitBtn.disabled = true;
|
||||
submitBtn.innerHTML = '<span class="spinner-border spinner-border-sm me-2"></span>Wird hochgeladen…';
|
||||
document.getElementById('progressWrap').classList.remove('d-none');
|
||||
document.getElementById('errorBox').classList.add('d-none');
|
||||
|
||||
const formData = new FormData();
|
||||
formData.append('image', file);
|
||||
formData.append('_token', '{{ csrf_token() }}');
|
||||
|
||||
const xhr = new XMLHttpRequest();
|
||||
|
||||
xhr.upload.addEventListener('progress', e => {
|
||||
if (e.lengthComputable) {
|
||||
const pct = Math.round(e.loaded / e.total * 100);
|
||||
document.getElementById('progressBar').style.width = pct + '%';
|
||||
document.getElementById('progressPct').textContent = pct + '%';
|
||||
}
|
||||
});
|
||||
|
||||
xhr.addEventListener('load', () => {
|
||||
if (xhr.status === 200) {
|
||||
try {
|
||||
const data = JSON.parse(xhr.responseText);
|
||||
if (data.redirect) { window.location.href = data.redirect; return; }
|
||||
} catch(e) {}
|
||||
}
|
||||
showError('Upload fehlgeschlagen (Status ' + xhr.status + '). Bitte erneut versuchen.');
|
||||
resetBtn();
|
||||
});
|
||||
|
||||
xhr.addEventListener('error', () => {
|
||||
showError('Netzwerkfehler beim Upload. Bitte erneut versuchen.');
|
||||
resetBtn();
|
||||
});
|
||||
|
||||
xhr.open('POST', '{{ route('nail-polish-imports.store') }}');
|
||||
xhr.setRequestHeader('X-Requested-With', 'XMLHttpRequest');
|
||||
xhr.send(formData);
|
||||
}
|
||||
|
||||
function showError(msg) {
|
||||
const box = document.getElementById('errorBox');
|
||||
box.textContent = msg;
|
||||
box.classList.remove('d-none');
|
||||
document.getElementById('progressWrap').classList.add('d-none');
|
||||
}
|
||||
|
||||
function resetBtn() {
|
||||
submitBtn.disabled = false;
|
||||
submitBtn.innerHTML = '<i class="fas fa-magic me-2"></i>KI-Analyse starten';
|
||||
}
|
||||
</script>
|
||||
@endsection
|
||||
@@ -0,0 +1,83 @@
|
||||
@extends('layouts.app')
|
||||
|
||||
@section('title', 'Meine Importe – NeoNail DB')
|
||||
|
||||
@section('content')
|
||||
|
||||
<div class="page-hero d-flex align-items-center justify-content-between flex-wrap gap-3 mb-4">
|
||||
<div>
|
||||
<h1><i class="fas fa-history me-2"></i>Meine Importe</h1>
|
||||
<p>KI-Analysen deiner hochgeladenen Fotos</p>
|
||||
</div>
|
||||
<a href="{{ route('nail-polish-imports.create') }}" class="btn btn-glass">
|
||||
<i class="fas fa-camera me-2"></i>Neues Foto
|
||||
</a>
|
||||
</div>
|
||||
|
||||
@if($imports->isEmpty())
|
||||
<div class="empty-state">
|
||||
<div class="empty-icon"><i class="fas fa-camera"></i></div>
|
||||
<h4>Noch keine Importe</h4>
|
||||
<p>Lade ein Foto hoch und lass die KI deinen Nagellack erkennen.</p>
|
||||
<a href="{{ route('nail-polish-imports.create') }}" class="btn btn-primary">
|
||||
<i class="fas fa-camera me-2"></i>Jetzt importieren
|
||||
</a>
|
||||
</div>
|
||||
@else
|
||||
<div class="card">
|
||||
<div class="card-body p-0">
|
||||
<div class="table-responsive">
|
||||
<table class="table mb-0" style="font-size:.875rem;">
|
||||
<thead style="background:#f9fafb; border-bottom:1px solid #f3f4f6;">
|
||||
<tr>
|
||||
<th style="padding:12px 16px; font-weight:600; color:#374151;">Bild</th>
|
||||
<th style="padding:12px 16px; font-weight:600; color:#374151;">Ergebnis</th>
|
||||
<th style="padding:12px 16px; font-weight:600; color:#374151;">Status</th>
|
||||
<th style="padding:12px 16px; font-weight:600; color:#374151;">Datum</th>
|
||||
<th style="padding:12px 16px;"></th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
@foreach($imports as $import)
|
||||
<tr style="border-bottom:1px solid #f3f4f6;">
|
||||
<td style="padding:12px 16px;">
|
||||
<img src="{{ Storage::url($import->image_path) }}"
|
||||
alt=""
|
||||
style="width:52px; height:52px; object-fit:cover; border-radius:10px;">
|
||||
</td>
|
||||
<td style="padding:12px 16px;">
|
||||
@if($import->result)
|
||||
<div style="font-weight:600; color:#111827;">{{ $import->result['name'] ?? '—' }}</div>
|
||||
<div style="color:#9ca3af; font-size:.78rem;">{{ $import->result['manufacturer'] ?? '' }}</div>
|
||||
@elseif($import->status === 'failed')
|
||||
<span style="color:#dc2626; font-size:.8rem;">{{ Str::limit($import->error_message, 60) }}</span>
|
||||
@else
|
||||
<span style="color:#9ca3af;">wird analysiert…</span>
|
||||
@endif
|
||||
</td>
|
||||
<td style="padding:12px 16px;">
|
||||
<span class="badge bg-{{ $import->statusColor() }}">{{ $import->statusLabel() }}</span>
|
||||
</td>
|
||||
<td style="padding:12px 16px; color:#9ca3af;">
|
||||
{{ $import->created_at->format('d.m.Y H:i') }}
|
||||
</td>
|
||||
<td style="padding:12px 16px; text-align:right;">
|
||||
<a href="{{ route('nail-polish-imports.show', $import) }}"
|
||||
class="btn btn-outline-secondary btn-sm">
|
||||
<i class="fas fa-eye"></i>
|
||||
</a>
|
||||
</td>
|
||||
</tr>
|
||||
@endforeach
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="mt-3">
|
||||
{{ $imports->links() }}
|
||||
</div>
|
||||
@endif
|
||||
|
||||
@endsection
|
||||
@@ -0,0 +1,118 @@
|
||||
@extends('layouts.app')
|
||||
|
||||
@section('title', 'Import-Status – NeoNail DB')
|
||||
|
||||
@php $pending = $import->isPending(); @endphp
|
||||
|
||||
@if($pending)
|
||||
<meta http-equiv="refresh" content="5">
|
||||
@endif
|
||||
|
||||
@section('content')
|
||||
|
||||
<div class="page-hero mb-4">
|
||||
<h1><i class="fas fa-magic me-2"></i>KI-Analyse</h1>
|
||||
<p>
|
||||
<span class="badge bg-{{ $import->statusColor() }} fs-6">
|
||||
{{ $import->statusLabel() }}
|
||||
</span>
|
||||
</p>
|
||||
</div>
|
||||
|
||||
<div class="row g-4 justify-content-center">
|
||||
|
||||
{{-- Bild --}}
|
||||
<div class="col-md-4">
|
||||
<div class="card">
|
||||
<div class="card-body p-3 text-center">
|
||||
<img src="{{ Storage::url($import->image_path) }}"
|
||||
alt="Importiertes Bild"
|
||||
style="max-width:100%; border-radius:12px; max-height:320px; object-fit:contain;">
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{{-- Status / Ergebnis --}}
|
||||
<div class="col-md-6">
|
||||
<div class="card">
|
||||
<div class="card-header">
|
||||
@if($pending)
|
||||
<i class="fas fa-spinner fa-spin me-2"></i>KI analysiert das Bild…
|
||||
@elseif($import->status === 'done')
|
||||
<i class="fas fa-check-circle text-success me-2"></i>Ergebnis
|
||||
@else
|
||||
<i class="fas fa-exclamation-circle text-danger me-2"></i>Fehler
|
||||
@endif
|
||||
</div>
|
||||
<div class="card-body p-4">
|
||||
|
||||
@if($pending)
|
||||
<p style="color:#6b7280;">
|
||||
Ollama verarbeitet das Bild gerade. Diese Seite aktualisiert sich automatisch alle 5 Sekunden.
|
||||
</p>
|
||||
<div class="progress" style="height:6px; border-radius:3px;">
|
||||
<div class="progress-bar progress-bar-striped progress-bar-animated"
|
||||
style="width:100%; background: linear-gradient(135deg,#7c3aed,#ec4899);"></div>
|
||||
</div>
|
||||
|
||||
@elseif($import->status === 'done')
|
||||
@php $result = $import->result; @endphp
|
||||
<table class="table table-borderless mb-0">
|
||||
<tr>
|
||||
<th style="width:130px; color:#6b7280; font-size:.85rem;">Name</th>
|
||||
<td style="font-weight:600;">{{ $result['name'] ?? '—' }}</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th style="color:#6b7280; font-size:.85rem;">Nummer</th>
|
||||
<td>{{ $result['number'] ?? '—' }}</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th style="color:#6b7280; font-size:.85rem;">Hersteller</th>
|
||||
<td>{{ $result['manufacturer'] ?? '—' }}</td>
|
||||
</tr>
|
||||
@if($import->nailPolish)
|
||||
<tr>
|
||||
<th style="color:#6b7280; font-size:.85rem;">In Sammlung</th>
|
||||
<td>
|
||||
<span class="badge" style="background:linear-gradient(135deg,#7c3aed,#ec4899);">
|
||||
<i class="fas fa-check me-1"></i>Hinzugefügt
|
||||
</span>
|
||||
</td>
|
||||
</tr>
|
||||
@endif
|
||||
</table>
|
||||
|
||||
@if($import->nailPolish)
|
||||
<div class="mt-3">
|
||||
<a href="{{ route('user-nail-polishes.index') }}" class="btn btn-primary btn-sm">
|
||||
<i class="fas fa-home me-1"></i>Zur Sammlung
|
||||
</a>
|
||||
</div>
|
||||
@endif
|
||||
|
||||
@else
|
||||
<div class="alert alert-danger mb-3">
|
||||
<i class="fas fa-exclamation-circle me-2"></i>
|
||||
{{ $import->error_message ?? 'Unbekannter Fehler' }}
|
||||
</div>
|
||||
<a href="{{ route('nail-polish-imports.create') }}" class="btn btn-primary btn-sm">
|
||||
<i class="fas fa-redo me-1"></i>Nochmal versuchen
|
||||
</a>
|
||||
@endif
|
||||
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="mt-3 d-flex gap-3 align-items-center">
|
||||
<a href="{{ route('nail-polish-imports.create') }}" class="btn btn-glass btn-sm">
|
||||
<i class="fas fa-camera me-1"></i>Weiteres Foto hochladen
|
||||
</a>
|
||||
<a href="{{ route('nail-polish-imports.index') }}" style="color:rgba(255,255,255,.65); font-size:.85rem;">
|
||||
<i class="fas fa-history me-1"></i>Alle Importe
|
||||
</a>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
|
||||
@endsection
|
||||
@@ -65,13 +65,23 @@
|
||||
<span class="np-brand">{{ $nailPolish->manufacturer->name }}</span>
|
||||
@endif
|
||||
</div>
|
||||
<div class="mt-3">
|
||||
<div class="mt-3 d-flex flex-column gap-2">
|
||||
<form method="POST" action="{{ route('user-nail-polishes.add', $nailPolish) }}">
|
||||
@csrf
|
||||
<button type="submit" class="btn btn-success btn-sm w-100">
|
||||
<i class="fas fa-plus me-1"></i>Zur Sammlung
|
||||
</button>
|
||||
</form>
|
||||
@if(auth()->user()->isAdmin())
|
||||
<form method="POST" action="{{ route('nail-polishes.destroy', $nailPolish) }}"
|
||||
onsubmit="return confirm('Lack dauerhaft aus dem Katalog löschen?')">
|
||||
@csrf
|
||||
@method('DELETE')
|
||||
<button type="submit" class="btn btn-outline-danger btn-sm w-100">
|
||||
<i class="fas fa-trash-alt me-1"></i>Löschen
|
||||
</button>
|
||||
</form>
|
||||
@endif
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -65,7 +65,15 @@
|
||||
<span class="np-brand">{{ $nailPolish->manufacturer->name }}</span>
|
||||
@endif
|
||||
</div>
|
||||
<div class="mt-3">
|
||||
<div class="mt-3 d-flex flex-column gap-2">
|
||||
@if($nailPolish->image_path)
|
||||
<form method="POST" action="{{ route('nail-polishes.rescan', $nailPolish) }}">
|
||||
@csrf
|
||||
<button type="submit" class="btn btn-outline-secondary btn-sm w-100">
|
||||
<i class="fas fa-sync-alt me-1"></i>KI-Rescan
|
||||
</button>
|
||||
</form>
|
||||
@endif
|
||||
<form method="POST" action="{{ route('user-nail-polishes.remove', $nailPolish) }}"
|
||||
onsubmit="return confirm('Lack aus der Sammlung entfernen?')">
|
||||
@csrf
|
||||
|
||||
@@ -5,6 +5,10 @@ use App\Http\Controllers\NailPolishController;
|
||||
use App\Http\Controllers\UserNailPolishController;
|
||||
use App\Http\Controllers\AdminController;
|
||||
use App\Http\Controllers\Auth\LoginController;
|
||||
use App\Http\Controllers\Auth\SsoController;
|
||||
use App\Http\Controllers\Admin\SsoSettingController;
|
||||
use App\Http\Controllers\Admin\AiSettingController;
|
||||
use App\Http\Controllers\NailPolishImportController;
|
||||
use App\Http\Controllers\ManufacturerController;
|
||||
|
||||
// Startseite
|
||||
@@ -16,8 +20,12 @@ Route::get('/', function () {
|
||||
Route::middleware('guest')->group(function () {
|
||||
Route::get('/login', [LoginController::class, 'showLoginForm'])->name('login');
|
||||
Route::post('/login', [LoginController::class, 'login']);
|
||||
Route::get('/sso/redirect', [SsoController::class, 'redirect'])->name('sso.redirect');
|
||||
});
|
||||
|
||||
// SSO Callback (kein guest-Middleware, da Authentik zurückleitet)
|
||||
Route::get('/sso/callback', [SsoController::class, 'callback'])->name('sso.callback');
|
||||
|
||||
// Logout (nur für eingeloggte Benutzer)
|
||||
Route::post('/logout', [LoginController::class, 'logout'])->name('logout')->middleware('auth');
|
||||
|
||||
@@ -42,6 +50,10 @@ Route::middleware(['auth'])->group(function () {
|
||||
Route::delete('/users/{user}', [AdminController::class, 'destroyUser'])->name('users.destroy');
|
||||
Route::get('/statistics', [AdminController::class, 'statistics'])->name('statistics');
|
||||
Route::get('/users/{user}/collection', [UserNailPolishController::class, 'showUserCollection'])->name('users.collection');
|
||||
Route::get('/sso', [SsoSettingController::class, 'show'])->name('sso.show');
|
||||
Route::put('/sso', [SsoSettingController::class, 'update'])->name('sso.update');
|
||||
Route::get('/ai', [AiSettingController::class, 'show'])->name('ai.show');
|
||||
Route::put('/ai', [AiSettingController::class, 'update'])->name('ai.update');
|
||||
});
|
||||
|
||||
// Nagellack-Verwaltung (nur für Admin)
|
||||
@@ -53,6 +65,11 @@ Route::middleware(['auth'])->group(function () {
|
||||
// Hersteller-Verwaltung (für alle eingeloggten User)
|
||||
Route::resource('manufacturers', ManufacturerController::class);
|
||||
Route::get('/manufacturers-search', [ManufacturerController::class, 'search'])->name('manufacturers.search');
|
||||
|
||||
// KI Foto-Import (für alle eingeloggten User)
|
||||
Route::resource('nail-polish-imports', NailPolishImportController::class)
|
||||
->only(['index', 'create', 'store', 'show']);
|
||||
Route::post('/nail-polishes/{nailPolish}/rescan', [NailPolishImportController::class, 'rescan'])->name('nail-polishes.rescan');
|
||||
});
|
||||
|
||||
// Fallback
|
||||
|
||||
Reference in New Issue
Block a user