@open-commune/web 0.2.12 → 0.2.14

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.
@@ -1,78 +1,70 @@
1
1
  <template>
2
- <div class="mt-12">
3
- <form class="space-y-6" form @submit.prevent="_signIn">
4
- <input-text
5
- place-holder="Adresse email"
6
- name="email"
7
- type="email"
8
- autocomplete="email"
9
- :value="emailAddress"
10
- :read-only="isLoading"
11
- required
12
- @change="emailAddress = $event"
13
- />
14
- <input-text
15
- place-holder="Mot de passe"
16
- name="password"
17
- type="password"
18
- autocomplete="current-password"
19
- :value="password"
20
- :read-only="isLoading"
21
- required
22
- @change="password = $event"
23
- />
24
- <button-primary type="submit" label="S'identifier" :loading="isLoading" class="w-full" />
25
- </form>
26
- <div class="flex mt-8 flex-col items-center justify-center">
27
- <button-tertiary
28
- label="Vous avez oublié votre mot de passe ?"
29
- @click="$router.push({ path: '/password/recover' })"
30
- />
31
- <button-tertiary class="h-10" label="Je n'arrive pas à m'identifier" @click="_openForm()" />
32
- </div>
33
- </div>
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 { useNotificationsStore } from '~/store/layout/notifications'
38
- import InputText from '~/components/forms/inputs/input-text'
39
- import ButtonPrimary from '~/components/elements/buttons/primary'
40
- import ButtonTertiary from '~/components/elements/buttons/tertiary'
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 notificationsStore = useNotificationsStore()
44
- const session = useSession()
54
+ const $session = useSession()
55
+ const $toast = useToast()
45
56
 
