Initial commit

This commit is contained in:
root
2026-05-09 17:28:23 +02:00
commit 9d73f82529
5575 changed files with 281989 additions and 0 deletions
+186
View File
@@ -0,0 +1,186 @@
<?php
namespace App\Http\Controllers\Api;
use App\Actions\Fortify\CreateNewUser;
use App\Http\Controllers\Controller;
use App\Models\Articles\WebsiteArticle;
use App\Models\Miscellaneous\CameraWeb;
use App\Models\User;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Hash;
use Illuminate\Validation\ValidationException;
class AuthController extends Controller
{
public function login(Request $request): JsonResponse
{
$request->validate([
'username' => ['required', 'string'],
'password' => ['required'],
]);
$username = $request->input('username');
$user = User::where('username', $username)
->orWhere('mail', $username)
->first();
if (! $user || ! Hash::check($request->input('password'), $user->password)) {
throw ValidationException::withMessages([
'email' => ['The provided credentials are incorrect.'],
]);
}
if ($user->is_banned) {
throw ValidationException::withMessages([
'email' => ['Your account has been banned.'],
]);
}
$user->update(['last_login' => time()]);
$token = $user->createToken('auth-token')->plainTextToken;
return response()->json([
'user' => [
'id' => (string) $user->id,
'email' => $user->mail,
'username' => $user->username,
'look' => $user->look,
],
'token' => $token,
]);
}
public function register(Request $request): JsonResponse
{
$createNewUser = new CreateNewUser;
try {
$validated = $request->validate([
'username' => ['required', 'string', 'max:50'],
'password' => ['required', 'string', 'min:6'],
'mail' => ['required', 'email', 'max:255'],
'look' => ['nullable', 'string'],
'motto' => ['nullable', 'string', 'max:100'],
]);
$user = $createNewUser->create($validated);
$token = $user->createToken('auth-token')->plainTextToken;
return response()->json([
'user' => [
'id' => (string) $user->id,
'email' => $user->mail,
'username' => $user->username,
'look' => $user->look,
],
'token' => $token,
], 201);
} catch (ValidationException $e) {
return response()->json([
'errors' => $e->errors(),
], 422);
}
}
public function user(Request $request): JsonResponse
{
$user = $request->user();
return response()->json([
'id' => (string) $user->id,
'email' => $user->mail,
'username' => $user->username,
'look' => $user->look,
'motto' => $user->motto ?? '',
'credits' => $user->credits ?? 0,
'pixels' => $user->pixels ?? 0,
'diamonds' => $user->diamonds ?? 0,
]);
}
public function logout(Request $request): JsonResponse
{
$request->user()->currentAccessToken()->delete();
return response()->json(['message' => 'Logged out successfully']);
}
public function home(): JsonResponse
{
$articles = WebsiteArticle::with(['user:id,username,look'])
->latest('id')
->take(4)
->get()
->map(fn ($article) => [
'id' => $article->id,
'title' => $article->title,
'slug' => $article->slug,
'image' => $article->image,
'excerpt' => $article->excerpt,
'user' => $article->user,
'created_at' => $article->created_at,
]);
$photos = CameraWeb::query()
->latest('id')
->take(4)
->where('visible', true)
->with('user:id,username,look')
->get()
->map(fn ($photo) => [
'id' => $photo->id,
'image' => $photo->image,
'user' => $photo->user,
]);
return response()->json([
'articles' => $articles,
'photos' => $photos,
]);
}
public function updateUser(Request $request): JsonResponse
{
$user = $request->user();
$validated = $request->validate([
'motto' => ['nullable', 'string', 'max:100'],
'look' => ['nullable', 'string'],
]);
$user->update($validated);
return response()->json([
'id' => (string) $user->id,
'email' => $user->mail,
'username' => $user->username,
'look' => $user->look,
'motto' => $user->motto,
'credits' => $user->credits,
'pixels' => $user->pixels,
'diamonds' => $user->diamonds,
]);
}
public function articleComment(Request $request, string $slug): JsonResponse
{
$article = WebsiteArticle::where('slug', $slug)->firstOrFail();
$validated = $request->validate([
'comment' => ['required', 'string', 'max:1000'],
]);
$comment = $article->comments()->create([
'user_id' => $request->user()->id,
'comment' => strip_tags((string) $validated['comment']),
]);
return response()->json([
'data' => $comment->load('user:id,username,look'),
], 201);
}
}
+317
View File
@@ -0,0 +1,317 @@
<?php
namespace App\Http\Controllers\Api;
use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Log;
class FurniEditorController extends Controller
{
private function checkAdmin(): void
{
if (! Auth::check() || Auth::user()->rank < (int) setting('min_staff_rank', 7)) {
abort(403, 'Forbidden');
}
}
public function search(Request $request)
{
$this->checkAdmin();
try {
$q = mb_substr(strip_tags((string) $request->input('q', '')), 0, 100);
$type = $request->input('type', '');
$page = max(1, (int) $request->input('page', 1));
$limit = min(50, max(1, (int) $request->input('limit', 20)));
$query = DB::table('items_base');
if ($q !== '' && $q !== '0') {
$query->where(function ($w) use ($q) {
$w->where('item_name', 'like', "%{$q}%")
->orWhere('public_name', 'like', "%{$q}%")
->orWhere('id', '=', $q);
});
}
if ($type) {
$query->where('type', $type);
}
$total = $query->count();
$items = $query
->orderBy('id')
->skip(($page - 1) * $limit)
->take($limit)
->get()
->map(fn ($r) => [
'id' => $r->id,
'spriteId' => $r->sprite_id,
'itemName' => $r->item_name,
'publicName' => $r->public_name,
'type' => $r->type,
'width' => $r->width,
'length' => $r->length,
'stackHeight' => $r->stack_height,
'allowStack' => (bool) $r->allow_stack,
'allowWalk' => (bool) $r->allow_walk,
'allowSit' => (bool) $r->allow_sit,
'allowLay' => (bool) $r->allow_lay,
'interactionType' => $r->interaction_type,
'interactionModesCount' => $r->interaction_modes_count,
]);
return response()->json([
'items' => $items,
'total' => $total,
'page' => $page,
]);
} catch (\Exception) {
Log::error('[FurniEditor] Search failed', ['error' => 'Actie mislukt']);
return response()->json(['error' => 'Zoeken mislukt'], 500);
}
}
public function detail(Request $request)
{
$this->checkAdmin();
try {
$id = (int) $request->input('id');
if ($id === 0) {
return response()->json(['error' => 'Missing id'], 400);
}
$item = DB::table('items_base')->where('id', $id)->first();
if (! $item) {
return response()->json(['error' => 'Item not found'], 404);
}
$catalog = DB::table('catalog_items')
->whereRaw('FIND_IN_SET(?, item_ids)', [$id])
->get()
->map(fn ($r) => [
'id' => $r->id,
'catalogName' => $r->catalog_name,
'costCredits' => $r->cost_credits,
'costPoints' => $r->cost_points,
'pointsType' => $r->points_type,
'pageId' => $r->page_id,
'pageName' => $r->page_id ? DB::table('catalog_pages')->where('id', $r->page_id)->value('caption') ?? '' : '',
]);
return response()->json([
'item' => [
'id' => $item->id,
'spriteId' => $item->sprite_id,
'itemName' => $item->item_name,
'publicName' => $item->public_name,
'type' => $item->type,
'width' => $item->width,
'length' => $item->length,
'stackHeight' => $item->stack_height,
'allowStack' => (bool) $item->allow_stack,
'allowWalk' => (bool) $item->allow_walk,
'allowSit' => (bool) $item->allow_sit,
'allowLay' => (bool) $item->allow_lay,
'allowGift' => (bool) $item->allow_gift,
'allowTrade' => (bool) $item->allow_trade,
'allowRecycle' => (bool) $item->allow_recycle,
'allowMarketplaceSell' => (bool) $item->allow_marketplace_sell,
'allowInventoryStack' => (bool) $item->allow_inventory_stack,
'interactionType' => $item->interaction_type,
'interactionModesCount' => $item->interaction_modes_count,
'vendingIds' => $item->vending_ids,
'multiheight' => $item->multiheight,
'customparams' => $item->customparams,
'effectIdMale' => $item->effect_id_male,
'effectIdFemale' => $item->effect_id_female,
'clothingOnWalk' => $item->clothing_on_walk,
'description' => '',
'usageCount' => 0,
],
'catalogItems' => $catalog,
'furniDataEntry' => null,
]);
} catch (\Exception) {
return response()->json(['error' => 'Kan item niet laden'], 500);
}
}
public function update(Request $request)
{
$this->checkAdmin();
try {
$id = (int) $request->input('id');
if ($id === 0) {
return response()->json(['error' => 'Missing id'], 400);
}
$data = $request->json()->all();
$update = [];
$map = [
'itemName' => ['item_name', 'string', 100],
'publicName' => ['public_name', 'string', 100],
'spriteId' => ['sprite_id', 'integer', 0],
'width' => ['width', 'integer', 0],
'length' => ['length', 'integer', 0],
'stackHeight' => ['stack_height', 'integer', 0],
'allowStack' => ['allow_stack', 'boolean', 0],
'allowWalk' => ['allow_walk', 'boolean', 0],
'allowSit' => ['allow_sit', 'boolean', 0],
'allowLay' => ['allow_lay', 'boolean', 0],
'allowGift' => ['allow_gift', 'boolean', 0],
'allowTrade' => ['allow_trade', 'boolean', 0],
'allowRecycle' => ['allow_recycle', 'boolean', 0],
'allowMarketplaceSell' => ['allow_marketplace_sell', 'boolean', 0],
'allowInventoryStack' => ['allow_inventory_stack', 'boolean', 0],
'interactionType' => ['interaction_type', 'string', 50],
'interactionModesCount' => ['interaction_modes_count', 'integer', 0],
'vendingIds' => ['vending_ids', 'string', 255],
'multiheight' => ['multiheight', 'string', 255],
'customparams' => ['customparams', 'string', 255],
'effectIdMale' => ['effect_id_male', 'integer', 0],
'effectIdFemale' => ['effect_id_female', 'integer', 0],
'clothingOnWalk' => ['clothing_on_walk', 'string', 255],
];
foreach ($map as $key => [$col, $type, $maxLen]) {
if (! array_key_exists($key, $data)) {
continue;
}
$val = $data[$key];
if ($type === 'string') {
$val = mb_substr(strip_tags((string) $val), 0, $maxLen);
} elseif ($type === 'integer') {
$val = (int) $val;
} elseif ($type === 'boolean') {
$val = (bool) $val;
}
$update[$col] = $val;
}
if ($update === []) {
return response()->json(['error' => 'No fields to update'], 400);
}
DB::table('items_base')->where('id', $id)->update($update);
Log::info('[Audit] FurniEditor update', [
'user_id' => Auth::id(),
'item_id' => $id,
'fields' => array_keys($update),
]);
return response()->json(['success' => true]);
} catch (\Exception) {
return response()->json(['error' => 'Actie mislukt'], 500);
}
}
public function create(Request $request)
{
$this->checkAdmin();
try {
$data = $request->json()->all();
$id = DB::table('items_base')->insertGetId([
'sprite_id' => $data['spriteId'] ?? 0,
'item_name' => $data['itemName'] ?? '',
'public_name' => $data['publicName'] ?? '',
'type' => $data['type'] ?? 's',
'width' => $data['width'] ?? 1,
'length' => $data['length'] ?? 1,
'stack_height' => $data['stackHeight'] ?? 0,
'allow_stack' => $data['allowStack'] ?? false,
'allow_walk' => $data['allowWalk'] ?? false,
'allow_sit' => $data['allowSit'] ?? false,
'allow_lay' => $data['allowLay'] ?? false,
'allow_gift' => $data['allowGift'] ?? true,
'allow_trade' => $data['allowTrade'] ?? true,
'allow_recycle' => $data['allowRecycle'] ?? false,
'allow_marketplace_sell' => $data['allowMarketplaceSell'] ?? false,
'allow_inventory_stack' => $data['allowInventoryStack'] ?? true,
'interaction_type' => $data['interactionType'] ?? 'default',
'interaction_modes_count' => $data['interactionModesCount'] ?? 1,
]);
Log::info('[Audit] FurniEditor create', [
'user_id' => Auth::id(),
'new_id' => $id,
]);
return response()->json(['id' => $id]);
} catch (\Exception) {
return response()->json(['error' => 'Actie mislukt'], 500);
}
}
public function delete(Request $request)
{
$this->checkAdmin();
try {
$id = (int) $request->input('id');
if ($id === 0) {
return response()->json(['error' => 'Missing id'], 400);
}
DB::table('items_base')->where('id', $id)->delete();
Log::warning('[Audit] FurniEditor delete', [
'user_id' => Auth::id(),
'deleted_id' => $id,
]);
return response()->json(['success' => true]);
} catch (\Exception) {
return response()->json(['error' => 'Actie mislukt'], 500);
}
}
public function interactions(Request $request)
{
$this->checkAdmin();
try {
$rows = DB::table('items_base')
->select('interaction_type')
->groupBy('interaction_type')
->orderBy('interaction_type')
->pluck('interaction_type');
return response()->json(['interactions' => $rows]);
} catch (\Exception) {
return response()->json(['error' => 'Actie mislukt'], 500);
}
}
public function bySprite(Request $request)
{
$this->checkAdmin();
try {
$spriteId = (int) $request->input('spriteId');
if ($spriteId === 0) {
return response()->json(['error' => 'Missing spriteId'], 400);
}
$item = DB::table('items_base')->where('sprite_id', $spriteId)->first();
if (! $item) {
return response()->json(['error' => 'Item not found'], 404);
}
return response()->json(['id' => $item->id]);
} catch (\Exception) {
return response()->json(['error' => 'Actie mislukt'], 500);
}
}
}
+342
View File
@@ -0,0 +1,342 @@
<?php
namespace App\Http\Controllers\Api;
use App\Http\Controllers\Controller;
use App\Models\Articles\WebsiteArticle;
use App\Models\Game\Furniture\CatalogItem;
use App\Models\Game\Furniture\CatalogPage;
use App\Models\Game\Guild\Guild;
use App\Models\Help\WebsiteHelpCenterTicket;
use App\Models\Miscellaneous\CameraWeb;
use App\Models\Miscellaneous\WebsiteSetting;
use App\Models\Shop\WebsiteShopArticle;
use App\Models\User;
use App\Services\Community\StaffService;
use App\Services\User\UserApiService;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Cache;
class HotelApiController extends Controller
{
public function __construct(
private readonly UserApiService $userApiService,
private readonly StaffService $staffService,
) {}
public function fetchUser(string $username): JsonResponse
{
$user = $this->userApiService->fetchUser($username, ['username', 'motto', 'look']);
return response()->json([
'data' => $user,
]);
}
public function onlineUsers(): JsonResponse
{
$users = $this->userApiService->onlineUsers(['username', 'motto', 'look'], true);
return response()->json([
'data' => $users,
]);
}
public function onlineUserCount(): JsonResponse
{
$count = $this->userApiService->onlineUserCount();
return response()->json([
'data' => [
'onlineCount' => $count,
],
]);
}
public function articles(): JsonResponse
{
$articles = WebsiteArticle::with(['user:id,username,look'])
->latest('id')
->paginate(12);
return response()->json([
'data' => $articles->items(),
'meta' => [
'current_page' => $articles->currentPage(),
'last_page' => $articles->lastPage(),
'per_page' => $articles->perPage(),
'total' => $articles->total(),
],
]);
}
public function article(string $slug): JsonResponse
{
$article = WebsiteArticle::with(['user:id,username,look', 'comments.user:id,username,look'])
->where('slug', $slug)
->firstOrFail();
return response()->json([
'data' => $article,
]);
}
public function photos(): JsonResponse
{
$photos = CameraWeb::query()
->where('visible', true)
->latest('id')
->paginate(12);
return response()->json([
'data' => $photos->items(),
'meta' => [
'current_page' => $photos->currentPage(),
'last_page' => $photos->lastPage(),
'per_page' => $photos->perPage(),
'total' => $photos->total(),
],
]);
}
public function staff(): JsonResponse
{
$employees = $this->staffService->fetchStaffPositions();
return response()->json([
'data' => $employees,
]);
}
public function shopPackages(Request $request): JsonResponse
{
$packages = WebsiteShopArticle::latest('id')->paginate(12);
$mapped = $packages->items()->map(fn ($pkg) => [
'id' => $pkg->id,
'title' => $pkg->name,
'description' => $pkg->description,
'price' => $pkg->price(),
'credits' => null,
'pixels' => null,
'diamonds' => null,
'image' => null,
'currency' => 'credits',
]);
return response()->json([
'data' => $mapped,
'meta' => [
'current_page' => $packages->currentPage(),
'last_page' => $packages->lastPage(),
'per_page' => $packages->perPage(),
'total' => $packages->total(),
],
]);
}
public function shopCategories(): JsonResponse
{
return response()->json([
'data' => ['furniture', 'badges', 'ranks'],
]);
}
public function teams(): JsonResponse
{
$teams = Guild::with('members')
->latest('id')
->paginate(12);
return response()->json([
'data' => $teams->items(),
'meta' => [
'current_page' => $teams->currentPage(),
'last_page' => $teams->lastPage(),
'per_page' => $teams->perPage(),
'total' => $teams->total(),
],
]);
}
public function leaderboard(Request $request): JsonResponse
{
$type = $request->query('type', 'credits');
$limit = (int) $request->query('limit', 100);
$validTypes = ['credits', 'pixels'];
if (! in_array($type, $validTypes)) {
$type = 'credits';
}
$users = User::orderByDesc($type)
->limit($limit)
->get(['id', 'username', 'look', 'motto', 'credits', 'pixels']);
return response()->json([
'data' => $users,
'type' => $type,
]);
}
public function rareValues(Request $request): JsonResponse
{
$categoryId = $request->query('category');
$query = CatalogItem::query();
if ($categoryId) {
$query->where('page_id', $categoryId);
}
$items = $query->with('itemBase')
->latest('id')
->paginate(24);
return response()->json([
'data' => $items->items(),
'meta' => [
'current_page' => $items->currentPage(),
'last_page' => $items->lastPage(),
'per_page' => $items->perPage(),
'total' => $items->total(),
],
]);
}
public function rareValuesCategories(): JsonResponse
{
$categories = CatalogPage::where('catalog_name', '!=', '')
->where('visible', 1)
->orderBy('order_number')
->get(['id', 'catalog_name', 'icon']);
return response()->json([
'data' => $categories,
]);
}
public function settings(): JsonResponse
{
$settings = Cache::remember('api_all_settings', 60, fn () => WebsiteSetting::all()->pluck('value', 'key'));
return response()->json([
'data' => $settings,
]);
}
public function userProfile(string $username): JsonResponse
{
$user = User::where('username', $username)
->firstOrFail();
return response()->json([
'id' => $user->id,
'username' => $user->username,
'look' => $user->look,
'motto' => $user->motto,
'account_created' => $user->account_created,
'online' => false,
]);
}
public function helpTickets(Request $request): JsonResponse
{
$tickets = WebsiteHelpCenterTicket::with('user:id,username,look')
->when($request->user(), fn ($q) => $q->where('user_id', $request->user()->id))
->latest()
->paginate(10);
return response()->json([
'data' => $tickets->items(),
'meta' => [
'current_page' => $tickets->currentPage(),
'last_page' => $tickets->lastPage(),
'total' => $tickets->total(),
],
]);
}
public function helpTicket(string $id): JsonResponse
{
$ticket = WebsiteHelpCenterTicket::with(['user:id,username,look', 'replies.user:id,username,look'])
->where('id', $id)
->firstOrFail();
return response()->json(['data' => $ticket]);
}
public function helpTicketCreate(Request $request): JsonResponse
{
$validated = $request->validate([
'subject' => ['required', 'string', 'max:200'],
'category' => ['required', 'string', 'max:100'],
'message' => ['required', 'string', 'max:5000'],
]);
$ticket = WebsiteHelpCenterTicket::create([
'user_id' => $request->user()->id,
'subject' => $validated['subject'],
'category' => $validated['category'],
'status' => 'open',
]);
$ticket->replies()->create([
'user_id' => $request->user()->id,
'message' => $validated['message'],
]);
return response()->json(['data' => $ticket], 201);
}
public function helpTicketReply(Request $request, string $id): JsonResponse
{
$validated = $request->validate(['message' => 'required', 'string', 'max:5000']);
$ticket = WebsiteHelpCenterTicket::where('id', $id)
->where('user_id', $request->user()->id)
->firstOrFail();
$reply = $ticket->replies()->create([
'user_id' => $request->user()->id,
'message' => $validated['message'],
]);
return response()->json(['data' => $reply->load('user:id,username,look')], 201);
}
public function uploadPhoto(Request $request): JsonResponse
{
$validated = $request->validate([
'image' => ['required', 'image', 'max:5120'],
]);
$path = $validated['image']->store('photos', 'public');
$photo = CameraWeb::create([
'user_id' => $request->user()->id,
'image' => '/storage/' . $path,
'visible' => true,
]);
return response()->json(['data' => $photo], 201);
}
public function purchasePackage(Request $request, int $packageId): JsonResponse
{
$package = WebsiteShopArticle::findOrFail($packageId);
$user = $request->user();
$cost = $package->costs;
if ($user->credits < $cost) {
return response()->json(['error' => 'Not enough credits'], 400);
}
$user->decrement('credits', $cost);
return response()->json(['success' => true, 'message' => 'Purchase successful']);
}
}