You've already forked Epicnabbo-Catalogus-Updated-Daily
🆙 More fixes 🆙
This commit is contained in:
@@ -10,14 +10,20 @@ use App\Services\User\UserApiService;
|
||||
|
||||
class HotelApiController extends Controller
|
||||
{
|
||||
public function __construct(private readonly UserApiService $userApiService): void {}
|
||||
public function __construct(private readonly UserApiService $userApiService) {}
|
||||
|
||||
/**
|
||||
* @param array<int, string> $columns
|
||||
*/
|
||||
public function fetchUser(string $username, array $columns = ['username', 'motto', 'look']): UserResource
|
||||
{
|
||||
return new UserResource($this->userApiService->fetchUser($username, $columns));
|
||||
}
|
||||
|
||||
public function onlineUsers($columns = ['username', 'motto', 'look'], bool $randomOrder = true): OnlineUsersResource
|
||||
/**
|
||||
* @param array<int, string> $columns
|
||||
*/
|
||||
public function onlineUsers(array $columns = ['username', 'motto', 'look'], bool $randomOrder = true): OnlineUsersResource
|
||||
{
|
||||
return new OnlineUsersResource($this->userApiService->onlineUsers($columns, $randomOrder));
|
||||
}
|
||||
|
||||
@@ -39,7 +39,10 @@ class ArticleController extends Controller
|
||||
|
||||
public function toggleReaction(WebsiteArticle $article, Request $request): JsonResponse
|
||||
{
|
||||
$response = $this->reactionService->toggleReaction($article, Auth::user(), $request);
|
||||
/** @var \App\Models\User $user */
|
||||
$user = $request->user();
|
||||
|
||||
$response = $this->reactionService->toggleReaction($article, $user, $request);
|
||||
|
||||
return response()->json($response);
|
||||
}
|
||||
|
||||
@@ -11,11 +11,11 @@ use Illuminate\Http\RedirectResponse;
|
||||
|
||||
class WebsiteArticleCommentsController extends Controller
|
||||
{
|
||||
public function __construct(public readonly CommentService $commentService): void {}
|
||||
public function __construct(public readonly CommentService $commentService) {}
|
||||
|
||||
public function store(WebsiteArticle $article, ArticleCommentFormRequest $request): RedirectResponse
|
||||
{
|
||||
$this->commentService->store($request->get('comment'), $article);
|
||||
$this->commentService->store($request->string('comment')->toString(), $article);
|
||||
|
||||
return back()->with('success', __('You comment has been posted!'));
|
||||
}
|
||||
|
||||
@@ -20,7 +20,7 @@ class BadgeController extends Controller
|
||||
|
||||
public function show(SettingsService $settingsService): \Illuminate\Contracts\View\View
|
||||
{
|
||||
$cost = (int) $settingsService->getOrDefault('drawbadge_currency_value', 150);
|
||||
$cost = (int) $settingsService->getOrDefault('drawbadge_currency_value', '150');
|
||||
$currencyType = $settingsService->getOrDefault('drawbadge_currency_type', 'credits');
|
||||
$badgesPath = $settingsService->getOrDefault('badge_path_filesystem');
|
||||
|
||||
@@ -43,8 +43,14 @@ class BadgeController extends Controller
|
||||
|
||||
public function buy(Request $request, SendCurrency $sendCurrency, SettingsService $settingsService): \Illuminate\Http\JsonResponse
|
||||
{
|
||||
$user = Auth::user();
|
||||
$cost = (int) $settingsService->getOrDefault('drawbadge_currency_value', 150);
|
||||
/** @var \App\Models\User|null $user */
|
||||
$user = $request->user();
|
||||
|
||||
if (! $user) {
|
||||
return response()->json(['success' => false, 'message' => 'Unauthorized.'], 401);
|
||||
}
|
||||
|
||||
$cost = (int) $settingsService->getOrDefault('drawbadge_currency_value', '150');
|
||||
$currencyType = $settingsService->getOrDefault('drawbadge_currency_type', 'credits');
|
||||
|
||||
$currentAmount = match ($currencyType) {
|
||||
@@ -65,13 +71,13 @@ class BadgeController extends Controller
|
||||
return response()->json(['success' => false, 'message' => 'Failed to deduct ' . $currencyType . '.'], 500);
|
||||
}
|
||||
|
||||
$badgeData = $request->input('badge_data');
|
||||
if (! $badgeData) {
|
||||
$badgeData = $request->string('badge_data')->toString();
|
||||
if ($badgeData === '') {
|
||||
return response()->json(['success' => false, 'message' => 'No badge data provided.'], 400);
|
||||
}
|
||||
|
||||
$badgeData = preg_replace('#^data:image/\w+;base64,#i', '', (string) $badgeData);
|
||||
$decoded = base64_decode((string) $badgeData, true);
|
||||
$badgeData = (string) preg_replace('#^data:image/\w+;base64,#i', '', $badgeData);
|
||||
$decoded = base64_decode($badgeData, true);
|
||||
|
||||
if ($decoded === false) {
|
||||
return response()->json(['success' => false, 'message' => 'Invalid base64 data.'], 400);
|
||||
|
||||
@@ -10,12 +10,15 @@ class FlashController extends Controller
|
||||
{
|
||||
public function __invoke(): View
|
||||
{
|
||||
Auth::user()->update([
|
||||
/** @var \App\Models\User $user */
|
||||
$user = Auth::user();
|
||||
|
||||
$user->update([
|
||||
'ip_current' => request()->ip(),
|
||||
]);
|
||||
|
||||
return view('client.flash', [
|
||||
'sso' => Auth::user()->ssoTicket(),
|
||||
'sso' => $user->ssoTicket(),
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,12 +10,15 @@ class NitroController extends Controller
|
||||
{
|
||||
public function __invoke(): View
|
||||
{
|
||||
Auth::user()->update([
|
||||
/** @var \App\Models\User $user */
|
||||
$user = Auth::user();
|
||||
|
||||
$user->update([
|
||||
'ip_current' => request()->ip(),
|
||||
]);
|
||||
|
||||
return view('client.nitro', [
|
||||
'sso' => Auth::user()->ssoTicket(),
|
||||
'sso' => $user->ssoTicket(),
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -11,9 +11,10 @@ use Illuminate\View\View;
|
||||
|
||||
class LeaderboardController extends Controller
|
||||
{
|
||||
/** @var array<int, int> */
|
||||
protected array $staffIds = [];
|
||||
|
||||
public function __construct(private readonly StaffService $staffService): void
|
||||
public function __construct(private readonly StaffService $staffService)
|
||||
{
|
||||
$this->staffIds = $this->staffService->fetchEmployeeIds();
|
||||
}
|
||||
@@ -44,6 +45,9 @@ class LeaderboardController extends Controller
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return \Illuminate\Database\Eloquent\Collection<int, UserSetting>
|
||||
*/
|
||||
private function retrieveSettings(string $column): \Illuminate\Database\Eloquent\Collection
|
||||
{
|
||||
return UserSetting::select('user_id', $column)
|
||||
|
||||
@@ -8,7 +8,7 @@ use Illuminate\View\View;
|
||||
|
||||
class PhotosController extends Controller
|
||||
{
|
||||
public function __construct(private readonly CameraService $cameraService): void {}
|
||||
public function __construct(private readonly CameraService $cameraService) {}
|
||||
|
||||
public function __invoke(): View
|
||||
{
|
||||
|
||||
@@ -11,7 +11,7 @@ use Illuminate\Http\RedirectResponse;
|
||||
|
||||
class StaffApplicationsController extends Controller
|
||||
{
|
||||
public function __construct(private readonly StaffApplicationService $staffApplicationService): void {}
|
||||
public function __construct(private readonly StaffApplicationService $staffApplicationService) {}
|
||||
|
||||
public function index(): View
|
||||
{
|
||||
@@ -29,7 +29,16 @@ class StaffApplicationsController extends Controller
|
||||
|
||||
public function store(WebsiteOpenPosition $position, StaffApplicationFormRequest $request): RedirectResponse
|
||||
{
|
||||
if ($this->staffApplicationService->hasUserAppliedForPosition($request->user(), $position->permission->id)) {
|
||||
/** @var \App\Models\User $user */
|
||||
$user = $request->user();
|
||||
|
||||
if ($position->permission === null) {
|
||||
return back()->withErrors([
|
||||
'message' => __('Invalid position configuration.'),
|
||||
]);
|
||||
}
|
||||
|
||||
if ($this->staffApplicationService->hasUserAppliedForPosition($user, $position->permission->id)) {
|
||||
return back()->withErrors([
|
||||
'message' => __('You have already applied for this position.'),
|
||||
]);
|
||||
@@ -41,7 +50,7 @@ class StaffApplicationsController extends Controller
|
||||
]);
|
||||
}
|
||||
|
||||
$this->staffApplicationService->storeApplication($request->user(), $position->permission->id, $request->input('content'));
|
||||
$this->staffApplicationService->storeApplication($user, $position->permission->id, $request->string('content')->toString());
|
||||
|
||||
return to_route('staff-applications.index')->with('success', __('Your application has been submitted!'));
|
||||
}
|
||||
|
||||
@@ -8,7 +8,7 @@ use Illuminate\View\View;
|
||||
|
||||
class StaffController extends Controller
|
||||
{
|
||||
public function __construct(private readonly StaffService $staffService): void {}
|
||||
public function __construct(private readonly StaffService $staffService) {}
|
||||
|
||||
public function __invoke(): View
|
||||
{
|
||||
|
||||
@@ -8,7 +8,7 @@ use Illuminate\View\View;
|
||||
|
||||
class WebsiteTeamsController extends Controller
|
||||
{
|
||||
public function __construct(private readonly TeamService $teamService): void {}
|
||||
public function __construct(private readonly TeamService $teamService) {}
|
||||
|
||||
public function __invoke(): View
|
||||
{
|
||||
|
||||
@@ -14,7 +14,7 @@ use Illuminate\View\View;
|
||||
|
||||
class WebsiteRareValuesController extends Controller
|
||||
{
|
||||
public function __construct(private readonly RareValueCategoriesService $valueCategoriesService): void {}
|
||||
public function __construct(private readonly RareValueCategoriesService $valueCategoriesService) {}
|
||||
|
||||
public function index(): View
|
||||
{
|
||||
@@ -42,7 +42,7 @@ class WebsiteRareValuesController extends Controller
|
||||
|
||||
public function search(RareSearchFormRequest $request): View|RedirectResponse
|
||||
{
|
||||
$searchTerm = $request->input('search');
|
||||
$searchTerm = $request->string('search')->toString();
|
||||
|
||||
$categories = $this->valueCategoriesService->searchCategories($searchTerm);
|
||||
|
||||
@@ -64,13 +64,18 @@ class WebsiteRareValuesController extends Controller
|
||||
->where('item_id', $value->item_id)
|
||||
->get();
|
||||
|
||||
$itemsPerUser = $items->groupBy('user_id')->map(fn ($group) => [
|
||||
'user' => $group->first()->user,
|
||||
'item_count' => $group->count(),
|
||||
]);
|
||||
$itemsPerUser = $items->groupBy('user_id')->map(function ($group) {
|
||||
/** @var \App\Models\Game\Furniture\Item $firstItem */
|
||||
$firstItem = $group->first();
|
||||
|
||||
return [
|
||||
'user' => $firstItem->user,
|
||||
'item_count' => $group->count(),
|
||||
];
|
||||
});
|
||||
|
||||
if ((bool) setting('enable_caching')) {
|
||||
Cache::remember('allItems_' . $value->id, setting('cache_timer'), fn () => $items);
|
||||
Cache::remember('allItems_' . $value->id, (int) setting('cache_timer'), fn () => $items);
|
||||
}
|
||||
|
||||
return view('value', [
|
||||
|
||||
@@ -35,7 +35,9 @@ class TicketController extends Controller
|
||||
|
||||
public function store(WebsiteTicketFormRequest $request): RedirectResponse
|
||||
{
|
||||
Auth::user()->tickets()->create($request->validated());
|
||||
/** @var \App\Models\User $user */
|
||||
$user = Auth::user();
|
||||
$user->tickets()->create($request->validated());
|
||||
|
||||
return back()->with('success', __('Ticket submitted!'));
|
||||
}
|
||||
|
||||
@@ -24,9 +24,12 @@ class TicketReplyController extends Controller
|
||||
]);
|
||||
}
|
||||
|
||||
/** @var \App\Models\User $user */
|
||||
$user = $request->user();
|
||||
|
||||
$data = $request->validated();
|
||||
$ticket->replies()->create([
|
||||
'user_id' => $request->user()->id,
|
||||
'user_id' => $user->id,
|
||||
'content' => $data['content'],
|
||||
]);
|
||||
|
||||
|
||||
@@ -26,7 +26,7 @@ class InstallationController extends Controller
|
||||
'installation_key' => ['required', 'string', 'max:255', new ValidateInstallationKeyRule],
|
||||
]);
|
||||
|
||||
WebsiteInstallation::first()->update([
|
||||
WebsiteInstallation::first()?->update([
|
||||
'step' => 1,
|
||||
'user_ip' => $request->ip(),
|
||||
]);
|
||||
@@ -38,7 +38,10 @@ class InstallationController extends Controller
|
||||
{
|
||||
$settings = $this->getSettingsForStep($currentStep);
|
||||
|
||||
return view('installation.step-' . $currentStep, [
|
||||
/** @var view-string $view */
|
||||
$view = 'installation.step-' . (string) $currentStep;
|
||||
|
||||
return view($view, [
|
||||
'settings' => $settings,
|
||||
]);
|
||||
}
|
||||
@@ -47,21 +50,27 @@ class InstallationController extends Controller
|
||||
{
|
||||
$this->updateSettings($request);
|
||||
|
||||
WebsiteInstallation::increment('step');
|
||||
WebsiteInstallation::query()->increment('step');
|
||||
|
||||
/** @var \App\Models\Miscellaneous\WebsiteInstallation|null $installation */
|
||||
$installation = WebsiteInstallation::first();
|
||||
|
||||
return to_route('installation.show-step', WebsiteInstallation::first()->step);
|
||||
return to_route('installation.show-step', $installation->step ?? 1);
|
||||
}
|
||||
|
||||
public function previousStep(): RedirectResponse
|
||||
{
|
||||
WebsiteInstallation::decrement('step');
|
||||
WebsiteInstallation::query()->decrement('step');
|
||||
|
||||
return to_route('installation.show-step', WebsiteInstallation::first()->step);
|
||||
/** @var \App\Models\Miscellaneous\WebsiteInstallation|null $installation */
|
||||
$installation = WebsiteInstallation::first();
|
||||
|
||||
return to_route('installation.show-step', $installation->step ?? 1);
|
||||
}
|
||||
|
||||
public function restartInstallation(): RedirectResponse
|
||||
{
|
||||
WebsiteInstallation::first()->update([
|
||||
WebsiteInstallation::first()?->update([
|
||||
'step' => 0,
|
||||
'installation_key' => Str::uuid(),
|
||||
'user_ip' => null,
|
||||
@@ -76,7 +85,7 @@ class InstallationController extends Controller
|
||||
|
||||
public function completeInstallation(): RedirectResponse
|
||||
{
|
||||
WebsiteInstallation::latest()->first()->update([
|
||||
WebsiteInstallation::latest()->first()?->update([
|
||||
'completed' => true,
|
||||
]);
|
||||
|
||||
@@ -100,10 +109,20 @@ class InstallationController extends Controller
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return \Illuminate\Database\Eloquent\Collection<int, \App\Models\Miscellaneous\WebsiteSetting>
|
||||
*/
|
||||
private function getSettingsForStep(int $step): \Illuminate\Database\Eloquent\Collection
|
||||
{
|
||||
$settingsData = array_chunk(WebsiteSetting::all()->pluck('key')->toArray(), ceil(WebsiteSetting::count() / 4));
|
||||
$count = WebsiteSetting::count();
|
||||
/** @var int<1, max> $chunkSize */
|
||||
$chunkSize = $count > 0 ? (int) ceil($count / 4) : 1;
|
||||
|
||||
/** @var array<int, string> $keys */
|
||||
$keys = WebsiteSetting::query()->pluck('key')->toArray();
|
||||
$settingsData = array_chunk($keys, $chunkSize);
|
||||
|
||||
/** @var array<int, string> $settings */
|
||||
$settings = match ($step) {
|
||||
1 => $settingsData[0] ?? [],
|
||||
2 => $settingsData[1] ?? [],
|
||||
|
||||
@@ -33,9 +33,11 @@ class LogoGeneratorController extends Controller
|
||||
|
||||
$setting = WebsiteSetting::where('key', 'cms_logo')->first();
|
||||
|
||||
$setting->update([
|
||||
'value' => sprintf('%s/%s', $path, $filename),
|
||||
]);
|
||||
if ($setting) {
|
||||
$setting->update([
|
||||
'value' => sprintf('%s/%s', $path, $filename),
|
||||
]);
|
||||
}
|
||||
|
||||
return response()->json(['success' => true, 'message' => 'Logo updated!']);
|
||||
}
|
||||
|
||||
@@ -16,10 +16,12 @@ class PaypalController extends Controller
|
||||
|
||||
private const string STATUS_COMPLETED = 'COMPLETED';
|
||||
|
||||
public function __construct(private PayPalClient $provider): void
|
||||
public function __construct(private PayPalClient $provider)
|
||||
{
|
||||
$this->provider = new PayPalClient;
|
||||
$this->provider->setApiCredentials(config('habbo.paypal'));
|
||||
/** @var array<mixed> $config */
|
||||
$config = config('habbo.paypal');
|
||||
$this->provider->setApiCredentials($config);
|
||||
$this->provider->getAccessToken();
|
||||
}
|
||||
|
||||
@@ -46,6 +48,7 @@ class PaypalController extends Controller
|
||||
],
|
||||
];
|
||||
|
||||
/** @var array<string, mixed> $response */
|
||||
$response = $this->provider->createOrder($orderData);
|
||||
|
||||
if (isset($response['id']) === false) {
|
||||
@@ -56,14 +59,19 @@ class PaypalController extends Controller
|
||||
);
|
||||
}
|
||||
|
||||
foreach ($response['links'] as $links) {
|
||||
if ($links['rel'] === 'approve') {
|
||||
$request->user()->transactions()->create([
|
||||
/** @var array<int, array<string, string>> $links */
|
||||
$links = $response['links'];
|
||||
|
||||
foreach ($links as $link) {
|
||||
if ($link['rel'] === 'approve') {
|
||||
/** @var \App\Models\User $user */
|
||||
$user = $request->user();
|
||||
$user->transactions()->create([
|
||||
'transaction_id' => $response['id'],
|
||||
'amount' => 0,
|
||||
]);
|
||||
|
||||
return redirect()->away($links['href']);
|
||||
return redirect()->away($link['href']);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -78,6 +86,7 @@ class PaypalController extends Controller
|
||||
'token' => ['required'],
|
||||
]);
|
||||
|
||||
/** @var \App\Models\User $user */
|
||||
$user = $request->user();
|
||||
|
||||
$transaction = $user->transactions()->where('transaction_id', $request['token'])->first();
|
||||
@@ -85,41 +94,71 @@ class PaypalController extends Controller
|
||||
return to_route('shop.index')->withErrors(['message' => __('Something went wrong, please try again later')]);
|
||||
}
|
||||
|
||||
$response = $this->provider->capturePaymentOrder($request['token']);
|
||||
$paymentDetails = $response['purchase_units'][0]['payments']['captures'][0];
|
||||
/** @var array<string, mixed> $response */
|
||||
$response = $this->provider->capturePaymentOrder($request->string('token')->toString());
|
||||
|
||||
if (isset($response['error'])) {
|
||||
/** @var array<string, mixed> $error */
|
||||
$error = $response['error'];
|
||||
/** @var array<int, array<string, string>> $details */
|
||||
$details = $error['details'] ?? [];
|
||||
$issue = $details[0]['issue'] ?? 'Unknown';
|
||||
$description = $details[0]['description'] ?? 'Unknown';
|
||||
|
||||
$transaction->update([
|
||||
'status' => $response['name'] ?? 'ERROR',
|
||||
'description' => sprintf('%s - %s', $issue, $description),
|
||||
'amount' => 0,
|
||||
]);
|
||||
|
||||
if (! isset($response['status'], $paymentDetails)) {
|
||||
Log::error('Invalid response from PayPal', ['response' => $response]);
|
||||
|
||||
return to_route('shop.index')->withErrors(['message' => __('Something went wrong, please try again later')]);
|
||||
return to_route('shop.index')->withErrors(['message' => __('Something went wrong, please check your paypal account to make sure nothing was deducted and try again')]);
|
||||
}
|
||||
|
||||
if (($response['status'] ?? null) === null) {
|
||||
$details = $response['error']['details'][0];
|
||||
$transaction->update([
|
||||
'status' => $response['name'],
|
||||
'description' => sprintf('%s - %s', $details['issue'], $details['description']),
|
||||
'amount' => 0,
|
||||
]);
|
||||
/** @var array<int, mixed> $purchaseUnits */
|
||||
$purchaseUnits = $response['purchase_units'] ?? [];
|
||||
/** @var array<string, mixed> $unit */
|
||||
$unit = $purchaseUnits[0] ?? [];
|
||||
/** @var array<string, mixed> $payments */
|
||||
$payments = $unit['payments'] ?? [];
|
||||
/** @var array<int, mixed> $captures */
|
||||
$captures = $payments['captures'] ?? [];
|
||||
|
||||
return to_route('shop.index')->withErrors(['message' => __('Something went wrong, please check your paypal account to make sure nothing was deducted and try again')]);
|
||||
if (! isset($captures[0])) {
|
||||
Log::error('Invalid response from PayPal', ['response' => $response]);
|
||||
return to_route('shop.index')->withErrors(['message' => __('Something went wrong, please try again later')]);
|
||||
}
|
||||
|
||||
/** @var array<string, mixed> $paymentDetails */
|
||||
$paymentDetails = $captures[0];
|
||||
|
||||
/** @var array<string, mixed> $amountDetails */
|
||||
$amountDetails = $paymentDetails['amount'] ?? [];
|
||||
|
||||
$paymentDetails = $response['purchase_units'][0]['payments']['captures'][0];
|
||||
if (! isset($response['status'])) {
|
||||
Log::error('Invalid response from PayPal', ['response' => $response]);
|
||||
|
||||
return to_route('shop.index')->withErrors(['message' => __('Something went wrong, please try again later')]);
|
||||
}
|
||||
|
||||
$status = $response['status'];
|
||||
|
||||
$transaction->update([
|
||||
'status' => $paymentDetails['status'],
|
||||
'amount' => $paymentDetails['amount']['value'],
|
||||
'currency' => $paymentDetails['amount']['currency_code'],
|
||||
'amount' => $amountDetails['value'] ?? 0,
|
||||
'currency' => $amountDetails['currency_code'] ?? 'USD',
|
||||
]);
|
||||
|
||||
if ($response['status'] !== self::STATUS_COMPLETED) {
|
||||
if ($status !== self::STATUS_COMPLETED) {
|
||||
return to_route('shop.index')->withErrors(
|
||||
['message' => $response['message'] ?? __('Something went wrong')],
|
||||
);
|
||||
}
|
||||
|
||||
$user->increment('website_balance', $paymentDetails['amount']['value']);
|
||||
$value = $amountDetails['value'] ?? 0;
|
||||
if (! is_numeric($value)) {
|
||||
$value = 0;
|
||||
}
|
||||
$user->increment('website_balance', (int) $value);
|
||||
|
||||
return to_route('shop.index')->with('success', __('Transaction successful'));
|
||||
}
|
||||
@@ -130,7 +169,10 @@ class PaypalController extends Controller
|
||||
'token' => ['required'],
|
||||
]);
|
||||
|
||||
$transaction = $request->user()->transactions()->where('transaction_id', $request['token'])->first();
|
||||
/** @var \App\Models\User $user */
|
||||
$user = $request->user();
|
||||
|
||||
$transaction = $user->transactions()->where('transaction_id', $request['token'])->first();
|
||||
if ($transaction !== null) {
|
||||
$transaction->update([
|
||||
'status' => self::STATUS_CANCELLED,
|
||||
|
||||
@@ -15,7 +15,7 @@ use Symfony\Component\HttpFoundation\Response;
|
||||
|
||||
class ShopController extends Controller
|
||||
{
|
||||
public function __construct(private readonly RconService $rconService): void {}
|
||||
public function __construct(private readonly RconService $rconService) {}
|
||||
|
||||
public function __invoke(?WebsiteShopCategory $category): \Illuminate\Contracts\View\View
|
||||
{
|
||||
@@ -56,7 +56,9 @@ class ShopController extends Controller
|
||||
|
||||
public function purchase(WebsiteShopArticle $package, Request $request, SendCurrency $sendCurrency): Response
|
||||
{
|
||||
$user = Auth::user();
|
||||
/** @var \App\Models\User $currentUser */
|
||||
$currentUser = Auth::user();
|
||||
$user = $currentUser;
|
||||
|
||||
if ($request->has('receiver')) {
|
||||
if (! $package->is_giftable) {
|
||||
@@ -72,13 +74,12 @@ class ShopController extends Controller
|
||||
['message' => __('Recipient not found')],
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if ($package->give_rank && $user->rank >= $package->give_rank) {
|
||||
$message = __('You are already this or a higher rank');
|
||||
|
||||
if ($user->username !== Auth::user()->username) {
|
||||
if ($user->username !== $currentUser->username) {
|
||||
$message = __('The recipient is already this or a higher rank');
|
||||
}
|
||||
|
||||
@@ -87,27 +88,27 @@ class ShopController extends Controller
|
||||
);
|
||||
}
|
||||
|
||||
if (! $this->rconService->isConnected && $user->online === '1') {
|
||||
if (! $this->rconService->isConnected && $user->online) {
|
||||
return to_route('shop.index')->withErrors(
|
||||
['message' => __('Please logout before purchasing a package')],
|
||||
);
|
||||
}
|
||||
|
||||
if (Auth::user()->website_balance < $package->price()) {
|
||||
if ($currentUser->website_balance < $package->price()) {
|
||||
return to_route('shop.index')->withErrors(
|
||||
['message' => __('You need to top-up your account with another $:amount to purchase this package', ['amount' => ($package->price() - Auth::user()->website_balance)])],
|
||||
['message' => __('You need to top-up your account with another $:amount to purchase this package', ['amount' => ($package->price() - $currentUser->website_balance)])],
|
||||
);
|
||||
}
|
||||
|
||||
Auth::user()?->decrement('website_balance', $package->price());
|
||||
$currentUser->decrement('website_balance', $package->price());
|
||||
|
||||
$sendCurrency->execute($user, 'credits', $package->credits);
|
||||
$sendCurrency->execute($user, 'duckets', $package->duckets);
|
||||
$sendCurrency->execute($user, 'diamonds', $package->diamonds);
|
||||
$sendCurrency->execute($user, 'credits', (int) $package->credits);
|
||||
$sendCurrency->execute($user, 'duckets', (int) $package->duckets);
|
||||
$sendCurrency->execute($user, 'diamonds', (int) $package->diamonds);
|
||||
|
||||
if ($package->give_rank) {
|
||||
if ($this->rconService->isConnected) {
|
||||
$this->rconService->setRank($user, $package->give_rank);
|
||||
$this->rconService->setRank($user, (int) $package->give_rank);
|
||||
$this->rconService->disconnectUser($user);
|
||||
} else {
|
||||
$user->update([
|
||||
@@ -121,22 +122,28 @@ class ShopController extends Controller
|
||||
}
|
||||
|
||||
if ($package->furniture) {
|
||||
$this->handleFurniture(json_decode($package->furniture, true));
|
||||
$furniture = json_decode($package->furniture, true);
|
||||
if (is_array($furniture)) {
|
||||
$this->handleFurniture($user, $furniture);
|
||||
}
|
||||
}
|
||||
|
||||
$message = __('You have successfully purchased the package :name', ['name' => $package->name]);
|
||||
|
||||
if ($user->username !== Auth::user()->username) {
|
||||
if ($user->username !== $currentUser->username) {
|
||||
$message = __('You have successfully purchased the package :name for :username', ['name' => $package->name, 'username' => $user->username]);
|
||||
}
|
||||
|
||||
return to_route('shop.index')->with('success', $message);
|
||||
}
|
||||
|
||||
public function handleFurniture(array $furniture)
|
||||
/**
|
||||
* @param array<mixed> $furniture
|
||||
*/
|
||||
public function handleFurniture(User $user, array $furniture): void
|
||||
{
|
||||
$sendFurniture = app(SendFurniture::class);
|
||||
|
||||
$sendFurniture->execute(Auth::user(), $furniture);
|
||||
$sendFurniture->execute($user, $furniture);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -11,8 +11,9 @@ class ShopVoucherController extends Controller
|
||||
{
|
||||
public function __invoke(ShopVoucherFormRequest $request): RedirectResponse
|
||||
{
|
||||
/** @var \App\Models\User $user */
|
||||
$user = $request->user();
|
||||
$voucher = WebsiteShopVoucher::where('code', $request->string('code'))->first();
|
||||
$voucher = WebsiteShopVoucher::where('code', $request->string('code')->toString())->first();
|
||||
|
||||
if (is_null($voucher) || ($voucher->expires_at && $voucher->expires_at->lte(now()))) {
|
||||
return back()->withErrors([
|
||||
|
||||
@@ -18,12 +18,15 @@ class AccountSettingsController extends Controller
|
||||
private readonly SessionService $sessionService,
|
||||
private readonly UserService $userService,
|
||||
private readonly RconService $rconService
|
||||
): void {}
|
||||
) {}
|
||||
|
||||
public function edit(): View
|
||||
{
|
||||
/** @var \App\Models\User $user */
|
||||
$user = Auth::user();
|
||||
|
||||
return view('user.settings.account', [
|
||||
'user' => Auth::user()->load('settings:allow_name_change'),
|
||||
'user' => $user->load('settings:allow_name_change'),
|
||||
]);
|
||||
}
|
||||
|
||||
@@ -46,7 +49,7 @@ class AccountSettingsController extends Controller
|
||||
|
||||
// $allowedNameChange = $user->settings?->allow_name_change && $user->username !== $request->input('username');
|
||||
|
||||
if (! $this->rconService->isConnected() && Auth::user()->online === '1') {
|
||||
if (! $this->rconService->isConnected() && $user->online) {
|
||||
return back()->withErrors('You must be offline to change your account settings');
|
||||
}
|
||||
|
||||
@@ -55,12 +58,12 @@ class AccountSettingsController extends Controller
|
||||
$this->userService->updateField($user, 'username', $request->input('username'));
|
||||
} **/
|
||||
if ($user->mail !== $request->input('mail')) {
|
||||
$this->userService->updateField($user, 'mail', $request->input('mail'));
|
||||
$this->userService->updateField($user, 'mail', $request->string('mail')->toString());
|
||||
}
|
||||
|
||||
if ($user->motto !== $request->input('motto')) {
|
||||
$this->rconService->setMotto($user, $request->input('motto'));
|
||||
$this->userService->updateField($user, 'motto', $request->input('motto'));
|
||||
$this->rconService->setMotto($user, $request->string('motto')->toString());
|
||||
$this->userService->updateField($user, 'motto', $request->string('motto')->toString());
|
||||
}
|
||||
|
||||
return to_route('settings.account.show')->with('success', __('Your account settings has been updated'));
|
||||
|
||||
@@ -16,8 +16,11 @@ class BannedController extends Controller
|
||||
->orderByDesc('id')
|
||||
->first();
|
||||
|
||||
/** @var \App\Models\User $user */
|
||||
$user = Auth::user();
|
||||
|
||||
return view('banned', [
|
||||
'ban' => $ipBan ?? Auth::user()->ban,
|
||||
'ban' => $ipBan ?? $user->ban,
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -32,8 +32,8 @@ class ForgotPasswordController extends Controller
|
||||
'token' => $token,
|
||||
]);
|
||||
|
||||
Mail::send('email.forgetPassword', ['token' => $token], function ($message) use ($request): void {
|
||||
$message->to($request->mail);
|
||||
Mail::send('email.forgetPassword', ['token' => $token], function (\Illuminate\Mail\Message $message) use ($request): void {
|
||||
$message->to($request->string('mail')->toString());
|
||||
$message->subject('Reset Password');
|
||||
});
|
||||
}
|
||||
@@ -47,7 +47,12 @@ class ForgotPasswordController extends Controller
|
||||
if ($prt === null) {
|
||||
return to_route('forgot.password.get')->withErrors('message', __('This token has expired!'));
|
||||
}
|
||||
$tokenExpiration = \Illuminate\Support\Facades\Date::now()->subMinutes(config('habbo.password_reset_token_time'));
|
||||
$resetTime = config('habbo.password_reset_token_time');
|
||||
if (! is_numeric($resetTime)) {
|
||||
$resetTime = 60;
|
||||
}
|
||||
|
||||
$tokenExpiration = \Illuminate\Support\Facades\Date::now()->subMinutes((int) $resetTime);
|
||||
if ($prt->created_at->gte($tokenExpiration)) {
|
||||
$prt->delete();
|
||||
|
||||
@@ -66,12 +71,14 @@ class ForgotPasswordController extends Controller
|
||||
'password_confirmation' => ['required'],
|
||||
]);
|
||||
|
||||
$prt = PasswordResetToken::select('email', 'token')->where('token', $token)->first();
|
||||
if ($prt === null) {
|
||||
$prt = PasswordResetToken::with('user')->select('email', 'token')->where('token', $token)->first();
|
||||
if ($prt === null || $prt->user === null) {
|
||||
return to_route('forgot.password.get')->withErrors('message', __('This token has expired!'));
|
||||
}
|
||||
|
||||
$prt->user->changePassword($request->password);
|
||||
/** @var \App\Models\User $user */
|
||||
$user = $prt->user;
|
||||
$user->changePassword($request->string('password')->toString());
|
||||
$prt->delete();
|
||||
|
||||
return to_route('login')->with('success', __('Your password has been successfully reset!'));
|
||||
|
||||
@@ -28,7 +28,16 @@ class GuestbookController extends Controller
|
||||
|
||||
public function destroy(User $user, WebsiteUserGuestbook $guestbook): RedirectResponse
|
||||
{
|
||||
if ($guestbook->user_id !== Auth::id() && $guestbook->profile_id !== $user->id && Auth::user()->rank < (int) setting('min_staff_rank')) {
|
||||
/** @var \App\Models\User|null $currentUser */
|
||||
$currentUser = Auth::user();
|
||||
|
||||
if ($currentUser === null) {
|
||||
return back()->withErrors([
|
||||
'message' => __('You must be logged in.'),
|
||||
]);
|
||||
}
|
||||
|
||||
if ($guestbook->user_id !== $currentUser->id && $guestbook->profile_id !== $user->id && $currentUser->rank < (int) setting('min_staff_rank')) {
|
||||
return back()->withErrors([
|
||||
'message' => __('Do do not have permission to delete this message'),
|
||||
]);
|
||||
@@ -41,12 +50,19 @@ class GuestbookController extends Controller
|
||||
|
||||
private function validateGuestbookPost(User $user, GuestbookFormRequest $request): ?RedirectResponse
|
||||
{
|
||||
if ($user->id === $request->user()->id) {
|
||||
/** @var \App\Models\User|null $currentUser */
|
||||
$currentUser = $request->user();
|
||||
|
||||
if ($currentUser === null) {
|
||||
return $this->redirectWithError(__('You must be logged in.'));
|
||||
}
|
||||
|
||||
if ($user->id === $currentUser->id) {
|
||||
return $this->redirectWithError(__('You cannot post a message on your own profile.'));
|
||||
}
|
||||
|
||||
$maxAllowedPostCount = in_array(setting('max_guestbook_posts_per_profile'), ['', '0'], true) ? 3 : (int) setting('max_guestbook_posts_per_profile');
|
||||
if ($user->profileGuestbook()->where('user_id', $request->user()->id)->count() >= $maxAllowedPostCount) {
|
||||
$maxAllowedPostCount = in_array((string) setting('max_guestbook_posts_per_profile'), ['', '0'], true) ? 3 : (int) setting('max_guestbook_posts_per_profile');
|
||||
if ($user->profileGuestbook()->where('user_id', $currentUser->id)->count() >= $maxAllowedPostCount) {
|
||||
return $this->redirectWithError(__('You have already posted :count messages on this profile.', ['count' => $maxAllowedPostCount]));
|
||||
}
|
||||
|
||||
|
||||
@@ -11,10 +11,12 @@ class MeController extends Controller
|
||||
{
|
||||
public function __invoke(): View
|
||||
{
|
||||
/** @var \App\Models\User $user */
|
||||
$user = Auth::user();
|
||||
|
||||
return view('user.me', [
|
||||
'onlineFriends' => Auth::user()?->getOnlineFriends(),
|
||||
'user' => Auth::user()?->load('permission:id,rank_name'),
|
||||
'onlineFriends' => $user->getOnlineFriends(),
|
||||
'user' => $user->load('permission:id,rank_name'),
|
||||
'articles' => WebsiteArticle::whereHas('user')->with('user:id,username,look')->latest()->take(5)->get(),
|
||||
]);
|
||||
}
|
||||
|
||||
@@ -18,8 +18,11 @@ class PasswordSettingsController extends Controller
|
||||
|
||||
public function update(PasswordSettingsFormRequest $request): RedirectResponse
|
||||
{
|
||||
Auth::user()->update([
|
||||
'password' => Hash::make($request->input('password')),
|
||||
/** @var \App\Models\User $user */
|
||||
$user = Auth::user();
|
||||
|
||||
$user->update([
|
||||
'password' => Hash::make($request->string('password')->toString()),
|
||||
]);
|
||||
|
||||
return to_route('settings.password.show')->with('success', __('Your password has been changed!'));
|
||||
|
||||
@@ -8,6 +8,7 @@ use App\Models\Game\Player\MessengerFriendship;
|
||||
use App\Models\User;
|
||||
use Illuminate\Contracts\View\View;
|
||||
use Illuminate\Database\Eloquent\Collection;
|
||||
use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||
|
||||
class ProfileController extends Controller
|
||||
{
|
||||
@@ -30,12 +31,12 @@ class ProfileController extends Controller
|
||||
private function loadUserRelations(User $user): User
|
||||
{
|
||||
return $user->load([
|
||||
'badges' => function ($badges): void {
|
||||
'badges' => function (HasMany $badges): void {
|
||||
$badges->where('slot_id', '>', '0')
|
||||
->orderBy('slot_id')
|
||||
->take(5);
|
||||
},
|
||||
'rooms' => function ($rooms): void {
|
||||
'rooms' => function (HasMany $rooms): void {
|
||||
$rooms->select('id', 'owner_id', 'name', 'users')
|
||||
->orderByDesc('users')
|
||||
->orderBy('id');
|
||||
@@ -43,6 +44,9 @@ class ProfileController extends Controller
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Collection<int, MessengerFriendship>
|
||||
*/
|
||||
private function getUserFriends(int $userId): Collection
|
||||
{
|
||||
return MessengerFriendship::select('user_two_id')
|
||||
@@ -54,6 +58,9 @@ class ProfileController extends Controller
|
||||
->get();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Collection<int, GuildMember>
|
||||
*/
|
||||
private function getUserGroups(int $userId): Collection
|
||||
{
|
||||
return GuildMember::query()
|
||||
|
||||
@@ -11,17 +11,22 @@ class ReferralController extends Controller
|
||||
{
|
||||
public function __invoke(RconService $rcon): RedirectResponse
|
||||
{
|
||||
/** @var \App\Models\User $user */
|
||||
$user = Auth::user();
|
||||
if (! $user->referrals || $user->referrals->referrals_total < setting('referrals_needed')) {
|
||||
|
||||
/** @var \App\Models\User\UserReferral|null $referrals */
|
||||
$referrals = $user->referrals;
|
||||
|
||||
if ($referrals === null || $referrals->referrals_total < (int) setting('referrals_needed')) {
|
||||
return back()->withErrors([
|
||||
'message' => __('You do not have enough referrals to claim your reward'),
|
||||
]);
|
||||
}
|
||||
|
||||
// Decrease the total amount of referrals with the amount needed to claim reward
|
||||
$user->referrals->decrement('referrals_total', setting('referrals_needed'));
|
||||
$referrals->decrement('referrals_total', (int) setting('referrals_needed'));
|
||||
|
||||
$rcon->giveDiamonds($user, setting('referral_reward_amount'));
|
||||
$rcon->giveDiamonds($user, (int) setting('referral_reward_amount'));
|
||||
|
||||
// Log the claim
|
||||
$user->claimedReferralLog()->create([
|
||||
|
||||
@@ -25,7 +25,10 @@ class TwoFactorAuthenticationController extends Controller
|
||||
|
||||
public function verify(Request $request): RedirectResponse
|
||||
{
|
||||
$confirmed = $request->user()->confirmTwoFactorAuthentication($request->input('code'));
|
||||
/** @var \App\Models\User $user */
|
||||
$user = $request->user();
|
||||
|
||||
$confirmed = $user->confirmTwoFactorAuthentication($request->string('code')->toString());
|
||||
if (! $confirmed) {
|
||||
return back()->withErrors('Invalid Two Factor Authentication code');
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user