account refactor
This commit is contained in:
@@ -1,9 +0,0 @@
|
|||||||
#!/bin/bash
|
|
||||||
|
|
||||||
cp -r ./ ~/temp-lucent
|
|
||||||
cd ~/temp-lucent && npm run build
|
|
||||||
rm -rf ~/temp-lucent/node_modules
|
|
||||||
rm -rf ~/temp-lucent/.git
|
|
||||||
cd ~/
|
|
||||||
zip -r lucent.zip temp-lucent/
|
|
||||||
rm -rf ~/temp-lucent
|
|
||||||
@@ -1,3 +0,0 @@
|
|||||||
#!/bin/bash
|
|
||||||
|
|
||||||
php8.2 artisan serve --port 8197
|
|
||||||
@@ -21,5 +21,10 @@
|
|||||||
setContext("channel", channel);
|
setContext("channel", channel);
|
||||||
setContext("user", user);
|
setContext("user", user);
|
||||||
</script>
|
</script>
|
||||||
|
<div class="text-center">
|
||||||
|
<h1><a class="text-decoration-none" href="{channel.lucentUrl}">{channel.name}</a></h1>
|
||||||
|
</div>
|
||||||
|
<div>
|
||||||
|
<svelte:component this={components[view]} {title} {...data}/>
|
||||||
|
</div>
|
||||||
|
|
||||||
<svelte:component this={components[view]} {title} {...data}/>
|
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
<script>
|
<script>
|
||||||
import {getContext} from "svelte";
|
import {getContext} from "svelte";
|
||||||
import SpinnerButton from "../common/SpinnerButton.svelte";
|
import SpinnerButton from "../common/SpinnerButton.svelte";
|
||||||
import SuccessAlert from "../common/SuccessAlert.svelte";
|
|
||||||
|
|
||||||
const channel = getContext("channel");
|
const channel = getContext("channel");
|
||||||
let email = "";
|
let email = "";
|
||||||
|
|||||||
@@ -3,23 +3,25 @@
|
|||||||
import SpinnerButton from "../common/SpinnerButton.svelte";
|
import SpinnerButton from "../common/SpinnerButton.svelte";
|
||||||
import Avatar from "./Avatar.svelte";
|
import Avatar from "./Avatar.svelte";
|
||||||
import {getContext} from "svelte";
|
import {getContext} from "svelte";
|
||||||
|
import SuccessAlert from "../common/SuccessAlert.svelte";
|
||||||
|
|
||||||
const user = getContext("user");
|
const user = getContext("user");
|
||||||
const channel = getContext("channel");
|
const channel = getContext("channel");
|
||||||
let name = user.name;
|
let name = user.name;
|
||||||
let email = user.email;
|
let email = user.email;
|
||||||
let errorMessage = "";
|
let errorMessage = "";
|
||||||
|
let successAlert;
|
||||||
|
|
||||||
function saveName(e) {
|
function saveName(e) {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
errorMessage = "";
|
errorMessage = "";
|
||||||
|
|
||||||
axios
|
axios
|
||||||
.post("/account/update-name", {
|
.post(channel.lucentUrl + "/account/update-name", {
|
||||||
name: name,
|
name: name,
|
||||||
})
|
})
|
||||||
.then((response) => {
|
.then((response) => {
|
||||||
// window.reload();
|
successAlert.show();
|
||||||
})
|
})
|
||||||
.catch((error) => {
|
.catch((error) => {
|
||||||
errorMessage = error.response?.data.error;
|
errorMessage = error.response?.data.error;
|
||||||
@@ -32,11 +34,11 @@
|
|||||||
errorMessage = "";
|
errorMessage = "";
|
||||||
|
|
||||||
axios
|
axios
|
||||||
.post("/account/update-email", {
|
.post(channel.lucentUrl + "/account/update-email", {
|
||||||
email: email,
|
email: email,
|
||||||
})
|
})
|
||||||
.then((response) => {
|
.then((response) => {
|
||||||
// window.reload();
|
successAlert.show();
|
||||||
})
|
})
|
||||||
.catch((error) => {
|
.catch((error) => {
|
||||||
errorMessage = error.response?.data.error;
|
errorMessage = error.response?.data.error;
|
||||||
@@ -48,22 +50,38 @@
|
|||||||
|
|
||||||
<div class="wrapper-tiny">
|
<div class="wrapper-tiny">
|
||||||
<ErrorAlert message={errorMessage}/>
|
<ErrorAlert message={errorMessage}/>
|
||||||
|
<SuccessAlert bind:this={successAlert} />
|
||||||
<h3 class="header-small mb-5">
|
<h3 class="header-small mb-5">
|
||||||
<Avatar name={user.name}/>
|
<Avatar name={user.name}/>
|
||||||
</h3>
|
</h3>
|
||||||
<form on:submit={saveName}>
|
<form on:submit={saveName}>
|
||||||
<div class="input-group mb-3">
|
<div class="input-group mb-3">
|
||||||
<input
|
<input
|
||||||
type="text"
|
type="text"
|
||||||
bind:value={name}
|
bind:value={name}
|
||||||
class="form-control"
|
class="form-control"
|
||||||
placeholder="Name"
|
placeholder="Name"
|
||||||
|
required
|
||||||
|
/>
|
||||||
|
<SpinnerButton label="Update"/>
|
||||||
|
</div>
|
||||||
|
</form>
|
||||||
|
|
||||||
|
<form on:submit={saveEmail}>
|
||||||
|
<div class="input-group mb-3">
|
||||||
|
<input
|
||||||
|
type="email"
|
||||||
|
bind:value={email}
|
||||||
|
class="form-control"
|
||||||
|
placeholder="Email"
|
||||||
|
required
|
||||||
/>
|
/>
|
||||||
<SpinnerButton label="Update"/>
|
<SpinnerButton label="Update"/>
|
||||||
</div>
|
</div>
|
||||||
</form>
|
</form>
|
||||||
|
|
||||||
<div class="list-group">
|
<div class="list-group">
|
||||||
<a class="list-group-item list-group-item-action" href="{ channel.lucentUrl }/logout">Logout from this device</a>
|
<a class="list-group-item list-group-item-action" href="{ channel.lucentUrl }/logout">Logout from this
|
||||||
|
device</a>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -1,44 +0,0 @@
|
|||||||
export function avatar(name, side = 48) {
|
|
||||||
const colors = [
|
|
||||||
"#00AA55",
|
|
||||||
"#009FD4",
|
|
||||||
"#B381B3",
|
|
||||||
"#939393",
|
|
||||||
"#E3BC00",
|
|
||||||
"#D47500",
|
|
||||||
"#DC2A2A",
|
|
||||||
"#3ede91",
|
|
||||||
"#377dd4",
|
|
||||||
"#0256b0",
|
|
||||||
"#053d82",
|
|
||||||
"#3d026e",
|
|
||||||
"#b378e3",
|
|
||||||
"#c4065c",
|
|
||||||
"#543208",
|
|
||||||
"#d97811",
|
|
||||||
"#0c6b40",
|
|
||||||
];
|
|
||||||
let initials = "";
|
|
||||||
if (name.split(" ").length > 1) {
|
|
||||||
initials =
|
|
||||||
name.split(" ")[0].charAt(0).toUpperCase() +
|
|
||||||
name.split(" ")[1].charAt(0).toUpperCase();
|
|
||||||
} else {
|
|
||||||
initials =
|
|
||||||
name.split(" ")[0].charAt(0).toUpperCase() +
|
|
||||||
name.split(" ")[0].charAt(1).toUpperCase();
|
|
||||||
}
|
|
||||||
|
|
||||||
let charIndex = name.charCodeAt(1) + name.length;
|
|
||||||
let colorIndex = charIndex % 19;
|
|
||||||
|
|
||||||
return `
|
|
||||||
<div
|
|
||||||
class="avatar"
|
|
||||||
style="background-color:${
|
|
||||||
colors[colorIndex]
|
|
||||||
};height: ${side}px;width: ${side}px; font-size:${side / 2}px">
|
|
||||||
<div class="avatar__letters">${initials}</div>
|
|
||||||
</div>
|
|
||||||
`;
|
|
||||||
}
|
|
||||||
@@ -1,6 +1,5 @@
|
|||||||
<script>
|
<script>
|
||||||
import {getContext} from "svelte";
|
import {getContext} from "svelte";
|
||||||
import Status from "./Status.svelte";
|
|
||||||
import {getStatus, getStatusList} from "./StatusText";
|
import {getStatus, getStatusList} from "./StatusText";
|
||||||
|
|
||||||
const channel = getContext("channel");
|
const channel = getContext("channel");
|
||||||
|
|||||||
@@ -142,7 +142,24 @@ readonly class AuthService
|
|||||||
{
|
{
|
||||||
$name = (new Name($name));
|
$name = (new Name($name));
|
||||||
$this->userRepo->updateName($this->currentUserId(), $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]);
|
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();
|
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 App\Http\Controllers\Controller;
|
||||||
use Illuminate\Http\Request;
|
use Illuminate\Http\Request;
|
||||||
use Illuminate\Support\Facades\Validator;
|
use Illuminate\Support\Facades\Validator;
|
||||||
use Intervention\Image\ImageManager;
|
|
||||||
use Lucent\Channel\ChannelRepo;
|
|
||||||
use Lucent\Channel\ChannelService;
|
use Lucent\Channel\ChannelService;
|
||||||
use Lucent\File\FileUploadResult;
|
use Lucent\File\FileUploadResult;
|
||||||
use Lucent\Query\Query;
|
use Lucent\Query\Query;
|
||||||
@@ -34,65 +32,10 @@ class FileController extends Controller
|
|||||||
return $disk->download($request->input("path"));
|
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)
|
public function upload(Request $request)
|
||||||
{
|
{
|
||||||
$validator = Validator::make(request()->all(), [
|
$validator = Validator::make($request->all(), [
|
||||||
'files.*' => 'required|file|max:100000',
|
'files.*' => 'required|file|max:100000',
|
||||||
]);
|
]);
|
||||||
|
|
||||||
@@ -100,7 +43,7 @@ class FileController extends Controller
|
|||||||
return fail($validator->errors()->first());
|
return fail($validator->errors()->first());
|
||||||
}
|
}
|
||||||
$schema = $this->channelService->channel->schemas->firstWhere("name", $request->input("schema"));
|
$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();
|
$uploadResults = collect($files)->map(fn($file) => uploadFile($schema, $file))->toArray();
|
||||||
@@ -128,8 +71,6 @@ class FileController extends Controller
|
|||||||
->limit(15)
|
->limit(15)
|
||||||
->skip(0)
|
->skip(0)
|
||||||
->sort("-_sys.updatedAt")
|
->sort("-_sys.updatedAt")
|
||||||
->childrenDepth(0)
|
|
||||||
->parentsDepth(0)
|
|
||||||
->run();
|
->run();
|
||||||
|
|
||||||
return ok($graph->records->toArray());
|
return ok($graph->records->toArray());
|
||||||
|
|||||||
+1
-1
@@ -31,6 +31,7 @@ Route::group([
|
|||||||
Route::get('/logout', [AuthController::class, 'logout']);
|
Route::get('/logout', [AuthController::class, 'logout']);
|
||||||
Route::get('/profile', [AccountController::class, 'profile']);
|
Route::get('/profile', [AccountController::class, 'profile']);
|
||||||
Route::post('/account/update-name', [AccountController::class, 'updateName']);
|
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', [BuildController::class, 'report']);
|
||||||
Route::get('/build-report-source', [BuildController::class, 'reportSource']);
|
Route::get('/build-report-source', [BuildController::class, 'reportSource']);
|
||||||
Route::post('/build', [BuildController::class, 'build']);
|
Route::post('/build', [BuildController::class, 'build']);
|
||||||
@@ -76,7 +77,6 @@ Route::group([
|
|||||||
});
|
});
|
||||||
|
|
||||||
Route::middleware(["lucent.auth"])->group(function () {
|
Route::middleware(["lucent.auth"])->group(function () {
|
||||||
|
|
||||||
Route::post('/files/upload', [FileController::class, 'upload']);
|
Route::post('/files/upload', [FileController::class, 'upload']);
|
||||||
Route::get('/files/download', [FileController::class, 'download']);
|
Route::get('/files/download', [FileController::class, 'download']);
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -48,11 +48,7 @@ readonly class RecordService
|
|||||||
string $uploadFromUrl = "",
|
string $uploadFromUrl = "",
|
||||||
): string
|
): string
|
||||||
{
|
{
|
||||||
$schema = $this->channelService->channel->schemas->where("name", $schemaName)->first();
|
$schema = $this->channelService->getSchema($schemaName)->get();
|
||||||
|
|
||||||
if (empty($schema)) {
|
|
||||||
throw new LucentException("The schema " . $schemaName . " does not exist");
|
|
||||||
}
|
|
||||||
|
|
||||||
$formattedData = $this->inputFormatter->fill($schemaName, new RecordData($data));
|
$formattedData = $this->inputFormatter->fill($schemaName, new RecordData($data));
|
||||||
if (empty($formattedData["id"])) {
|
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="viewport" content="width=device-width, initial-scale=1">
|
||||||
<meta name="csrf-token" content="{{ csrf_token() }}">
|
<meta name="csrf-token" content="{{ csrf_token() }}">
|
||||||
<title>@yield('title') - Lucent Data Platform</title>
|
<title>@yield('title') - Lucent Data Platform</title>
|
||||||
{{-- @php--}}
|
|
||||||
{{-- echo '<script type="module" crossorigin src="http://127.0.0.1:5173/@vite/client"></script>';--}}
|
<!-- if Dev -->
|
||||||
{{-- @endphp--}}
|
@php
|
||||||
{{-- <script type="module" crossorigin src="http://127.0.0.1:5173/main.js"></script>--}}
|
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 -->
|
<!-- if production -->
|
||||||
<link rel="stylesheet" href="/vendor/lucent/dist/{{ $manifest['main.css']["file"] }}" />
|
{{-- <link rel="stylesheet" href="/vendor/lucent/dist/{{ $manifest['main.css']["file"] }}" />--}}
|
||||||
<script type="module" src="/vendor/lucent/dist/{{ $manifest['main.js']["file"] }}"></script>
|
{{-- <script type="module" src="/vendor/lucent/dist/{{ $manifest['main.js']["file"] }}"></script>--}}
|
||||||
|
|
||||||
|
|
||||||
<link rel="icon" type="image/x-icon" href="/favicon.ico">
|
<link rel="icon" type="image/x-icon" href="/favicon.ico">
|
||||||
|
|
||||||
</head>
|
</head>
|
||||||
|
|
||||||
<body class="view-{{ $view }}">
|
<body class="view-{{ $view }}">
|
||||||
<div class="mt-5">
|
<div class="mt-5">
|
||||||
<div class="text-center">
|
@yield('content')
|
||||||
<h1><a href="/" class="text-decoration-none">{{ config("app.name") }}</a></h1>
|
|
||||||
</div>
|
|
||||||
<div>
|
|
||||||
@yield('content')
|
|
||||||
</div>
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
</body>
|
</body>
|
||||||
|
|||||||
@@ -7,13 +7,13 @@
|
|||||||
<meta name="csrf-token" content="{{ csrf_token() }}">
|
<meta name="csrf-token" content="{{ csrf_token() }}">
|
||||||
<title>@yield('title') - Lucent Data Platform</title>
|
<title>@yield('title') - Lucent Data Platform</title>
|
||||||
<!-- if development -->
|
<!-- if development -->
|
||||||
{{-- @php--}}
|
@php
|
||||||
{{-- echo '<script type="module" crossorigin src="http://127.0.0.1:5173/@vite/client"></script>';--}}
|
echo '<script type="module" crossorigin src="http://127.0.0.1:5173/@vite/client"></script>';
|
||||||
{{-- @endphp--}}
|
@endphp
|
||||||
{{-- <script type="module" crossorigin src="http://127.0.0.1:5173/main.js"></script>--}}
|
<script type="module" crossorigin src="http://127.0.0.1:5173/main.js"></script>
|
||||||
<!-- if production -->
|
<!-- if production -->
|
||||||
<link rel="stylesheet" href="/vendor/lucent/dist/{{ $manifest['main.css']["file"] }}" />
|
{{-- <link rel="stylesheet" href="/vendor/lucent/dist/{{ $manifest['main.css']["file"] }}" />--}}
|
||||||
<script type="module" src="/vendor/lucent/dist/{{ $manifest['main.js']["file"] }}"></script>
|
{{-- <script type="module" src="/vendor/lucent/dist/{{ $manifest['main.js']["file"] }}"></script>--}}
|
||||||
|
|
||||||
|
|
||||||
<link rel="icon" type="image/x-icon" href="/favicon.ico">
|
<link rel="icon" type="image/x-icon" href="/favicon.ico">
|
||||||
|
|||||||
Reference in New Issue
Block a user