Progressing on profile edition and thumbnail cropping
This commit is contained in:
parent
e904f28b3b
commit
6856d3b9af
|
|
@ -15,13 +15,6 @@ const reset = (_: MouseEvent) => {
|
|||
dispX.value = 0;
|
||||
dispY.value = 0;
|
||||
}
|
||||
function clamp(x: number, min: number, max: number): number {
|
||||
if (x > max)
|
||||
return max;
|
||||
if (x < min)
|
||||
return min;
|
||||
return x;
|
||||
}
|
||||
function edgePos(side: 'bottom' | 'top' | 'left' | 'right', pos: { x: number, y: number }, offset: number): { x: number, y: number } {
|
||||
switch (side) {
|
||||
case "left":
|
||||
|
|
|
|||
|
|
@ -1,7 +1,8 @@
|
|||
<template>
|
||||
<HoverPopup @before-show="fetch" :class="[{'is-loaded': fetched}, file?.type === 'Markdown' ? 'overflow-auto' : 'overflow-hidden']">
|
||||
<HoverPopup @before-show="fetch">
|
||||
<template #content>
|
||||
<Suspense suspensible>
|
||||
<div :class="[{'is-loaded': fetched}, file?.type === 'Markdown' ? 'overflow-auto' : 'overflow-hidden']">
|
||||
<div v-if="pending" class="loading w-[550px] h-[450px]"></div>
|
||||
<template v-else-if="!!file">
|
||||
<div v-if="file.type === 'Markdown'" class="p-6 ms-6">
|
||||
|
|
@ -20,6 +21,8 @@
|
|||
<div class="text-3xl font-extralight tracking-wide text-light-60 dark:text-dark-60">Impossible d'afficher</div>
|
||||
<div class="text-lg text-light-60 dark:text-dark-60">Cette page est impossible à traiter</div>
|
||||
</div>
|
||||
</div>
|
||||
<template #fallback><div class="loading w-[550px] h-[450px]"></div></template>
|
||||
</Suspense>
|
||||
</template>
|
||||
<template #default><slot name="default"></slot></template>
|
||||
|
|
|
|||
|
|
@ -1,7 +1,8 @@
|
|||
<template>
|
||||
<HoverPopup class="mw-[400px]" @before-show="fetch">
|
||||
<HoverPopup @before-show="fetch">
|
||||
<template #content>
|
||||
<Suspense>
|
||||
<Suspense suspensible>
|
||||
<div class="mw-[400px]">
|
||||
<div v-if="fetched === false" class="loading w-[400px] h-[150px]"></div>
|
||||
<template v-else-if="!!data">
|
||||
<div v-if="data.description" class="pb-4 pt-3 px-8">
|
||||
|
|
@ -17,6 +18,8 @@
|
|||
<div class="text-3xl font-extralight tracking-wide text-light-60 dark:text-dark-60">Impossible d'afficher</div>
|
||||
<div class="text-lg text-light-60 dark:text-dark-60">Cette page est impossible à traiter</div>
|
||||
</div>
|
||||
</div>
|
||||
<template #fallback><div class="loading w-[400px] h-[150px]"></div></template>
|
||||
</Suspense>
|
||||
</template>
|
||||
<template #default>
|
||||
|
|
|
|||
|
|
@ -0,0 +1,41 @@
|
|||
<template>
|
||||
<Teleport to="#teleports" v-if="visible">
|
||||
<div @click.self="() => !focused && hide()" class="z-[100] absolute top-0 bottom-0 left-0 right-0 bg-light-0 dark:bg-dark-0 !bg-opacity-80 flex justify-center items-center">
|
||||
<div class="relative border border-light-35 dark:border-dark-35 bg-light-0 dark:bg-dark-0 min-h-40 min-w-72">
|
||||
<span v-if="closeIcon" class="cursor-pointer absolute top-1 right-1 flex hover:opacity-75" @click="() => hide()"><Icon :width="20" :height="20" icon="icons/close" /></span>
|
||||
<div class="p-6" :class="$attrs.class">
|
||||
<slot></slot>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</Teleport>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
const props = defineProps({
|
||||
focused: {
|
||||
type: Boolean,
|
||||
defualt: false,
|
||||
},
|
||||
closeIcon: {
|
||||
type: Boolean,
|
||||
default: true,
|
||||
}
|
||||
})
|
||||
|
||||
const emit = defineEmits(['show', 'hide']);
|
||||
const visible = ref(false);
|
||||
|
||||
function show()
|
||||
{
|
||||
visible.value = true;
|
||||
emit('show');
|
||||
}
|
||||
function hide()
|
||||
{
|
||||
visible.value = false;
|
||||
emit('hide');
|
||||
}
|
||||
|
||||
defineExpose({hide, show});
|
||||
</script>
|
||||
|
|
@ -1,11 +1,11 @@
|
|||
<template>
|
||||
<Teleport to="#teleports">
|
||||
<div v-show="display" :class="$attrs.class" class="absolute border-2 border-light-35 dark:border-dark-35 max-w-[550px] max-h-[450px] bg-light-0 dark:bg-dark-0 text-light-100 dark:text-dark-100" :style="pos"
|
||||
<Teleport to="#teleports" v-if="display">
|
||||
<div class="absolute border-2 border-light-35 dark:border-dark-35 max-w-[550px] max-h-[450px] bg-light-0 dark:bg-dark-0 text-light-100 dark:text-dark-100 overflow-hidden" :style="pos"
|
||||
@mouseenter="debounce(show, 250)" @mouseleave="debounce(() => { emit('beforeHide'); display = false }, 250)">
|
||||
<slot name="content"></slot>
|
||||
</div>
|
||||
</Teleport>
|
||||
<span ref="el" @mouseenter="debounce(show, 250)" @mouseleave="debounce(() => { emit('beforeHide'); display = false }, 250)">
|
||||
<span ref="el" :class="$attrs.class" @mouseenter="debounce(show, 250)" @mouseleave="debounce(() => { emit('beforeHide'); display = false }, 250)">
|
||||
<slot name="default"></slot>
|
||||
</span>
|
||||
</template>
|
||||
|
|
|
|||
|
|
@ -13,11 +13,9 @@ watchEffect(() => err.value = props.error);
|
|||
</script>
|
||||
|
||||
<template>
|
||||
<template></template>
|
||||
<div class="m-1">
|
||||
<div class="m-1 flex justify-between items-center gap-8">
|
||||
<label v-if="title" class="pe-4">{{ title }}</label>
|
||||
<Input @input="err = false" :class="{ 'input-has-error': !!err }" v-model="model"
|
||||
v-bind="$attrs" />
|
||||
<span v-if="err && typeof err === 'string'" class="text-light-red dark:text-dark-red block pb-2">{{ err }}</span>
|
||||
<Input class="flex-1" @input="err = false" :class="{ 'input-has-error': !!err }" v-model="model" v-bind="$attrs" />
|
||||
</div>
|
||||
<span v-if="err && typeof err === 'string'" class="text-light-red dark:text-dark-red block pb-2">{{ err }}</span>
|
||||
</template>
|
||||
|
|
@ -58,10 +58,9 @@ onUnmounted(() => {
|
|||
<ThemeSwitch />
|
||||
<NuxtLink @click="hideNavigation" class="" :to="{ path: '/user/profile', force: true }"><div class=" hover:border-opacity-70 flex border p-px border-light-70 dark:border-dark-70">
|
||||
<Icon v-if="!loggedIn" icon="icons/user-login" :width=28 :height=28 />
|
||||
<picture v-else :width=28 :height=28 class="flex" >
|
||||
<source :src="`/users/${user?.id}/small.jpg`" :width=28 :height=28 />
|
||||
<Icon :icon="`users/unknown`" :width=28 :height=28 ></Icon>
|
||||
</picture>
|
||||
<Picture v-else :src="`/users/${user?.id}/small.jpg`" :width=28 :height=28 class="flex" >
|
||||
<Icon :icon="`icons/unknown`" :width=28 :height=28 ></Icon>
|
||||
</Picture>
|
||||
</div></NuxtLink>
|
||||
</div>
|
||||
</div>
|
||||
|
|
|
|||
|
|
@ -0,0 +1,31 @@
|
|||
<template>
|
||||
<span>
|
||||
<img v-show="src && !fallback" @load="hideFallback" @error="showFallback" :src="src" :width="width" :height="height" />
|
||||
<span v-show="!src || fallback"><slot></slot></span>
|
||||
</span>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
const props = defineProps({
|
||||
src: {
|
||||
type: String,
|
||||
},
|
||||
width: {
|
||||
type: Number,
|
||||
},
|
||||
height: {
|
||||
type: Number,
|
||||
}
|
||||
});
|
||||
|
||||
const fallback = ref(false);
|
||||
|
||||
const showFallback = () => toggleFallback(true);
|
||||
const hideFallback = () => toggleFallback(false);
|
||||
|
||||
function toggleFallback(toggle: boolean): void
|
||||
{
|
||||
console.log("Something happened")
|
||||
fallback.value = toggle;
|
||||
}
|
||||
</script>
|
||||
|
|
@ -0,0 +1,27 @@
|
|||
<template>
|
||||
<label>
|
||||
<slot></slot>
|
||||
<input ref="input" :accept="accept" :multiple="multiple" type="file" class="hidden" @change.self="(e) => files = [...(e.target as HTMLInputElement)?.files ?? []]"/>
|
||||
</label>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
const props = defineProps({
|
||||
accept: {
|
||||
type: String,
|
||||
},
|
||||
multiple: {
|
||||
type: Boolean,
|
||||
default: false,
|
||||
}
|
||||
});
|
||||
|
||||
const input = useTemplateRef('input');
|
||||
const files = ref<File[]>([]);
|
||||
|
||||
watch([files], () => emit('change', files.value));
|
||||
|
||||
const emit = defineEmits(['change']);
|
||||
|
||||
defineExpose({ files });
|
||||
</script>
|
||||
|
|
@ -23,11 +23,12 @@ export default defineNuxtModule({
|
|||
|
||||
const template = new Database(nuxt.options.runtimeConfig.templateFile);
|
||||
const schema = template.query(`SELECT * FROM sqlite_schema WHERE type = 'table'`).all() as Schema[];
|
||||
const structure = template.query(`SELECT * FROM pragma_table_info(?1)`);
|
||||
|
||||
const db = new Database(nuxt.options.runtimeConfig.dbFile);
|
||||
db.exec(`PRAGMA foreign_keys = 0`);
|
||||
db.exec(`PRAGMA foreign_keys = OFF; PRAGMA defer_foreign_keys = OFF;`);
|
||||
const oldSchema = db.query(`SELECT * FROM sqlite_schema WHERE type = 'table'`).all() as Schema[];
|
||||
const structure = db.query(`SELECT * FROM pragma_table_info(?1)`);
|
||||
const oldStructure = db.query(`SELECT * FROM pragma_table_info(?1)`);
|
||||
|
||||
(db.transaction((tables: Schema[], oldTables: Schema[]) => {
|
||||
for(const table of tables)
|
||||
|
|
@ -41,15 +42,18 @@ export default defineNuxtModule({
|
|||
}
|
||||
|
||||
const columns = structure.all(table.name) as Structure[];
|
||||
const oldColumns = oldStructure.all(table.name) as Structure[];
|
||||
|
||||
if(oldIdx !== -1)
|
||||
{
|
||||
oldTables.splice(oldIdx, 1);
|
||||
|
||||
db.exec(`ALTER TABLE ${table.name} RENAME TO ${table.name}_old`);
|
||||
db.exec(table.sql);
|
||||
db.exec(`INSERT INTO ${table.name} (${columns.map(e => `"${e.name}"`).join(', ')}) SELECT * FROM ${table.name}_old`);
|
||||
db.exec(`DROP TABLE ${table.name}_old`);
|
||||
const filteredColumns = oldColumns.filter(e => columns.find(f => e.name === f.name)).map(e => `"${e.name}"`).join(', ')
|
||||
|
||||
db.exec(table.sql.replace(`CREATE TABLE "${table.name}"`, `CREATE TABLE "${table.name}_new"`));
|
||||
db.exec(`INSERT INTO ${table.name}_new (${filteredColumns}) SELECT ${filteredColumns} FROM ${table.name}`);
|
||||
db.exec(`DROP TABLE ${table.name}`);
|
||||
db.exec(`ALTER TABLE ${table.name}_new RENAME TO ${table.name}`);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
|
@ -62,7 +66,7 @@ export default defineNuxtModule({
|
|||
}
|
||||
})).immediate(schema, oldSchema);
|
||||
|
||||
db.exec(`PRAGMA foreign_keys = 1`);
|
||||
db.exec(`PRAGMA foreign_keys = ON; PRAGMA foreign_keys = ON;`);
|
||||
|
||||
db.close();
|
||||
template.close();
|
||||
|
|
|
|||
|
|
@ -99,7 +99,12 @@ export default defineNuxtConfig({
|
|||
}
|
||||
},
|
||||
security: {
|
||||
rateLimiter: false
|
||||
rateLimiter: false,
|
||||
headers: {
|
||||
contentSecurityPolicy: {
|
||||
"img-src": "'self' data: blob:"
|
||||
}
|
||||
}
|
||||
},
|
||||
compatibilityDate: '2024-07-25',
|
||||
})
|
||||
|
|
@ -78,16 +78,16 @@ function handleErrors(error: Error | ZodError)
|
|||
</Head>
|
||||
<div class="flex flex-1 justify-center items-center">
|
||||
<div class="p-8 w-[48em] border border-light-35 dark:border-dark-35">
|
||||
<form @submit.prevent="submit" class="p-4 bg-light-25 dark:bg-dark-30">
|
||||
<form @submit.prevent="submit" class="p-4 bg-light-20 dark:bg-dark-20">
|
||||
<h1 class="text-2xl font-bold tracking-wider pb-4">Connexion</h1>
|
||||
<InputField type="text" autocomplete="username" v-model="state.usernameOrEmail"
|
||||
placeholder="" title="Nom d'utilisateur ou adresse mail" :error="usernameError" class="w-[24em]" />
|
||||
placeholder="" title="Nom d'utilisateur ou adresse mail" :error="usernameError"/>
|
||||
<InputField type="password" autocomplete="current-password" v-model="state.password"
|
||||
placeholder="" title="Mot de passe"
|
||||
:error="passwordError" class="w-[24em]"/>
|
||||
<span v-if="generalError" class="text-light-red dark:text-dark-red">{{ generalError }}</span>
|
||||
<button class="m-auto block px-4 py-1 bg-light-20 dark:bg-dark-20 border border-light-40 dark:border-dark-40 hover:border-light-50 dark:hover:border-dark-50 active:relative active:top-[1px]">
|
||||
<div class="loading" v-if="status === 'pending'"></div>
|
||||
<div class="loading before:w-6 before:h-6" v-if="status === 'pending'"></div>
|
||||
<template v-else>Se connecter</template>
|
||||
</button>
|
||||
<NuxtLink class="mt-4 text-center block text-sm font-semibold tracking-wide hover:italic" :to="{ path: `/user/register`, force: true }">Pas de compte ?</NuxtLink>
|
||||
|
|
|
|||
|
|
@ -4,15 +4,88 @@ definePageMeta({
|
|||
});
|
||||
|
||||
const { user, clear } = useUserSession();
|
||||
const { data: projects } = useFetch(`/api/users/${user.value?.id}/projects`);
|
||||
const { data: comments } = useFetch(`/api/users/${user.value?.id}/comments`);
|
||||
|
||||
const dialog = useTemplateRef('dialog');
|
||||
const files = ref<File[]>([]), imgURL = ref<string |null>(null);
|
||||
|
||||
const posX = ref(0), posY = ref(0), sizeX = ref(128), sizeY = ref(128);
|
||||
|
||||
async function loadImage(f: File[])
|
||||
{
|
||||
files.value = f;
|
||||
if(f.length > 0)
|
||||
imgURL.value = URL.createObjectURL(f[0]);
|
||||
}
|
||||
async function approveThumbnail()
|
||||
{
|
||||
|
||||
}
|
||||
const dragHandler = ({ delta: [x, y] }: { delta: number[] }) => {
|
||||
posX.value = clamp(posX.value + x, 0, 256 - sizeX.value);
|
||||
posY.value = clamp(posY.value + y, 0, 256 - sizeY.value);
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<Head>
|
||||
<Title>Votre profil</Title>
|
||||
</Head>
|
||||
<div class="flex-1 flex justify-center items-center flex-col">
|
||||
<ThemeIcon icon="logo" :width=128 :height=128 />
|
||||
<div class="not-found-title">Bonjour {{ user?.username }} :)</div>
|
||||
<button class="m-auto block px-4 py-1 bg-light-20 dark:bg-dark-20 border border-light-40 dark:border-dark-40 hover:border-light-50 dark:hover:border-dark-50 active:relative active:top-[1px]" @click="clear">Se deconnecter</button>
|
||||
<div v-if="user" class="flex-1 grid gap-4 grid-cols-3">
|
||||
<div class="border border-light-35 dark:border-dark-35 p-4 flex gap-4 col-span-2">
|
||||
<Picture @click="() => dialog?.show()" :src="`/users/${user?.id}/normal.jpg`" :width=128 :height=128 class="inline-block hover:bg-light-70 hover:bg-opacity-50 hover:opacity-50 transition-all cursor-pointer">
|
||||
<Icon :icon="`icons/unknown`" :width=128 :height=128></Icon>
|
||||
</Picture>
|
||||
<Dialog :close-icon="true" :focused="false" ref="dialog">
|
||||
<div class="w-[640px] h-[320px] flex justify-center">
|
||||
<div class="w-[256px] h-[256px] relative">
|
||||
<Picture :src="imgURL ?? undefined" :width=256 :height=256 class="inline-block select-none">
|
||||
<Icon :icon="`icons/unknown`" :width=256 :height=256></Icon>
|
||||
</Picture>
|
||||
<div v-if="imgURL" class="border-2 border-dashed border-light-50 dark:border-dark-50 absolute cursor-move" :style="{
|
||||
top: `${posY}px`,
|
||||
left: `${posX}px`,
|
||||
width: `${sizeX}px`,
|
||||
height: `${sizeX}px`,
|
||||
}" v-drag="dragHandler">
|
||||
<span class=""></span>
|
||||
<span class=""></span>
|
||||
<span class=""></span>
|
||||
<span class=""></span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="border-t border-light-35 dark:border-dark-35 absolute bottom-0 left-0 right-0 p-4 flex justify-between">
|
||||
<div class="flex gap-3">
|
||||
<Upload accept="image/png,image/jpeg,image/webp" @change="loadImage">
|
||||
<span class="py-1 px-2 cursor-pointer text-light-100 dark:text-dark-100 transition-all duration-200 mb-4 border border-light-35 dark:border-dark-35 bg-light-20 dark:bg-dark-20 hover:border-light-50 dark:hover:border-dark-50 hover:bg-light-30 dark:hover:bg-dark-30">Importer un fichier</span>
|
||||
</Upload>
|
||||
<span class="text-sm text-light-60 dark:text-dark-60 italic">5 Mo max. 128 x 128 min recommandé.</span>
|
||||
</div>
|
||||
<div>
|
||||
<span @click="approveThumbnail" class="py-1 px-2 cursor-pointer text-light-100 dark:text-dark-100 transition-all duration-200 mb-4 border border-light-35 dark:border-dark-35 bg-light-20 dark:bg-dark-20 hover:border-light-50 dark:hover:border-dark-50 hover:bg-light-30 dark:hover:bg-dark-30">Valider</span>
|
||||
</div>
|
||||
</div>
|
||||
</Dialog>
|
||||
<div class="flex flex-col">
|
||||
<span class="text-xl font-semibold">{{ user?.username }}</span>
|
||||
<span>Inscrit depuis le {{ format(new Date(user.signin_timestamp), 'dd/MM/yyyy') }}</span>
|
||||
</div>
|
||||
</div>
|
||||
<div class="p-4 flex gap-4 flex-col">
|
||||
<button @click="clear()" class="py-1 transition-all duration-200 mb-4 border border-light-35 dark:border-dark-35 bg-light-20 dark:bg-dark-20 hover:border-light-50 dark:hover:border-dark-50 hover:bg-light-30 dark:hover:bg-dark-30">Se déconnecter</button>
|
||||
<button @click="" class="py-1 transition-all duration-200 border border-light-35 dark:border-dark-35 bg-light-20 dark:bg-dark-20 hover:border-light-50 dark:hover:border-dark-50 hover:bg-light-30 dark:hover:bg-dark-30">Mettre à jour le profil</button>
|
||||
<button @click="" class="py-1 transition-all duration-200 border border-light-35 dark:border-dark-35 bg-light-20 dark:bg-dark-20 hover:border-light-red dark:hover:border-dark-red hover:bg-light-30 dark:hover:bg-dark-30 text-light-red dark:text-dark-red">Supprimer le compte</button>
|
||||
</div>
|
||||
<div class="border border-light-35 dark:border-dark-35 p-4 flex flex-col">
|
||||
<div class="text-2xl">Mes projets</div>
|
||||
<div class="flex flex-col">
|
||||
<div v-for="project of projects" class="flex justify-between items-center py-1">
|
||||
<NuxtLink :to="{ path: `/explorer/${project.id}/${project.home}`, force: true }" class="text-accent-blue font-bold cursor-pointer hover:text-opacity-80 text-lg">{{ project.name }}</NuxtLink>
|
||||
<span>{{ project.pages }} pages</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
|
@ -87,15 +87,15 @@ function handleErrors(error: Error | ZodError)
|
|||
</Head>
|
||||
<div class="flex flex-1 justify-center items-center">
|
||||
<div class="p-8 w-[48em] border border-light-35 dark:border-dark-35">
|
||||
<form @submit.prevent="submit" class="p-4 bg-light-25 dark:bg-dark-30">
|
||||
<form @submit.prevent="submit" class="p-4 bg-light-20 dark:bg-dark-20">
|
||||
<h1 class="text-2xl font-bold tracking-wider pb-4">Inscription</h1>
|
||||
<InputField type="text" autocomplete="username" v-model="state.username"
|
||||
placeholder="Entrez un nom d'utilisateur" title="Nom d'utilisateur" :error="usernameError" class="w-[24em]"/>
|
||||
placeholder="Entrez un nom d'utilisateur" title="Nom d'utilisateur" :error="usernameError"/>
|
||||
<InputField type="text" autocomplete="email" v-model="state.email" placeholder="Entrez une addresse mail"
|
||||
title="Adresse mail" :error="emailError" class="w-[24em]"/>
|
||||
title="Adresse mail" :error="emailError"/>
|
||||
<InputField type="password" autocomplete="new-password" v-model="state.password"
|
||||
placeholder="Entrez un mot de passe" title="Mot de passe"
|
||||
:error="!(checkedLength && checkedLowerUpper && checkedDigit && checkedSymbol)" class="w-[24em]"/>
|
||||
:error="!(checkedLength && checkedLowerUpper && checkedDigit && checkedSymbol)"/>
|
||||
<div class="flex flex-col font-light">
|
||||
<span class="">Votre mot de passe doit respecter les critères de sécurité suivants
|
||||
:</span>
|
||||
|
|
@ -110,12 +110,13 @@ function handleErrors(error: Error | ZodError)
|
|||
<pre>! " # $ % & ' ( ) * + , - . / : ; < = > ? @ [ ] ^ _ ` { | } ~</pre>
|
||||
</span>
|
||||
</div>
|
||||
<InputField type="password" v-model="confirmPassword" placeholder="Confirmer le mot de passe"
|
||||
title="Confirmer le mot de passe"
|
||||
autocomplete="new-password"
|
||||
:error="confirmPassword === '' || confirmPassword === state.password ? '' : 'Les mots de passe saisies ne sont pas identique'" class="w-[24em]"/>
|
||||
<InputField type="password" v-model="confirmPassword" placeholder="Confirmer le mot de passe" title="Confirmer le mot de passe" autocomplete="new-password"
|
||||
:error="confirmPassword === '' || confirmPassword === state.password ? '' : 'Les mots de passe saisies ne sont pas identique'"/>
|
||||
<span v-if="generalError" class="text-light-red dark:text-dark-red">{{ generalError }}</span>
|
||||
<button class="m-auto block px-4 py-1 bg-light-20 dark:bg-dark-20 border border-light-40 dark:border-dark-40 hover:border-light-50 dark:hover:border-dark-50 active:relative active:top-[1px]"><div v-if="status === 'pending'" class="loading"></div><template v-else>S'inscrire</template></button>
|
||||
<button class="m-auto block px-4 py-1 bg-light-20 dark:bg-dark-20 border border-light-40 dark:border-dark-40 hover:border-light-50 dark:hover:border-dark-50 active:relative active:top-[1px]">
|
||||
<div v-if="status === 'pending'" class="loading"></div>
|
||||
<template v-else>S'inscrire</template>
|
||||
</button>
|
||||
<NuxtLink class="mt-4 text-center block text-sm font-semibold tracking-wide hover:italic" :to="{ path: `/user/login`, force: true }">Vous avez déjà un compte ? Se connecter</NuxtLink>
|
||||
</form>
|
||||
</div>
|
||||
|
|
|
|||
|
|
@ -7,9 +7,9 @@ const { data: comments } = useFetch(`/api/users/${route.params.id}/comments`);
|
|||
|
||||
<template>
|
||||
<Head>
|
||||
<Title>Inconnu</Title>
|
||||
<Title>{{ user?.username ?? "Inconnu" }}</Title>
|
||||
</Head>
|
||||
<div v-if="user" class="border border-light-35 dark:border-dark-35 p-4 flex">
|
||||
<div v-if="user" class="border border-light-35 dark:border-dark-35 p-4 flex gap-4">
|
||||
<div>
|
||||
<picture :width=128 :height=128 class="flex" >
|
||||
<source :src="`/users/${user?.id}/normal.jpg`" :width=128 :height=128 />
|
||||
|
|
|
|||
|
|
@ -0,0 +1,3 @@
|
|||
<svg xmlns="http://www.w3.org/2000/svg" width="1em" height="1em" viewBox="0 0 256 256">
|
||||
<path fill="currentColor" d="M204.24 195.76a6 6 0 1 1-8.48 8.48L128 136.49l-67.76 67.75a6 6 0 0 1-8.48-8.48L119.51 128L51.76 60.24a6 6 0 0 1 8.48-8.48L128 119.51l67.76-67.75a6 6 0 0 1 8.48 8.48L136.49 128Z" />
|
||||
</svg>
|
||||
|
After Width: | Height: | Size: 306 B |
|
Before Width: | Height: | Size: 362 B After Width: | Height: | Size: 362 B |
|
|
@ -63,10 +63,10 @@ export default defineEventHandler(async (e): Promise<Return> => {
|
|||
return { success: false, error: new ZodError([{ code: 'custom', path: ['password'], message: 'Mot de passe incorrect' }]) };
|
||||
}
|
||||
|
||||
logSession(e, await setUserSession(e, { user: getData(db, id.id) }) as UserSessionRequired);
|
||||
const data = await logSession(e, await setUserSession(e, { user: getData(db, id.id) }) as UserSessionRequired);
|
||||
|
||||
setResponseStatus(e, 201);
|
||||
return { success: true, session };
|
||||
return { success: true, session: data };
|
||||
}
|
||||
catch(err: any)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
import useDatabase from "~/composables/useDatabase";
|
||||
import type { Comment } from "~/types/auth";
|
||||
import type { CommentSearch } from "~/types/api";
|
||||
|
||||
export default defineEventHandler((e) => {
|
||||
const id = getRouterParam(e, 'id');
|
||||
|
|
@ -12,5 +12,5 @@ export default defineEventHandler((e) => {
|
|||
|
||||
const db = useDatabase();
|
||||
|
||||
return db.query(`SELECT * FROM explorer_comments WHERE user_id = ?1`).all(id) as Comment[];
|
||||
return db.query(`SELECT * FROM explorer_comments WHERE user_id = ?1`).all(id) as CommentSearch[];
|
||||
});
|
||||
|
|
@ -1,5 +1,5 @@
|
|||
import useDatabase from "~/composables/useDatabase";
|
||||
import type { Project } from "~/types/api";
|
||||
import type { ProjectSearch } from "~/types/api";
|
||||
|
||||
export default defineEventHandler((e) => {
|
||||
const id = getRouterParam(e, 'id');
|
||||
|
|
@ -12,5 +12,5 @@ export default defineEventHandler((e) => {
|
|||
|
||||
const db = useDatabase();
|
||||
|
||||
return db.query(`SELECT * FROM explorer_projects WHERE owner = ?1`).all(id) as Project[];
|
||||
return db.query(`SELECT p.*, count(f.path) as pages FROM explorer_projects p LEFT JOIN explorer_files f ON p.id = f.project WHERE p.owner = ?1`).all(id) as Omit<ProjectSearch, 'username'>[];
|
||||
});
|
||||
|
|
@ -1,27 +1,27 @@
|
|||
import useDatabase from "~/composables/useDatabase";
|
||||
|
||||
const monthAsMs = 1000 * 60 * 60 * 24 * 30;
|
||||
const monthAsMs = 60 * 60 * 24 * 30;
|
||||
|
||||
export default defineNitroPlugin(() => {
|
||||
const db = useDatabase();
|
||||
|
||||
sessionHooks.hook('fetch', async (session, event) => {
|
||||
const query = db.prepare('SELECT lastRefresh FROM user_sessions WHERE id = ?1 AND user_id = ?2');
|
||||
const result = query.get(session.id, session.user.id) as Record<string, any>;
|
||||
const query = db.prepare('SELECT last_refresh FROM user_sessions WHERE id = ?1 AND user_id = ?2');
|
||||
const result = query.get(session.id, session.user.id) as { last_refresh: number };
|
||||
|
||||
if(!result)
|
||||
{
|
||||
clearUserSession(event);
|
||||
throw createError({ statusCode: 401, message: 'Unauthorized' });
|
||||
}
|
||||
else if(result && result.lastRefresh && result.lastRefresh < Date.now() - monthAsMs)
|
||||
else if(result && result.last_refresh && result.last_refresh < Date.now() - monthAsMs)
|
||||
{
|
||||
clearUserSession(event);
|
||||
throw createError({ statusCode: 401, message: 'Session has expired' });
|
||||
}
|
||||
else
|
||||
{
|
||||
db.prepare('UPDATE user_sessions SET lastRefresh = ?1 WHERE id = ?2 AND user_id = ?3').run(Date.now(), session.id, session.user.id);
|
||||
db.prepare('UPDATE user_sessions SET last_refresh = ?1 WHERE id = ?2 AND user_id = ?3').run(Date.now(), session.id, session.user.id);
|
||||
}
|
||||
});
|
||||
sessionHooks.hook('clear', async (session, event) => {
|
||||
|
|
|
|||
|
|
@ -24,10 +24,12 @@ export async function checkSession(e: H3Event<EventRequestHandler>, session: Use
|
|||
}
|
||||
}
|
||||
}
|
||||
export async function logSession(e: H3Event<EventRequestHandler>, session: UserSessionRequired)
|
||||
export async function logSession(e: H3Event<EventRequestHandler>, session: UserSessionRequired): Promise<UserSessionRequired>
|
||||
{
|
||||
const db = useDatabase();
|
||||
|
||||
const loggingIn = db.query(`INSERT INTO user_sessions(id, user_id, ip, agent, lastRefresh) VALUES(?1, ?2, ?3, ?4, ?5)`);
|
||||
const loggingIn = db.query(`INSERT INTO user_sessions(id, user_id, ip, agent, last_refresh) VALUES(?1, ?2, ?3, ?4, ?5)`);
|
||||
loggingIn.get(session.id, session.user.id, getRequestIP(e) ?? null, getRequestHeader(e, 'User-Agent') ?? null, Date.now());
|
||||
|
||||
return session;
|
||||
}
|
||||
BIN
template.sqlite
BIN
template.sqlite
Binary file not shown.
|
|
@ -33,3 +33,10 @@ export function format(date: Date, template: string): string
|
|||
|
||||
return template;
|
||||
}
|
||||
export function clamp(x: number, min: number, max: number): number {
|
||||
if (x > max)
|
||||
return max;
|
||||
if (x < min)
|
||||
return min;
|
||||
return x;
|
||||
}
|
||||
Loading…
Reference in New Issue