46
- // Prepare reactive data
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 _openForm = () => {
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(emailAddress.value, password.value)
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 (err) {
74
- console.log(err)
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
- <div class="mt-12 text-center">
3
- <h2 class="inline-flex mt-6 text-sm font-semibold">
4
- Nouveau mot de passe
5
- </h2>
6
- <p class="mt-4 font-light text-sm text-gray-600">
7
- Choisissez un mot de passe robuste (10 caractères minimum).
8
- </p>
9
- <form class="mt-12 space-y-6" @submit.prevent="_updatePassword">
10
- <input-text
11
- place-holder="Mot de passe"
12
- name="password"
13
- type="password"
14
- autocomplete="new-password"
15
- :value="password"
16
- required
17
- @change="password = $event"
18
- />
19
- <input-text
20
- place-holder="Confirmation"
21
- name="password-confirmation"
22
- type="password"
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 { useNotificationsStore } from '~/store/layout/notifications'
41
- import InputText from '~/components/forms/inputs/input-text'
42
- import ButtonPrimary from '~/components/elements/buttons/primary'
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 $router = useRouter()
48
- const { Entrance } = useModels()
45
+ const $auth = useAuth()
49
46
 
50
- // Prepare data
51
- const password = ref('')
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
- // Cette page ne sert QUE la réinitialisation : le compte existe déjà, son nom
57
- // est conservé côté serveur. L'invitation, elle, a son propre écran (/welcome)
58
- // — c'est le seul parcours qui a un nom d'affichage à demander. Les deux
59
- // partageaient cet écran, et un utilisateur venu du mail « mot de passe
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="mt-12 text-center">
3
- <h2 class="inline-flex mt-6 text-sm font-semibold">
4
- {{ title }}
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-4 font-light text-sm text-gray-600">
7
- {{ message }}
6
+ <p class="mt-2 text-sm text-muted">
7
+ N'hésitez pas à vérifier vos courriers indésirables.
8
8
  </p>
9
- <form v-if="!isSent" class="mt-12 space-y-6" @submit.prevent="_recoverPassword">
10
- <input-text
11
- place-holder="Adresse email"
12
- name="email"
13
- type="email"
14
- autocomplete="email"
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 { useNotificationsStore } from '~/store/layout/notifications'
39
- import InputText from '~/components/forms/inputs/input-text'
40
- import ButtonPrimary from '~/components/elements/buttons/primary'
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 notificationsStore = useNotificationsStore()
44
- const { Entrance } = useModels()
49
+ const $auth = useAuth()
45
50
 
46
- // Prepare data
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 title = computed(() => {
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
- isLoading.value = true
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>
@@ -1,90 +1,53 @@
1
1
  <template>
2
- <div class="mt-12 text-center">
3
- <h2 class="inline-flex mt-6 text-sm font-semibold">
4
- Bienvenue !
5
- </h2>
6
- <p class="mt-4 font-light text-sm text-gray-600">
7
- Vous avez été invité·e à rejoindre l'espace d'administration.
8
- Choisissez votre nom d'affichage et un mot de passe robuste (10 caractères minimum).
9
- </p>
10
- <form class="mt-12 space-y-6" @submit.prevent="_createAccount">
11
- <input-text
12
- place-holder="Votre nom"
13
- name="name"
14
- autocomplete="name"
15
- :value="name"
16
- required
17
- @change="name = $event"
18
- />
19
- <input-text
20
- place-holder="Mot de passe"
21
- name="password"
22
- type="password"
23
- autocomplete="new-password"
24
- :value="password"
25
- required
26
- @change="password = $event"
27
- />
28
- <input-text
29
- place-holder="Confirmation"
30
- name="password-confirmation"
31
- type="password"
32
- autocomplete="new-password"
33
- :value="passwordConfirmation"
34
- required
35
- @change="passwordConfirmation = $event"
36
- />
37
- <button-primary
38
- type="submit"
39
- :label="isLoading ? 'Envoie en cours' : 'Créer mon compte'"
40
- :disabled="!name || !password || password !== passwordConfirmation"
41
- :loading="isLoading"
42
- class="w-full"
43
- />
44
- </form>
45
- </div>
2
+ <UAuthForm
3
+ title="Bienvenue !"
4
+ description="Vous avez été invité·e à rejoindre l'espace d'administration. Choisissez votre nom d'affichage et un mot de passe robuste."
5
+ :fields="FIELDS"
6
+ :schema="SCHEMA"
7
+ :submit="{ label: 'Accepter l\'invitation', color: 'neutral', loading: isLoading }"
8
+ @submit="_createAccount"
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>
46
23
  </template>
47
24
 
48
25
  <script setup>
49
- import { useNotificationsStore } from '~/store/layout/notifications'
50
- import InputText from '~/components/forms/inputs/input-text'
51
- import ButtonPrimary from '~/components/elements/buttons/primary'
26
+ import * as z from 'zod'
27
+
28
+ // Prepare constants
29
+ const FIELDS = [
30
+ { name: 'name', type: 'text', label: 'Votre nom', placeholder: 'Votre nom', autocomplete: 'name', required: true },
31
+ { name: 'password', type: 'password', label: 'Mot de passe', placeholder: 'Mot de passe', autocomplete: 'new-password', required: true }
32
+ ]
33
+ const SCHEMA = z.object({
34
+ name: z.string().min(1, 'Votre nom est requis'),
35
+ password: z.string().min(10, '10 caractères minimum')
36
+ })
52
37
 
53
- // Flux invitation Open Commune : la validité du jeton est vérifiée au moment de
54
- // l'acceptation (auth.acceptInvitation) — plus d'étape « confirmation d'email »
55
- // préalable.
56
- //
57
- // L'écran porte désormais le formulaire au lieu de renvoyer sur
58
- // /password/define : cette page-là ne sert plus qu'à la réinitialisation, où
59
- // il n'y a pas de nom à demander.
60
- const notificationsStore = useNotificationsStore()
38
+ // Prepare composables
61
39
  const $route = useRoute()
62
- const $router = useRouter()
63
- const { Entrance } = useModels()
40
+ const $auth = useAuth()
64
41
 
65
- // Prepare data
66
- const name = ref('')
67
- const password = ref('')
68
- const passwordConfirmation = ref('')
69
- const isLoading = ref(false)
42
+ // Prepare computed
43
+ const isLoading = computed(() => $auth.isAcceptingInvitation.value)
70
44
 
71
45
  // Prepare methods
72
- const _createAccount = async () => {
73
- isLoading.value = true
74
- try {
75
- const { token } = $route.params
76
- await Entrance.acceptInvitation({ token, name: name.value, password: password.value })
77
- notificationsStore.add({ icon: 'iconoir:password-cursor', type: 'success', title: 'Compte activé, connectez-vous.' })
78
- $router.push('/')
79
- } catch (err) {
80
- console.log(err)
81
- notificationsStore.add({
82
- icon: 'iconoir:password-error',
83
- type: 'warn',
84
- title: 'Invitation invalide ou mot de passe trop court (10 caractères minimum).'
85
- })
86
- } finally {
87
- isLoading.value = false
88
- }
46
+ const _createAccount = async (event) => {
47
+ await $auth.acceptInvitation({
48
+ token: $route.params.token,
49
+ name: event.data.name,
50
+ password: event.data.password
51
+ })
89
52
  }
90
53
  </script>
package/pages/index.vue CHANGED
@@ -1,44 +1,13 @@
1
1
  <template>
2
- <div class="min-h-screen bg-white flex">
3
- <div class="m-auto w-full max-w-lg lg:w-96">
4
- <div class="flex flex-col items-center space-y-2 mb-4">
5
- <img
6
- src="/logo-black.svg"
7
- alt="Logo"
8
- class="dark:hidden h-16 w-auto"
9
- >
10
- <img
11
- src="/logo-white.svg"
12
- alt="Logo"
13
- class="hidden h-24 w-auto"
14
- >
15
- <p v-if="demoEnv" class="text-sm text-gray-400 w-full border-t border-gray-100 text-center pt-2">
16
- <span class="bg-black rounded-lg text-white px-4 text-xs py-0.5 h-5 mx-auto">
17
- beta
18
- </span>
19
- </p>
2
+ <div class="entrance flex min-h-screen items-center justify-center bg-default px-4 py-12">
3
+ <div class="w-full max-w-sm">
4
+ <div class="entrance-card rounded-xl bg-elevated p-8 shadow-sm">
5
+ <nuxt-page />
20
6
  </div>
21
- <nuxt-page />
22
7
  </div>
23
8
  </div>
24
9
  </template>
25
10
 
26
11
  <script setup>
27
- const $config = useRuntimeConfig()
28
-
29
- definePageMeta({
30
- layout: 'entrance',
31
- auth: {
32
- unauthenticatedOnly: true,
33
- navigateAuthenticatedTo: '/overview',
34
- }
35
- })
36
-
37
- // Prepare computed
38
- // L'image d'instance est COMMUNE à tous les clients : rien de spécifique n'y est
39
- // cuit. L'hôte servi est donc la seule source fiable pour distinguer une démo.
40
- const demoEnv = computed(() => {
41
- const host = import.meta.client ? window.location.host : ''
42
- return host.includes('.beta') || host.includes('localhost')
43
- })
44
- </script>
12
+ definePageMeta({ layout: 'entrance' })
13
+ </script>
@@ -0,0 +1,7 @@
1
+ // Writes the instance's appearance on the document root, before anything
2
+ // paints: the tokens of assets/css/main.css are keyed on this attribute.
3
+ export default defineNuxtPlugin(() => {
4
+ const { appearance } = useRuntimeConfig().public
5
+ // `default` names the default aloud, for a layer whose own default is another.
6
+ if (appearance && appearance !== 'default') document.documentElement.dataset.appearance = String(appearance)
7
+ })
@@ -0,0 +1,36 @@
1
+ /**
2
+ * Location values of the `input-location` widget: `{ address, coordinates }`,
3
+ * where `coordinates` is a Mapbox `[longitude, latitude]` pair.
4
+ *
5
+ * Legacy records carry an address with `coordinates: []` (typed by hand, never
6
+ * geocoded). A map centred on such a value falls back to `[0, 0]` — the open
7
+ * ocean in the Gulf of Guinea — so every reader checks the pair first.
8
+ */
9
+
10
+ // Metropolitan France, the view shown while a location has no coordinates.
11
+ export const FALLBACK_CENTER = [2.35, 46.6];
12
+ export const FALLBACK_ZOOM = 5;
13
+ export const LOCATION_ZOOM = 15;
14
+
15
+ /** The `[lng, lat]` pair as numbers, or `null` when it is not a usable position. */
16
+ export const toLngLat = (coordinates) => {
17
+ if (!Array.isArray(coordinates) || coordinates.length !== 2) {
18
+ return null;
19
+ }
20
+ const [lng, lat] = coordinates.map((value) =>
21
+ value === '' || value === null ? Number.NaN : Number(value),
22
+ );
23
+ if (!Number.isFinite(lng) || !Number.isFinite(lat)) {
24
+ return null;
25
+ }
26
+ if (lng < -180 || lng > 180 || lat < -90 || lat > 90) {
27
+ return null;
28
+ }
29
+ // [0, 0] is what a failed geocoding leaves behind, never a commune.
30
+ if (lng === 0 && lat === 0) {
31
+ return null;
32
+ }
33
+ return [lng, lat];
34
+ };
35
+
36
+ export const hasCoordinates = (location) => toLngLat(location?.coordinates) !== null;