You've already forked Atomcms-edit
72 lines
2.1 KiB
PHP
Executable File
72 lines
2.1 KiB
PHP
Executable File
<?php
|
|
|
|
namespace App\Http\Controllers\Badge;
|
|
|
|
use App\Http\Controllers\Controller;
|
|
use Illuminate\Http\RedirectResponse;
|
|
use Illuminate\Http\Request;
|
|
use Illuminate\Support\Facades\Auth;
|
|
use Illuminate\View\View;
|
|
|
|
class BadgeController extends Controller
|
|
{
|
|
public function show(): View
|
|
{
|
|
$cost = (int) setting('badge_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): RedirectResponse
|
|
{
|
|
$user = Auth::user();
|
|
|
|
if (! $user) {
|
|
return redirect()->route('login')->with('error', 'You must be logged in to purchase badges.');
|
|
}
|
|
|
|
$cost = (int) setting('badge_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!');
|
|
}
|
|
}
|