forked from metin2/web
Shop improvements, renamed "shop" to "mall", support for Argon2ID
This commit is contained in:
@ -2,7 +2,6 @@
|
||||
|
||||
namespace App\Http\Controllers\Auth;
|
||||
|
||||
use App\Hashing\MySQLHasher;
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Models\Account;
|
||||
use App\Models\Enums\AccountStatusEnum;
|
||||
@ -10,6 +9,7 @@ use Illuminate\Auth\Events\Registered;
|
||||
use Illuminate\Http\RedirectResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Illuminate\Support\Facades\Hash;
|
||||
use Illuminate\Support\Facades\Validator;
|
||||
use Illuminate\Validation\ValidationException;
|
||||
use Illuminate\View\View;
|
||||
@ -43,7 +43,7 @@ class RegisterController extends Controller
|
||||
$account = new Account();
|
||||
$account->login = $data['login'];
|
||||
$account->email = $data['email'];
|
||||
$account->password = (new MySQLHasher)->make($data['password']);
|
||||
$account->password = Hash::make($data['password']);
|
||||
$account->status = AccountStatusEnum::NOT_AVAILABLE;
|
||||
$account->saveOrFail();
|
||||
|
||||
|
@ -1,18 +1,18 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Shop;
|
||||
namespace App\Http\Controllers\Mall;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Models\Shop\ShopCategory;
|
||||
use App\Models\Mall\MallCategory;
|
||||
use Illuminate\View\View;
|
||||
|
||||
class CategoryController extends Controller
|
||||
{
|
||||
public function show(int $id): View
|
||||
{
|
||||
$category = ShopCategory::find($id);
|
||||
$category = MallCategory::find($id);
|
||||
|
||||
return view('shop/category', [
|
||||
return view('mall/category', [
|
||||
'category' => $category
|
||||
]);
|
||||
}
|
20
app/Http/Controllers/Mall/HomeController.php
Normal file
20
app/Http/Controllers/Mall/HomeController.php
Normal file
@ -0,0 +1,20 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Mall;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Models\Mall\MallItem;
|
||||
use Illuminate\View\View;
|
||||
|
||||
class HomeController extends Controller
|
||||
{
|
||||
public function home(): View
|
||||
{
|
||||
$largeSuggestions = MallItem::getSuggestions(2, frontpageDisplay: 'recommend_desc');
|
||||
$smallSuggestions = MallItem::getSuggestions(8 - (2 * $largeSuggestions->count()), frontpageDisplay: 'recommend');
|
||||
|
||||
return view('mall/home', [
|
||||
'suggestions' => $largeSuggestions->merge($smallSuggestions),
|
||||
]);
|
||||
}
|
||||
}
|
87
app/Http/Controllers/Mall/ItemController.php
Normal file
87
app/Http/Controllers/Mall/ItemController.php
Normal file
@ -0,0 +1,87 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Mall;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Models\Mall\MallItem;
|
||||
use App\Utils\ImageHelpers;
|
||||
use Illuminate\View\View;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
|
||||
|
||||
class ItemController extends Controller
|
||||
{
|
||||
public function show(int $id): View
|
||||
{
|
||||
$item = MallItem::find($id);
|
||||
$suggestions = MallItem::getSuggestions(7, $item);
|
||||
|
||||
return view('mall/item/show', [
|
||||
'item' => $item,
|
||||
'suggestions' => $suggestions,
|
||||
]);
|
||||
}
|
||||
|
||||
public function generateImage(int $id, bool $isLarge = false, float $maxIconRatio = 0.8): Response
|
||||
{
|
||||
$item = MallItem::find($id);
|
||||
|
||||
// Return an error image if the item or its image is not found
|
||||
if (!$item || !$item->image) {
|
||||
return response()->file(public_path('assets/mall/img/error.png'));
|
||||
}
|
||||
|
||||
// Return an error if the item image is not available on the server
|
||||
if (!file_exists(public_path("assets/mall/img/item/icon/{$item->image}.png"))) {
|
||||
return response()->file(public_path('assets/mall/img/error.png'));
|
||||
}
|
||||
|
||||
// Load the proper background
|
||||
if (!$isLarge)
|
||||
$imageData = imagecreatefrompng(public_path('assets/mall/img/item/background.png'));
|
||||
else
|
||||
$imageData = imagecreatefrompng(public_path('assets/mall/img/item/background-lg.png'));
|
||||
|
||||
|
||||
// Get the max width or height we can work with
|
||||
$maxSquareSize = (int) (min(imagesx($imageData), imagesy($imageData)) * $maxIconRatio);
|
||||
|
||||
// Load the item icon
|
||||
$itemIcon = imagecreatefrompng(public_path("assets/mall/img/item/icon/{$item->image}.png"));
|
||||
|
||||
// Get the max dimension of the icon
|
||||
$maxIconDimension = max(imagesx($itemIcon), imagesy($itemIcon));
|
||||
|
||||
// Resize the icon
|
||||
$scalingFactor = (float) $maxSquareSize / $maxIconDimension;
|
||||
|
||||
// Select the best resizing algorithm based on whether we have to enlarge or reduce the icon size
|
||||
$mode = IMG_BILINEAR_FIXED;
|
||||
if ($scalingFactor < 1)
|
||||
$mode = IMG_BICUBIC_FIXED;
|
||||
|
||||
$itemIcon = imagescale($itemIcon, imagesx($itemIcon) * $scalingFactor, mode: $mode);
|
||||
|
||||
$destX = (imagesx($imageData) - imagesx($itemIcon)) / 2;
|
||||
$destY = (imagesy($imageData) - imagesy($itemIcon)) / 2;
|
||||
|
||||
// Apply the icon onto the background
|
||||
ImageHelpers::imagecopymerge_alpha($imageData, $itemIcon, $destX, $destY, 0, 0, imagesx($itemIcon), imagesy($itemIcon), 100);
|
||||
|
||||
return response()->streamDownload(
|
||||
function () use ($imageData) {
|
||||
echo imagejpeg($imageData);
|
||||
},
|
||||
headers: [
|
||||
'Content-Type' => 'image/jpeg',
|
||||
'Cache-Control' => 'max-age=3600',
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
public function generateLargeImage(int $id): Response
|
||||
{
|
||||
return $this->generateImage($id, true, 0.7);
|
||||
}
|
||||
|
||||
}
|
@ -1,20 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Shop;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Models\Shop\ShopCategory;
|
||||
use App\Models\Shop\ShopItem;
|
||||
use Illuminate\View\View;
|
||||
|
||||
class ItemController extends Controller
|
||||
{
|
||||
public function show(int $id): View
|
||||
{
|
||||
$item = ShopItem::find($id);
|
||||
|
||||
return view('shop/item/show', [
|
||||
'item' => $item
|
||||
]);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user