@open-commune/web 0.2.13 → 0.2.15
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/app.config.ts +13 -0
- package/assets/css/main.css +119 -0
- package/components/data/lists/data-table.vue +203 -0
- package/components/data/lists/row-actions.vue +41 -0
- package/components/elements/badges/status-badge.vue +23 -0
- package/components/elements/media/media-image.vue +26 -0
- package/components/forms/fields/input-files-media.vue +87 -0
- package/components/forms/{inputs → fields}/input-filter-status.vue +2 -2
- package/components/forms/{inputs → fields}/input-search.vue +8 -2
- package/components/forms/fields/input-text-area.vue +86 -0
- package/components/forms/fields/input-text.vue +47 -0
- package/components/forms/fields/select-enum.vue +69 -0
- package/components/forms/handlers/handler-collections.vue +100 -170
- package/components/forms/handlers/handler-list.vue +187 -0
- package/components/forms/handlers/handler-members.vue +171 -0
- package/components/forms/handlers/handler-password-reset.vue +45 -0
- package/components/forms/handlers/handler-roles.vue +28 -166
- package/components/forms/handlers/handler-sessions.vue +77 -0
- package/components/forms/handlers/handler-tokens.vue +54 -69
- package/components/forms/layouts/form-default.vue +99 -0
- package/components/forms/layouts/form.vue +4 -0
- package/components/forms/layouts/forms-layout.vue +236 -0
- package/components/forms/layouts/forms-section.vue +186 -0
- package/components/forms/layouts/layout.vue +4 -0
- package/components/forms/layouts/modal.vue +4 -0
- package/components/forms/layouts/section.vue +4 -0
- package/components/layout/entrance-mark.vue +18 -0
- package/components/layout/navigations/primary/dropdown-publish.vue +6 -4
- package/components/layout/shell/shell-account-menu.vue +63 -0
- package/components/layout/shell/shell-header.vue +99 -0
- package/composables/core/domains/use-api-tokens.ts +80 -0
- package/composables/core/domains/use-auth.ts +162 -0
- package/composables/core/domains/use-definitions.ts +18 -5
- package/composables/core/domains/use-entries.ts +113 -3
- package/composables/core/domains/use-media.ts +24 -1
- package/composables/core/domains/use-members.ts +68 -0
- package/composables/core/domains/use-organization.ts +53 -0
- package/composables/use-models.js +1 -9
- package/constants/errors.ts +28 -0
- package/constants/forms/account.ts +62 -0
- package/constants/forms/collections.ts +39 -0
- package/constants/forms/members.ts +40 -0
- package/constants/forms/organization.ts +188 -0
- package/constants/forms/tokens.ts +15 -0
- package/constants/roles.ts +57 -0
- package/constants/settings.ts +26 -0
- package/constants/statuses.ts +8 -5
- package/layouts/default.vue +1 -2
- package/layouts/entrance.vue +1 -6
- package/layouts/record.vue +1 -2
- package/middleware/00.light-mode.global.ts +8 -0
- package/nuxt.config.ts +8 -0
- package/package.json +5 -3
- package/pages/[collection]/index.vue +92 -79
- package/pages/account.vue +40 -0
- package/pages/index/index.vue +54 -62
- package/pages/index/password/define/[token].vue +44 -68
- package/pages/index/password/recover/index.vue +43 -54
- package/pages/index/welcome/[token].vue +42 -79
- package/pages/index.vue +6 -37
- package/pages/settings.vue +26 -181
- package/plugins/00.appearance.client.ts +7 -0
- package/plugins/01.validation.client.ts +23 -0
- package/store/layout/workspace.js +4 -28
- package/utils/colors.ts +26 -0
- package/utils/errors.ts +13 -0
- package/utils/forms.ts +67 -0
- package/utils/list-columns.ts +90 -0
- package/utils/settings.ts +38 -0
- package/utils/statuses.ts +4 -0
- package/components/layout/navigations/primary.vue +0 -132
- package/models/entrance.js +0 -42
- package/models/role.js +0 -66
- package/models/token.js +0 -56
- package/models/user.js +0 -97
- package/pages/management/index.vue +0 -15
- package/pages/management/members.vue +0 -176
- package/pages/management/organizations.vue +0 -192
- package/pages/management/roles.vue +0 -183
- package/public/logo-black.svg +0 -1
- package/public/logo-white.svg +0 -1
- /package/components/forms/{inputs → fields}/input-filter.vue +0 -0
|
@@ -1,34 +1,43 @@
|
|
|
1
1
|
<template>
|
|
2
|
-
<section class="w-full">
|
|
2
|
+
<section v-if="isPending" class="w-full">
|
|
3
|
+
<div class="mb-4 flex flex-wrap items-center gap-2">
|
|
4
|
+
<USkeleton class="h-9 w-44 rounded-md" />
|
|
5
|
+
<USkeleton class="h-9 w-28 rounded-md" />
|
|
6
|
+
<USkeleton class="ml-auto size-9 rounded-md" />
|
|
7
|
+
</div>
|
|
8
|
+
<div class="space-y-2">
|
|
9
|
+
<USkeleton v-for="i in 5" :key="i" class="h-16 rounded-lg" />
|
|
10
|
+
</div>
|
|
11
|
+
</section>
|
|
12
|
+
|
|
13
|
+
<section v-else class="w-full">
|
|
3
14
|
<!-- Both controls narrow on the SERVER: a collection of several hundred
|
|
4
15
|
entries does not fit in the browser, and narrowing what is loaded only
|
|
5
16
|
ever finds what is already visible. -->
|
|
6
|
-
<div
|
|
17
|
+
<div class="mb-4 flex flex-wrap items-center gap-2">
|
|
7
18
|
<input-filter
|
|
8
|
-
v-if="
|
|
19
|
+
v-if="collection?.name"
|
|
9
20
|
label="Collection"
|
|
10
|
-
:value="
|
|
21
|
+
:value="collection.name"
|
|
11
22
|
disabled
|
|
12
23
|
/>
|
|
13
|
-
<input-filter-status v-model="
|
|
14
|
-
<input-search v-model="search" class="ml-auto" />
|
|
24
|
+
<input-filter-status v-model="filters.status" />
|
|
25
|
+
<input-search v-model="filters.search" class="ml-auto" />
|
|
15
26
|
</div>
|
|
16
27
|
|
|
17
|
-
<
|
|
18
|
-
v-if="
|
|
19
|
-
:key="narrowingKey"
|
|
20
|
-
:headers="headers"
|
|
28
|
+
<data-table
|
|
29
|
+
v-if="records.length"
|
|
21
30
|
:items="records"
|
|
22
|
-
|
|
23
|
-
:
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
@update="
|
|
27
|
-
@remove="
|
|
31
|
+
v-bind="listingKeys"
|
|
32
|
+
:actions="ACTIONS"
|
|
33
|
+
:loading="isFetching"
|
|
34
|
+
:on-select="_onRowSelect"
|
|
35
|
+
@update="_open"
|
|
36
|
+
@remove="_remove"
|
|
28
37
|
/>
|
|
29
38
|
|
|
30
39
|
<UEmpty
|
|
31
|
-
v-else
|
|
40
|
+
v-else
|
|
32
41
|
icon="i-lucide-inbox"
|
|
33
42
|
:title="narrowed ? 'Aucun résultat' : 'Aucune entrée'"
|
|
34
43
|
:description="narrowed
|
|
@@ -36,89 +45,93 @@
|
|
|
36
45
|
: 'Cette collection est vide pour le moment.'"
|
|
37
46
|
/>
|
|
38
47
|
|
|
39
|
-
<
|
|
40
|
-
|
|
41
|
-
|
|
48
|
+
<div v-if="records.length" class="mt-6 flex items-center justify-center gap-4">
|
|
49
|
+
<p class="text-sm text-dimmed">
|
|
50
|
+
{{ records.length }} affichée{{ records.length > 1 ? 's' : '' }} sur {{ total }}
|
|
51
|
+
</p>
|
|
52
|
+
<UButton
|
|
53
|
+
v-if="hasNextPage"
|
|
54
|
+
color="neutral"
|
|
55
|
+
variant="outline"
|
|
56
|
+
class="px-4"
|
|
57
|
+
label="Afficher plus"
|
|
58
|
+
:loading="isFetchingNextPage"
|
|
59
|
+
@click="fetchNextPage()"
|
|
60
|
+
/>
|
|
61
|
+
</div>
|
|
42
62
|
</section>
|
|
43
63
|
</template>
|
|
44
64
|
|
|
45
65
|
<script setup>
|
|
46
|
-
import
|
|
47
|
-
import inputFilter from '~/components/forms/
|
|
48
|
-
import inputFilterStatus from '~/components/forms/
|
|
49
|
-
import inputSearch from '~/components/forms/
|
|
50
|
-
import { ALL_STATUSES } from '
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
66
|
+
import dataTable from '~/components/data/lists/data-table'
|
|
67
|
+
import inputFilter from '~/components/forms/fields/input-filter'
|
|
68
|
+
import inputFilterStatus from '~/components/forms/fields/input-filter-status'
|
|
69
|
+
import inputSearch from '~/components/forms/fields/input-search'
|
|
70
|
+
import { ALL_STATUSES } from '~/constants/statuses'
|
|
71
|
+
import { listingKeysFor } from '~/utils/list-columns'
|
|
72
|
+
|
|
73
|
+
// Prepare constants
|
|
74
|
+
const PAGE_SIZE = 25
|
|
75
|
+
const ACTIONS = ['update', 'remove']
|
|
76
|
+
|
|
77
|
+
// Prepare composables
|
|
54
78
|
const $route = useRoute()
|
|
55
79
|
const $router = useRouter()
|
|
80
|
+
const $definitions = useDefinitions()
|
|
81
|
+
const $entries = useEntries()
|
|
82
|
+
const toast = useToast()
|
|
56
83
|
|
|
57
84
|
// Prepare page meta
|
|
58
85
|
definePageMeta({
|
|
59
|
-
permissions: [
|
|
60
|
-
preFetch: ['Record']
|
|
86
|
+
permissions: ['read:records'] // TODO handle collections
|
|
61
87
|
})
|
|
62
88
|
|
|
63
89
|
// Prepare reactive data
|
|
64
|
-
const
|
|
65
|
-
const search = ref('')
|
|
66
|
-
const statuses = ref([...ALL_STATUSES])
|
|
67
|
-
const total = ref(0)
|
|
90
|
+
const filters = ref({ status: [...ALL_STATUSES], search: '' })
|
|
68
91
|
|
|
69
|
-
//
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
const
|
|
73
|
-
const abilities = computed(() => ['update', 'remove'])
|
|
92
|
+
// Fetch data
|
|
93
|
+
// A getter, not a snapshot: Nuxt REUSES this component from one collection to
|
|
94
|
+
// the next, and a slug read once at setup would name the previous one.
|
|
95
|
+
const { data: collection } = $definitions.get(() => $route.params.collection)
|
|
74
96
|
|
|
97
|
+
/** What narrows the listing, as the server takes it. */
|
|
75
98
|
const narrowing = computed(() => ({
|
|
76
|
-
search: search.
|
|
99
|
+
...(filters.value.search.trim() ? { search: filters.value.search.trim() } : {}),
|
|
77
100
|
// Keeping every status is not a filter: send nothing rather than all five.
|
|
78
|
-
|
|
101
|
+
...(filters.value.status.length === ALL_STATUSES.length ? {} : { status: filters.value.status }),
|
|
79
102
|
}))
|
|
80
103
|
|
|
81
|
-
|
|
82
|
-
|
|
104
|
+
// The listing is DESCRIBED, never fetched by hand: collection and filters are
|
|
105
|
+
// in its key, so it starts over whenever one of them moves, and the slices,
|
|
106
|
+
// the next one and their loading states are TanStack's.
|
|
107
|
+
const { records, total, isPending, isFetching, isFetchingNextPage, hasNextPage, fetchNextPage } = $entries.infinite(
|
|
108
|
+
() => collection.value?.id,
|
|
109
|
+
() => ({ ...narrowing.value, limit: PAGE_SIZE })
|
|
83
110
|
)
|
|
111
|
+
const { mutateAsync: removeEntry } = $entries.remove()
|
|
84
112
|
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
113
|
+
// Prepare computed
|
|
114
|
+
// The row is frozen in `data-table`; the definition only answers what it
|
|
115
|
+
// cannot guess: which fields hold the summary, the cover, the linked entries.
|
|
116
|
+
const listingKeys = computed(() => listingKeysFor(collection.value))
|
|
117
|
+
// An empty screen under a narrowed search is not an empty collection.
|
|
118
|
+
const narrowed = computed(() => Object.keys(narrowing.value).length > 0)
|
|
90
119
|
|
|
91
120
|
// Prepare methods
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
121
|
+
// `onSelect` is handed the event and the row: the table makes each line a
|
|
122
|
+
// button, keyboard included.
|
|
123
|
+
const _onRowSelect = (_event, row) => _open(row.original)
|
|
124
|
+
const _open = item => $router.push(`${$route.path}/${item.id}`)
|
|
125
|
+
|
|
126
|
+
const _remove = async (item) => {
|
|
127
|
+
try {
|
|
128
|
+
await removeEntry({ id: item.id, collectionId: collection.value.id })
|
|
129
|
+
} catch {
|
|
130
|
+
toast.add({
|
|
131
|
+
color: 'error',
|
|
132
|
+
title: "L'entrée n'a pas pu être supprimée",
|
|
133
|
+
description: 'Réessayez, et prévenez un administrateur si cela persiste.',
|
|
134
|
+
})
|
|
135
|
+
}
|
|
98
136
|
}
|
|
99
|
-
|
|
100
|
-
const _refreshTotal = async () => {
|
|
101
|
-
total.value = await Record.count($route.params.collection, narrowing.value)
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
const _fetchMoreRecords = async (skip = 0) => {
|
|
105
|
-
await _load(skip)
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
const _updateRecord = (item) => {
|
|
109
|
-
$router.push(`${$route.path}/${item._id}`)
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
const _removeRecord = async (item) => {
|
|
113
|
-
await Record.remove(item._id, $route.params.collection)
|
|
114
|
-
await _refreshTotal()
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
// Prepare watchers
|
|
118
|
-
watch(narrowing, async () => {
|
|
119
|
-
await _load(0)
|
|
120
|
-
await _refreshTotal()
|
|
121
|
-
}, { deep: true })
|
|
122
|
-
|
|
123
|
-
onMounted(_refreshTotal)
|
|
124
137
|
</script>
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<forms-layout v-bind="{ record, ...accountForm }" :schema="updateOwnProfileDto" />
|
|
3
|
+
</template>
|
|
4
|
+
|
|
5
|
+
<script setup>
|
|
6
|
+
import { updateOwnProfileDto } from '@open-commune/core/dtos'
|
|
7
|
+
import formsLayout from '~/components/forms/layouts/forms-layout'
|
|
8
|
+
import { ACCOUNT_FORM } from '~/constants/forms/account'
|
|
9
|
+
|
|
10
|
+
// Prepare composables
|
|
11
|
+
const $session = useSession()
|
|
12
|
+
const { mutateAsync: updateOwnProfile } = useAuth().updateOwnProfile()
|
|
13
|
+
const $toast = useToast()
|
|
14
|
+
|
|
15
|
+
definePageMeta({
|
|
16
|
+
permissions: ['entrance:self'],
|
|
17
|
+
headings: {
|
|
18
|
+
title: 'Mon compte',
|
|
19
|
+
description: 'Votre nom, votre mot de passe et vos appareils connectés.'
|
|
20
|
+
}
|
|
21
|
+
})
|
|
22
|
+
|
|
23
|
+
// Prepare computed
|
|
24
|
+
const accountForm = computed(() => ({
|
|
25
|
+
layout: ACCOUNT_FORM.layout.map(tab => ({
|
|
26
|
+
...tab,
|
|
27
|
+
sections: tab.sections.map(section => ({
|
|
28
|
+
...section,
|
|
29
|
+
componentOptions: { ...section.componentOptions, onSave: _save }
|
|
30
|
+
}))
|
|
31
|
+
}))
|
|
32
|
+
}))
|
|
33
|
+
const record = computed(() => $session.user.value ?? {})
|
|
34
|
+
|
|
35
|
+
// Prepare methods
|
|
36
|
+
const _save = async (changes) => {
|
|
37
|
+
await updateOwnProfile(changes.name)
|
|
38
|
+
$toast.add({ title: 'Votre nom est à jour.' })
|
|
39
|
+
}
|
|
40
|
+
</script>
|
package/pages/index/index.vue
CHANGED
|
@@ -1,78 +1,70 @@
|
|
|
1
1
|
<template>
|
|
2
|
-
<
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
2
|
+
<UAuthForm
|
|
3
|
+
class="entrance-sign-in"
|
|
4
|
+
title="Connexion"
|
|
5
|
+
description="Administrez le site de votre commune."
|
|
6
|
+
:fields="FIELDS"
|
|
7
|
+
:schema="SCHEMA"
|
|
8
|
+
:submit="{ label: 'S\'identifier', color: 'neutral', loading: isLoading }"
|
|
9
|
+
@submit="_signIn"
|
|
10
|
+
>
|
|
11
|
+
<template #leading>
|
|
12
|
+
<layout-entrance-mark />
|
|
13
|
+
</template>
|
|
14
|
+
|
|
15
|
+
<template #footer>
|
|
16
|
+
<div class="flex flex-col items-center gap-1">
|
|
17
|
+
<UButton
|
|
18
|
+
color="neutral"
|
|
19
|
+
variant="link"
|
|
20
|
+
label="Vous avez oublié votre mot de passe ?"
|
|
21
|
+
to="/password/recover"
|
|
22
|
+
/>
|
|
23
|
+
<UButton
|
|
24
|
+
v-if="supportUrl"
|
|
25
|
+
color="neutral"
|
|
26
|
+
variant="link"
|
|
27
|
+
label="Je n'arrive pas à m'identifier"
|
|
28
|
+
:to="supportUrl"
|
|
29
|
+
target="_blank"
|
|
30
|
+
rel="noopener"
|
|
31
|
+
/>
|
|
32
|
+
</div>
|
|
33
|
+
</template>
|
|
34
|
+
</UAuthForm>
|
|
34
35
|
</template>
|
|
35
36
|
|
|
36
37
|
<script setup>
|
|
37
|
-
import
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
38
|
+
import * as z from 'zod'
|
|
39
|
+
|
|
40
|
+
// Prepare constants
|
|
41
|
+
const FIELDS = [
|
|
42
|
+
{ name: 'email', type: 'email', label: 'Adresse email', placeholder: 'Adresse email', autocomplete: 'email', required: true },
|
|
43
|
+
{ name: 'password', type: 'password', label: 'Mot de passe', placeholder: 'Mot de passe', autocomplete: 'current-password', required: true }
|
|
44
|
+
]
|
|
45
|
+
const SCHEMA = z.object({
|
|
46
|
+
email: z.email('Adresse email invalide'),
|
|
47
|
+
password: z.string().min(1, 'Mot de passe requis')
|
|
48
|
+
})
|
|
49
|
+
// Where someone locked out asks for help: the host's support, from the
|
|
50
|
+
// configuration. Without it the link is not shown rather than leading nowhere.
|
|
51
|
+
const { public: { supportUrl } } = useRuntimeConfig()
|
|
41
52
|
|
|
42
53
|
// Prepare composables
|
|
43
|
-
const
|
|
44
|
-
const
|
|
54
|
+
const $session = useSession()
|
|
55
|
+
const $toast = useToast()
|
|
45
56
|
|
|
46
|
-
// Prepare reactive
|
|
57
|
+
// Prepare reactive
|
|
47
58
|
const isLoading = ref(false)
|
|
48
|
-
const emailAddress = ref('')
|
|
49
|
-
const password = ref('')
|
|
50
|
-
|
|
51
|
-
// Prepare emitters
|
|
52
|
-
defineEmits(['enter'])
|
|
53
59
|
|
|
54
60
|
// Prepare methods
|
|
55
|
-
const
|
|
56
|
-
// https://forms.fillout.com/t/vjkLG9ZXsLus
|
|
57
|
-
const formUrl = 'https://forms.fillout.com/t/vjkLG9ZXsLus'
|
|
58
|
-
const formWindow = window.open(formUrl, '_blank')
|
|
59
|
-
if (formWindow) {
|
|
60
|
-
// Browser has allowed it to be opened
|
|
61
|
-
formWindow.focus()
|
|
62
|
-
} else {
|
|
63
|
-
// Browser has blocked it
|
|
64
|
-
alert('Please allow popups for this website')
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
const _signIn = async () => {
|
|
61
|
+
const _signIn = async (event) => {
|
|
68
62
|
isLoading.value = true
|
|
69
63
|
try {
|
|
70
|
-
await session.login(
|
|
71
|
-
notificationsStore.add({ icon: 'iconoir:password-pass', type: 'success', title: 'Authentification réussie.' })
|
|
64
|
+
await $session.login(event.data.email, event.data.password)
|
|
72
65
|
await navigateTo('/overview')
|
|
73
|
-
} catch
|
|
74
|
-
|
|
75
|
-
notificationsStore.add({ icon: 'iconoir:password-error', type: 'warn', title: 'Identifiants incorrects.' })
|
|
66
|
+
} catch {
|
|
67
|
+
$toast.add({ icon: 'iconoir:password-error', color: 'warning', title: 'Identifiants incorrects.' })
|
|
76
68
|
} finally {
|
|
77
69
|
isLoading.value = false
|
|
78
70
|
}
|
|
@@ -1,79 +1,55 @@
|
|
|
1
1
|
<template>
|
|
2
|
-
<
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
autocomplete="new-password"
|
|
24
|
-
:value="passwordConfirmation"
|
|
25
|
-
required
|
|
26
|
-
@change="passwordConfirmation = $event"
|
|
27
|
-
/>
|
|
28
|
-
<button-primary
|
|
29
|
-
type="submit"
|
|
30
|
-
:label="isLoading ? 'Envoie en cours' : 'Confirmer'"
|
|
31
|
-
:disabled="!password || password !== passwordConfirmation"
|
|
32
|
-
:loading="isLoading"
|
|
33
|
-
class="w-full"
|
|
34
|
-
/>
|
|
35
|
-
</form>
|
|
36
|
-
</div>
|
|
2
|
+
<UAuthForm
|
|
3
|
+
title="Définir un mot de passe"
|
|
4
|
+
description="Il vous servira à vous identifier."
|
|
5
|
+
:fields="FIELDS"
|
|
6
|
+
:schema="SCHEMA"
|
|
7
|
+
:submit="{ label: 'Définir le mot de passe', color: 'neutral', loading: isLoading }"
|
|
8
|
+
@submit="_updatePassword"
|
|
9
|
+
>
|
|
10
|
+
<template #leading>
|
|
11
|
+
<layout-entrance-mark />
|
|
12
|
+
</template>
|
|
13
|
+
|
|
14
|
+
<template #footer>
|
|
15
|
+
<div class="flex flex-col items-center gap-3">
|
|
16
|
+
<p class="text-xs text-dimmed">
|
|
17
|
+
Dix caractères minimum.
|
|
18
|
+
</p>
|
|
19
|
+
<UButton color="neutral" variant="link" label="← Retour à la connexion" to="/" />
|
|
20
|
+
</div>
|
|
21
|
+
</template>
|
|
22
|
+
</UAuthForm>
|
|
37
23
|
</template>
|
|
38
24
|
|
|
39
25
|
<script setup>
|
|
40
|
-
import
|
|
41
|
-
|
|
42
|
-
|
|
26
|
+
import * as z from 'zod'
|
|
27
|
+
|
|
28
|
+
// Prepare constants
|
|
29
|
+
const FIELDS = [
|
|
30
|
+
{ name: 'password', type: 'password', label: 'Nouveau mot de passe', placeholder: 'Nouveau mot de passe', autocomplete: 'new-password', required: true },
|
|
31
|
+
{ name: 'confirmation', type: 'password', label: 'Confirmer le mot de passe', placeholder: 'Confirmer le mot de passe', autocomplete: 'new-password', required: true }
|
|
32
|
+
]
|
|
33
|
+
const SCHEMA = z
|
|
34
|
+
.object({
|
|
35
|
+
password: z.string().min(10, '10 caractères minimum'),
|
|
36
|
+
confirmation: z.string()
|
|
37
|
+
})
|
|
38
|
+
.refine((values) => values.password === values.confirmation, {
|
|
39
|
+
message: 'Les deux mots de passe diffèrent',
|
|
40
|
+
path: ['confirmation']
|
|
41
|
+
})
|
|
43
42
|
|
|
44
43
|
// Prepare composables
|
|
45
|
-
const notificationsStore = useNotificationsStore()
|
|
46
44
|
const $route = useRoute()
|
|
47
|
-
const $
|
|
48
|
-
const { Entrance } = useModels()
|
|
45
|
+
const $auth = useAuth()
|
|
49
46
|
|
|
50
|
-
// Prepare
|
|
51
|
-
const
|
|
52
|
-
const passwordConfirmation = ref('')
|
|
53
|
-
const isLoading = ref(false)
|
|
47
|
+
// Prepare computed
|
|
48
|
+
const isLoading = computed(() => $auth.isDefiningPassword.value)
|
|
54
49
|
|
|
55
50
|
// Prepare methods
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
// oublié » se voyait réclamer un nom sous un titre « Votre compte ».
|
|
61
|
-
const _updatePassword = async () => {
|
|
62
|
-
isLoading.value = true
|
|
63
|
-
try {
|
|
64
|
-
const { token } = $route.params
|
|
65
|
-
await Entrance.updatePassword({ token, password: password.value })
|
|
66
|
-
notificationsStore.add({ icon: 'iconoir:password-cursor', type: 'success', title: 'Mot de passe mis à jour, connectez-vous.' })
|
|
67
|
-
$router.push('/')
|
|
68
|
-
} catch (err) {
|
|
69
|
-
console.log(err)
|
|
70
|
-
notificationsStore.add({
|
|
71
|
-
icon: 'iconoir:password-error',
|
|
72
|
-
type: 'warn',
|
|
73
|
-
title: 'Lien expiré ou déjà utilisé, ou mot de passe trop court (10 caractères minimum).'
|
|
74
|
-
})
|
|
75
|
-
} finally {
|
|
76
|
-
isLoading.value = false
|
|
77
|
-
}
|
|
78
|
-
}
|
|
51
|
+
const _updatePassword = (event) => $auth.definePassword({
|
|
52
|
+
token: $route.params.token,
|
|
53
|
+
password: event.data.password,
|
|
54
|
+
})
|
|
79
55
|
</script>
|
|
@@ -1,72 +1,61 @@
|
|
|
1
1
|
<template>
|
|
2
|
-
<div class="
|
|
3
|
-
<h2 class="
|
|
4
|
-
|
|
2
|
+
<div v-if="isSent" class="text-center">
|
|
3
|
+
<h2 class="text-lg font-medium text-highlighted">
|
|
4
|
+
Le mail est parti
|
|
5
5
|
</h2>
|
|
6
|
-
<p class="mt-
|
|
7
|
-
|
|
6
|
+
<p class="mt-2 text-sm text-muted">
|
|
7
|
+
N'hésitez pas à vérifier vos courriers indésirables.
|
|
8
8
|
</p>
|
|
9
|
-
<
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
:value="emailAddress"
|
|
16
|
-
:read-only="isLoading"
|
|
17
|
-
required
|
|
18
|
-
@change="emailAddress = $event"
|
|
19
|
-
/>
|
|
20
|
-
<button-primary
|
|
21
|
-
type="submit"
|
|
22
|
-
:label="isLoading ? 'Envoie en cours' : 'Continuer'"
|
|
23
|
-
:disabled="!emailAddress"
|
|
24
|
-
:loading="isLoading"
|
|
25
|
-
class="w-full"
|
|
26
|
-
/>
|
|
27
|
-
</form>
|
|
28
|
-
<button-primary
|
|
29
|
-
v-if="isSent"
|
|
30
|
-
label="← Revenir à l'espace de connexion"
|
|
31
|
-
class="w-full mt-8"
|
|
32
|
-
@click="$router.push('/')"
|
|
9
|
+
<UButton
|
|
10
|
+
class="mt-8"
|
|
11
|
+
color="neutral"
|
|
12
|
+
variant="link"
|
|
13
|
+
label="← Retour à la connexion"
|
|
14
|
+
to="/"
|
|
33
15
|
/>
|
|
34
16
|
</div>
|
|
17
|
+
|
|
18
|
+
<UAuthForm
|
|
19
|
+
v-else
|
|
20
|
+
title="Mot de passe oublié"
|
|
21
|
+
description="Recevez un lien pour définir un nouveau mot de passe."
|
|
22
|
+
:fields="FIELDS"
|
|
23
|
+
:schema="SCHEMA"
|
|
24
|
+
:submit="{ label: isLoading ? 'Envoi en cours' : 'Envoyer le lien', color: 'neutral', loading: isLoading }"
|
|
25
|
+
@submit="_recoverPassword"
|
|
26
|
+
>
|
|
27
|
+
<template #leading>
|
|
28
|
+
<layout-entrance-mark />
|
|
29
|
+
</template>
|
|
30
|
+
|
|
31
|
+
<template #footer>
|
|
32
|
+
<div class="flex justify-center">
|
|
33
|
+
<UButton color="neutral" variant="link" label="← Retour à la connexion" to="/" />
|
|
34
|
+
</div>
|
|
35
|
+
</template>
|
|
36
|
+
</UAuthForm>
|
|
35
37
|
</template>
|
|
36
38
|
|
|
37
39
|
<script setup>
|
|
38
|
-
import
|
|
39
|
-
|
|
40
|
-
|
|
40
|
+
import * as z from 'zod'
|
|
41
|
+
|
|
42
|
+
// Prepare constants
|
|
43
|
+
const FIELDS = [
|
|
44
|
+
{ name: 'email', type: 'email', label: 'Adresse email', placeholder: 'Adresse email', autocomplete: 'email', required: true }
|
|
45
|
+
]
|
|
46
|
+
const SCHEMA = z.object({ email: z.email('Adresse email invalide') })
|
|
41
47
|
|
|
42
48
|
// Prepare composables
|
|
43
|
-
const
|
|
44
|
-
const { Entrance } = useModels()
|
|
49
|
+
const $auth = useAuth()
|
|
45
50
|
|
|
46
|
-
// Prepare
|
|
47
|
-
const isLoading = ref(false)
|
|
51
|
+
// Prepare reactive
|
|
48
52
|
const isSent = ref(false)
|
|
49
|
-
const emailAddress = ref('')
|
|
50
53
|
|
|
51
54
|
// Prepare computed
|
|
52
|
-
const
|
|
53
|
-
return isSent.value ? 'Le mail est parti' : 'Réinitialiser votre mot de passe'
|
|
54
|
-
})
|
|
55
|
-
const message = computed(() => {
|
|
56
|
-
return isSent.value ? 'N\'hésitez pas à vérifier vos courriers indesirables.' : 'Entrez votre adresse email et nous vous enverrons un lien pour mettre à jour votre mot de passe.'
|
|
57
|
-
})
|
|
55
|
+
const isLoading = computed(() => $auth.isRequestingPasswordReset.value)
|
|
58
56
|
|
|
59
57
|
// Prepare methods
|
|
60
|
-
const _recoverPassword = async () => {
|
|
61
|
-
|
|
62
|
-
try {
|
|
63
|
-
await Entrance.recoverPassword(emailAddress.value)
|
|
64
|
-
notificationsStore.add({ icon: 'iconoir:mail-out', type: 'success', title: 'Email envoyé.' })
|
|
65
|
-
isSent.value = true
|
|
66
|
-
} catch (err) {
|
|
67
|
-
console.log(err) // eslint-disable-line
|
|
68
|
-
} finally {
|
|
69
|
-
setTimeout(() => { isLoading.value = false }, 2 * 1000)
|
|
70
|
-
}
|
|
58
|
+
const _recoverPassword = async (event) => {
|
|
59
|
+
if (await $auth.requestPasswordReset(event.data.email)) isSent.value = true
|
|
71
60
|
}
|
|
72
61
|
</script>
|