account refactor
This commit is contained in:
@@ -142,7 +142,24 @@ readonly class AuthService
|
||||
{
|
||||
$name = (new Name($name));
|
||||
$this->userRepo->updateName($this->currentUserId(), $name);
|
||||
$user = $this->userRepo->findById($this->currentUserId());
|
||||
$this->session->put(["user" => $user->get()->safe()]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws LucentException
|
||||
*/
|
||||
public function updateEmail(string $email): void
|
||||
{
|
||||
$email = (new Email($email));
|
||||
$user = $this->userRepo->findByEmail($email);
|
||||
if($user->isDefined()){
|
||||
throw new LucentException("Email already assigned to user");
|
||||
}
|
||||
|
||||
$this->userRepo->updateEmail($this->currentUserId(), $email);
|
||||
$user = $this->userRepo->findById($this->currentUserId());
|
||||
$this->session->put(["user" => $user->get()->safe()]);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -88,4 +88,9 @@ class UserRepo
|
||||
{
|
||||
DB::table("users")->where("id", $userId)->update(["name" => $name->value]);
|
||||
}
|
||||
|
||||
public function updateEmail(string $userId, Email $email): void
|
||||
{
|
||||
DB::table("users")->where("id", $userId)->update(["email" => $email->value()]);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -42,4 +42,16 @@ class AccountController extends Controller
|
||||
return ok();
|
||||
}
|
||||
|
||||
public function updateEmail(Request $request)
|
||||
{
|
||||
|
||||
try {
|
||||
$this->authService->updateEmail($request->input("email"));
|
||||
} catch (Throwable $th) {
|
||||
return fail($th);
|
||||
}
|
||||
|
||||
return ok();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -5,8 +5,6 @@ namespace Lucent\Http\Controller;
|
||||
use App\Http\Controllers\Controller;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Validator;
|
||||
use Intervention\Image\ImageManager;
|
||||
use Lucent\Channel\ChannelRepo;
|
||||
use Lucent\Channel\ChannelService;
|
||||
use Lucent\File\FileUploadResult;
|
||||
use Lucent\Query\Query;
|
||||
@@ -34,65 +32,10 @@ class FileController extends Controller
|
||||
return $disk->download($request->input("path"));
|
||||
}
|
||||
|
||||
public function get(Request $request)
|
||||
{
|
||||
$manager = new ImageManager(['driver' => 'imagick']);
|
||||
$filesystem = loadDisk();
|
||||
$path = $request->route("path");
|
||||
|
||||
if ($filesystem->exists($path)) {
|
||||
$image = $manager->make($filesystem->get($path));
|
||||
return $image->response();
|
||||
}
|
||||
$arr = explode(".", $path);
|
||||
$ext = end($arr);
|
||||
$pathWithoutExtension = str_replace("." . $ext, "", $path);
|
||||
|
||||
$pathArguments = (function ($path) {
|
||||
$pathWithArgumentsAr = explode("-", $path);
|
||||
return collect($pathWithArgumentsAr)
|
||||
->filter(fn($ar) => str_contains($ar, "_"))
|
||||
->reduce(function ($carry, $arg) {
|
||||
[$k, $v] = explode("_", $arg);
|
||||
$carry[$k] = $v;
|
||||
return $carry;
|
||||
});
|
||||
|
||||
})($pathWithoutExtension);
|
||||
|
||||
$originalPath = (function ($path) use ($ext) {
|
||||
$arr = explode("-o-", $path);
|
||||
return $arr[0] . "." . $ext;
|
||||
})($path);
|
||||
$image = $manager->make($filesystem->get($originalPath));
|
||||
if (empty($pathArguments["mode"])) {
|
||||
|
||||
if (empty($pathArguments["w"])) {
|
||||
$image->resize(null, $pathArguments["h"], function ($constraint) {
|
||||
$constraint->aspectRatio();
|
||||
});
|
||||
} elseif (empty($pathArguments["h"])) {
|
||||
$image->resize($pathArguments["w"], null, function ($constraint) {
|
||||
$constraint->aspectRatio();
|
||||
});
|
||||
} else {
|
||||
$image->resize($pathArguments["w"], $pathArguments["h"]);
|
||||
}
|
||||
} else if ($pathArguments["mode"] === "fit") {
|
||||
$image->fit($pathArguments["w"], $pathArguments["h"]);
|
||||
}
|
||||
|
||||
$disk = loadDisk();
|
||||
// $disk->put("cache/" . $path, $image);
|
||||
$image->save(storage_path("app/public/cache/" . $path));
|
||||
return $image->response();
|
||||
|
||||
}
|
||||
|
||||
|
||||
public function upload(Request $request)
|
||||
{
|
||||
$validator = Validator::make(request()->all(), [
|
||||
$validator = Validator::make($request->all(), [
|
||||
'files.*' => 'required|file|max:100000',
|
||||
]);
|
||||
|
||||
@@ -100,7 +43,7 @@ class FileController extends Controller
|
||||
return fail($validator->errors()->first());
|
||||
}
|
||||
$schema = $this->channelService->channel->schemas->firstWhere("name", $request->input("schema"));
|
||||
$files = request()->file('files');
|
||||
$files = $request->file('files');
|
||||
|
||||
|
||||
$uploadResults = collect($files)->map(fn($file) => uploadFile($schema, $file))->toArray();
|
||||
@@ -128,8 +71,6 @@ class FileController extends Controller
|
||||
->limit(15)
|
||||
->skip(0)
|
||||
->sort("-_sys.updatedAt")
|
||||
->childrenDepth(0)
|
||||
->parentsDepth(0)
|
||||
->run();
|
||||
|
||||
return ok($graph->records->toArray());
|
||||
|
||||
+1
-1
@@ -31,6 +31,7 @@ Route::group([
|
||||
Route::get('/logout', [AuthController::class, 'logout']);
|
||||
Route::get('/profile', [AccountController::class, 'profile']);
|
||||
Route::post('/account/update-name', [AccountController::class, 'updateName']);
|
||||
Route::post('/account/update-email', [AccountController::class, 'updateEmail']);
|
||||
Route::get('/build-report', [BuildController::class, 'report']);
|
||||
Route::get('/build-report-source', [BuildController::class, 'reportSource']);
|
||||
Route::post('/build', [BuildController::class, 'build']);
|
||||
@@ -76,7 +77,6 @@ Route::group([
|
||||
});
|
||||
|
||||
Route::middleware(["lucent.auth"])->group(function () {
|
||||
|
||||
Route::post('/files/upload', [FileController::class, 'upload']);
|
||||
Route::get('/files/download', [FileController::class, 'download']);
|
||||
});
|
||||
|
||||
@@ -48,11 +48,7 @@ readonly class RecordService
|
||||
string $uploadFromUrl = "",
|
||||
): string
|
||||
{
|
||||
$schema = $this->channelService->channel->schemas->where("name", $schemaName)->first();
|
||||
|
||||
if (empty($schema)) {
|
||||
throw new LucentException("The schema " . $schemaName . " does not exist");
|
||||
}
|
||||
$schema = $this->channelService->getSchema($schemaName)->get();
|
||||
|
||||
$formattedData = $this->inputFormatter->fill($schemaName, new RecordData($data));
|
||||
if (empty($formattedData["id"])) {
|
||||
|
||||
@@ -1,12 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Lucent\Token;
|
||||
|
||||
|
||||
class Token
|
||||
{
|
||||
public static function new($length = "64"): string
|
||||
{
|
||||
return bin2hex(random_bytes($length));
|
||||
}
|
||||
}
|
||||
@@ -1,21 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Lucent\Validator;
|
||||
|
||||
use Lucent\Validator\Validator;
|
||||
|
||||
|
||||
class Uid
|
||||
{
|
||||
public string $value;
|
||||
function __construct(string $value)
|
||||
{
|
||||
Validator::single("Uid", $value, "required|alpha_dash|min:2|max:50");
|
||||
$this->value = $value;
|
||||
}
|
||||
|
||||
function value(): string
|
||||
{
|
||||
return $this->value;
|
||||
}
|
||||
}
|
||||
@@ -6,25 +6,27 @@
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||
<meta name="csrf-token" content="{{ csrf_token() }}">
|
||||
<title>@yield('title') - Lucent Data Platform</title>
|
||||
{{-- @php--}}
|
||||
{{-- echo '<script type="module" crossorigin src="http://127.0.0.1:5173/@vite/client"></script>';--}}
|
||||
{{-- @endphp--}}
|
||||
{{-- <script type="module" crossorigin src="http://127.0.0.1:5173/main.js"></script>--}}
|
||||
|
||||
<!-- if Dev -->
|
||||
@php
|
||||
echo '<script type="module" crossorigin src="http://127.0.0.1:5173/@vite/client"></script>';
|
||||
@endphp
|
||||
<script type="module" crossorigin src="http://127.0.0.1:5173/main.js"></script>
|
||||
|
||||
|
||||
<!-- if production -->
|
||||
<link rel="stylesheet" href="/vendor/lucent/dist/{{ $manifest['main.css']["file"] }}" />
|
||||
<script type="module" src="/vendor/lucent/dist/{{ $manifest['main.js']["file"] }}"></script>
|
||||
{{-- <link rel="stylesheet" href="/vendor/lucent/dist/{{ $manifest['main.css']["file"] }}" />--}}
|
||||
{{-- <script type="module" src="/vendor/lucent/dist/{{ $manifest['main.js']["file"] }}"></script>--}}
|
||||
|
||||
|
||||
<link rel="icon" type="image/x-icon" href="/favicon.ico">
|
||||
|
||||
</head>
|
||||
|
||||
<body class="view-{{ $view }}">
|
||||
<div class="mt-5">
|
||||
<div class="text-center">
|
||||
<h1><a href="/" class="text-decoration-none">{{ config("app.name") }}</a></h1>
|
||||
</div>
|
||||
<div>
|
||||
@yield('content')
|
||||
</div>
|
||||
@yield('content')
|
||||
|
||||
</div>
|
||||
|
||||
</body>
|
||||
|
||||
@@ -7,13 +7,13 @@
|
||||
<meta name="csrf-token" content="{{ csrf_token() }}">
|
||||
<title>@yield('title') - Lucent Data Platform</title>
|
||||
<!-- if development -->
|
||||
{{-- @php--}}
|
||||
{{-- echo '<script type="module" crossorigin src="http://127.0.0.1:5173/@vite/client"></script>';--}}
|
||||
{{-- @endphp--}}
|
||||
{{-- <script type="module" crossorigin src="http://127.0.0.1:5173/main.js"></script>--}}
|
||||
@php
|
||||
echo '<script type="module" crossorigin src="http://127.0.0.1:5173/@vite/client"></script>';
|
||||
@endphp
|
||||
<script type="module" crossorigin src="http://127.0.0.1:5173/main.js"></script>
|
||||
<!-- if production -->
|
||||
<link rel="stylesheet" href="/vendor/lucent/dist/{{ $manifest['main.css']["file"] }}" />
|
||||
<script type="module" src="/vendor/lucent/dist/{{ $manifest['main.js']["file"] }}"></script>
|
||||
{{-- <link rel="stylesheet" href="/vendor/lucent/dist/{{ $manifest['main.css']["file"] }}" />--}}
|
||||
{{-- <script type="module" src="/vendor/lucent/dist/{{ $manifest['main.js']["file"] }}"></script>--}}
|
||||
|
||||
|
||||
<link rel="icon" type="image/x-icon" href="/favicon.ico">
|
||||
|
||||
Reference in New Issue
Block a user