Files
Atomcms-edit/app/Http/Controllers/Badge/BadgeController.php
T
2026-05-09 17:32:17 +02:00

70 lines
2.0 KiB
PHP
Executable File

<?php
namespace App\Http\Controllers\Badge;
use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;
class BadgeController extends Controller
{
public function show()
{
$cost = 150;
$currencyType = 'credits';
$folderError = false;
$errorMessage = '';
$badgesPath = setting('badge_path_filesystem', storage_path('badges'));
if ($badgesPath) {
$baseDir = base_path();
$badgeDir = dirname((string) $badgesPath);
$realBaseDir = $baseDir;
$realBadgeDir = $badgeDir;
try {
$realBaseDir = @realpath($baseDir) ?: $baseDir;
$realBadgeDir = @realpath($badgeDir) ?: $badgeDir;
} catch (\Exception) {
// Ignore realpath errors
}
if ($realBadgeDir && ! str_starts_with($realBadgeDir, $realBaseDir)) {
$badgesPath = storage_path('badges');
}
} else {
$badgesPath = storage_path('badges');
}
if (! file_exists($badgesPath)) {
@mkdir($badgesPath, 0755, true);
}
if (! is_writable($badgesPath)) {
$folderError = true;
$errorMessage = 'Badges folder is not writable.';
}
return view('draw-badge', ['cost' => $cost, 'currencyType' => $currencyType, 'folderError' => $folderError, 'errorMessage' => $errorMessage]);
}
public function buy(Request $request)
{
$user = Auth::user();
if (! $user) {
return redirect()->route('login')->with('error', 'You must be logged in to purchase badges.');
}
$cost = 150;
if (property_exists($user, 'credits') && $user->credits !== null && $user->credits < $cost) {
return redirect()->back()->with('error', 'You don\'t have enough credits to purchase a badge.');
}
return redirect()->back()->with('success', 'Badge purchase feature coming soon!');
}
}