You've already forked Atomcms-edit
Initial commit
This commit is contained in:
+69
@@ -0,0 +1,69 @@
|
||||
<?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!');
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user