@oniti/quasar-app-extension-vlank-auth 3.2.26 → 4.0.0
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/.claude/settings.local.json +10 -0
- package/README.md +40 -23
- package/package.json +11 -4
- package/src/boot/index.js +40 -38
- package/src/components/pages/Login.vue +10 -12
- package/src/components/pages/PasswordLost.vue +6 -7
- package/src/components/pages/PasswordReset.vue +14 -17
- package/src/index.js +2 -2
- package/src/install.js +1 -5
- package/src/stores/auth.js +165 -0
- package/src/components/store/actions.js +0 -80
- package/src/components/store/getters.js +0 -78
- package/src/components/store/index.js +0 -12
- package/src/components/store/mutations.js +0 -32
- package/src/components/store/state.js +0 -14
package/README.md
CHANGED
|
@@ -7,6 +7,12 @@ Provides :
|
|
|
7
7
|
- login page
|
|
8
8
|
- helpers (get user, rights, disconnect, …)
|
|
9
9
|
|
|
10
|
+
### Prérequis
|
|
11
|
+
|
|
12
|
+
- Node.js >= 18.0.0
|
|
13
|
+
- Quasar 2 avec `@quasar/app-vite` ^2.0.0
|
|
14
|
+
- Pinia installé et enregistré dans l'app consommatrice (via un boot file chargé **avant** celui de vlank-auth)
|
|
15
|
+
- L'extension `@oniti/vlank-starter` installée au préalable
|
|
10
16
|
|
|
11
17
|
### Install
|
|
12
18
|
```bash
|
|
@@ -23,6 +29,16 @@ quasar ext remove @oniti/vlank-auth
|
|
|
23
29
|
yarn upgrade @oniti/vlank-auth
|
|
24
30
|
```
|
|
25
31
|
|
|
32
|
+
### Migration v3 → v4
|
|
33
|
+
|
|
34
|
+
**Breaking changes :**
|
|
35
|
+
|
|
36
|
+
- **Pinia obligatoire** : le composant utilise Pinia au lieu de Vuex. Votre application doit avoir Pinia installé et enregistré via un boot file **précédant** celui de vlank-auth dans `quasar.config.js > boot`.
|
|
37
|
+
- **`@quasar/app-vite` ^2.0.0 requis** : les projets encore sur `@quasar/app-webpack` doivent rester sur vlank-auth 3.2.x.
|
|
38
|
+
- **Alias webpack → alias Vite** : remplacer `chainWebpack` par `build.extendViteConf` (voir Configuration ci-dessous).
|
|
39
|
+
- **Node 18+** requis.
|
|
40
|
+
- **État accédé via Pinia** : si votre app accédait directement à l'état (déconseillé), utiliser `useAuthStore` à la place de `store.state.auth`. Le champ `has_check` est renommé `hasCheck`.
|
|
41
|
+
|
|
26
42
|
### Live extension development
|
|
27
43
|
```bash
|
|
28
44
|
# in this extension root directory (once for all):
|
|
@@ -32,7 +48,10 @@ yarn link
|
|
|
32
48
|
# (delete node_modules + yarn install to get to the original state)
|
|
33
49
|
yarn link "@oniti/quasar-app-extension-vlank-auth"
|
|
34
50
|
```
|
|
35
|
-
|
|
51
|
+
|
|
52
|
+
Pendant la phase de migration v4, il faut également linker `@oniti/quasar-app-extension-vlank-input` en v4 en local dans le projet consommateur.
|
|
53
|
+
|
|
54
|
+
In quasar.config.js of host project:
|
|
36
55
|
```javascript
|
|
37
56
|
devServer: {
|
|
38
57
|
…
|
|
@@ -54,13 +73,12 @@ ln -s /home/xfennec/git/vlank-auth/src/ node_modules/@oniti/quasar-app-extension
|
|
|
54
73
|
That's it. The extension is already in devServer's watchFiles of laravel-vlank,
|
|
55
74
|
so it will be reloaded automatically when you change something in the extension.
|
|
56
75
|
|
|
57
|
-
edit: I was also able to make it work by modifying files in node_modules and
|
|
58
|
-
running `quasar clean` in the host project + restarting `./serve.sh` for quick tests.
|
|
59
|
-
|
|
60
76
|
### Publish
|
|
61
77
|
```bash
|
|
62
78
|
# only necessary step (asks for new version):
|
|
63
79
|
yarn publish
|
|
80
|
+
# … ou si vous avez un yarn trop vieux (vu les changements récents chez npm):
|
|
81
|
+
npm publish
|
|
64
82
|
```
|
|
65
83
|
|
|
66
84
|
### Settings
|
|
@@ -73,28 +91,28 @@ The default page use `email` and `password` as credentials.
|
|
|
73
91
|
|
|
74
92
|
### Configuration
|
|
75
93
|
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
});
|
|
94
|
+
Les alias (logos, layout de login) sont définis côté consommateur dans `quasar.config.js` :
|
|
95
|
+
|
|
96
|
+
```javascript
|
|
97
|
+
import { fileURLToPath } from 'node:url'
|
|
98
|
+
|
|
99
|
+
build: {
|
|
100
|
+
extendViteConf (viteConf) {
|
|
101
|
+
viteConf.resolve ??= {}
|
|
102
|
+
viteConf.resolve.alias ??= {}
|
|
103
|
+
Object.assign(viteConf.resolve.alias, {
|
|
104
|
+
'vlank-auth-logo': fileURLToPath(new URL('./src/assets/logo-app.png', import.meta.url)),
|
|
105
|
+
'vlank-auth-logo-text': fileURLToPath(new URL('./src/assets/logo-app-text.png', import.meta.url)),
|
|
106
|
+
'vlank-auth-layout': fileURLToPath(new URL('./src/layouts/EmptyLayout.vue', import.meta.url)),
|
|
107
|
+
})
|
|
108
|
+
}
|
|
92
109
|
}
|
|
93
110
|
```
|
|
111
|
+
|
|
94
112
|
### Custom route validation
|
|
95
113
|
You can define a custom function to check route access.
|
|
96
114
|
|
|
97
|
-
in `quasar.
|
|
115
|
+
in `quasar.config.js`
|
|
98
116
|
```javascript
|
|
99
117
|
boot: [...,'override-check-route-access'],
|
|
100
118
|
...,
|
|
@@ -160,8 +178,7 @@ Route example:
|
|
|
160
178
|
|
|
161
179
|
## Helpers
|
|
162
180
|
|
|
163
|
-
The authentication logic is performed inside a
|
|
164
|
-
Les helpers sont accessibles depuis le composant après avoir fait un inject :
|
|
181
|
+
The authentication logic is performed inside a Pinia store (`useAuthStore`, exporté depuis `@oniti/quasar-app-extension-vlank-auth/src/stores/auth`). Les helpers sont accessibles depuis le composant après avoir fait un inject :
|
|
165
182
|
```javascript
|
|
166
183
|
import { inject } from 'vue'
|
|
167
184
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@oniti/quasar-app-extension-vlank-auth",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "4.0.0",
|
|
4
4
|
"description": "Authentification",
|
|
5
5
|
"author": "François BOUYER <francois@oniti.fr>",
|
|
6
6
|
"license": "MIT",
|
|
@@ -17,8 +17,15 @@
|
|
|
17
17
|
"access": "public"
|
|
18
18
|
},
|
|
19
19
|
"engines": {
|
|
20
|
-
"node": ">=
|
|
21
|
-
"npm": ">=
|
|
22
|
-
"yarn": ">= 1.
|
|
20
|
+
"node": ">= 18.0.0",
|
|
21
|
+
"npm": ">= 9.0.0",
|
|
22
|
+
"yarn": ">= 1.22.0"
|
|
23
|
+
},
|
|
24
|
+
"peerDependencies": {
|
|
25
|
+
"@quasar/app-vite": "^2.0.0",
|
|
26
|
+
"quasar": "^2.0.0",
|
|
27
|
+
"vue": "^3.3.0",
|
|
28
|
+
"pinia": "^3.0.0",
|
|
29
|
+
"@oniti/quasar-app-extension-vlank-input": "^4.0.0"
|
|
23
30
|
}
|
|
24
31
|
}
|
package/src/boot/index.js
CHANGED
|
@@ -1,10 +1,9 @@
|
|
|
1
|
-
import auth from "../components/store";
|
|
2
1
|
import { Notify } from "quasar";
|
|
3
2
|
import { boot } from 'quasar/wrappers'
|
|
3
|
+
import { useAuthStore } from "../stores/auth";
|
|
4
4
|
|
|
5
|
-
export default boot(({ app, router
|
|
6
|
-
|
|
7
|
-
store.registerModule("auth", auth);
|
|
5
|
+
export default boot(({ app, router }) => {
|
|
6
|
+
const authStore = useAuthStore();
|
|
8
7
|
|
|
9
8
|
const config = app.config.globalProperties.$q.config.onitiVlankAuth;
|
|
10
9
|
const configFramework = app.config.globalProperties.$q.config.onitiVlankAuthConfig ? app.config.globalProperties.$q.config.onitiVlankAuthConfig : {};
|
|
@@ -15,25 +14,25 @@ export default boot(({ app, router, store }) => {
|
|
|
15
14
|
* Défini les routes de redirection et de login
|
|
16
15
|
*/
|
|
17
16
|
const routesToSet = {
|
|
18
|
-
loginRoute: { default: "defaultAuthRoute",
|
|
17
|
+
loginRoute: { default: "defaultAuthRoute", setter: authStore.setLoginRoute },
|
|
19
18
|
redirectRoute: {
|
|
20
19
|
default: "defaultRedirectRoute",
|
|
21
|
-
|
|
20
|
+
setter: authStore.setRedirectRoute,
|
|
22
21
|
},
|
|
23
22
|
passwordCreateRoute: {
|
|
24
23
|
default: "defaultPasswordCreateRoute",
|
|
25
|
-
|
|
24
|
+
setter: authStore.setCreatePasswordRoute,
|
|
26
25
|
},
|
|
27
26
|
passwordLostRoute: {
|
|
28
27
|
default: "defaultPasswordLostRoute",
|
|
29
|
-
|
|
28
|
+
setter: authStore.setLostPasswordRoute,
|
|
30
29
|
},
|
|
31
30
|
};
|
|
32
31
|
|
|
33
32
|
for (const [key, routeConfig] of Object.entries(routesToSet)) {
|
|
34
33
|
let routePath = to.matched.find((r) => r.meta[key]);
|
|
35
34
|
routePath = routePath ? routePath.meta[key] : config[routeConfig.default];
|
|
36
|
-
|
|
35
|
+
routeConfig.setter(routePath);
|
|
37
36
|
}
|
|
38
37
|
|
|
39
38
|
let rights = to.matched.find((r) => r.meta.rights);
|
|
@@ -42,7 +41,6 @@ export default boot(({ app, router, store }) => {
|
|
|
42
41
|
let typeRightCheck = to.matched.find((r) => r.meta.typeRightCheck);
|
|
43
42
|
typeRightCheck = typeRightCheck ? typeRightCheck.meta.typeRightCheck : "all";
|
|
44
43
|
|
|
45
|
-
const getter_right_check = typeRightCheck === "any" ? "auth/checkAny" : "auth/checkAll";
|
|
46
44
|
const check_route_access_overide_name = configFramework.check_route_access_overide_name;
|
|
47
45
|
const check_route_access_overide = app.config.globalProperties[check_route_access_overide_name];
|
|
48
46
|
|
|
@@ -54,15 +52,19 @@ export default boot(({ app, router, store }) => {
|
|
|
54
52
|
: false;
|
|
55
53
|
|
|
56
54
|
if (!helper.isFunctionalRoute(to.path)) {
|
|
57
|
-
|
|
55
|
+
authStore.setWantedRoute(to.path);
|
|
58
56
|
}
|
|
59
57
|
if (to.matched.some((routeRecord) => routeRecord.meta.requiresAuth)) {
|
|
60
58
|
// eslint-disable-next-line
|
|
61
|
-
if (
|
|
59
|
+
if (authStore.logged) {
|
|
60
|
+
const rightCheck = typeRightCheck === "any"
|
|
61
|
+
? authStore.checkAny(rights)
|
|
62
|
+
: authStore.checkAll(rights);
|
|
63
|
+
|
|
62
64
|
// Pas les droits nécéssaires
|
|
63
|
-
if ((check_route_access_overide && !check_route_access_overide(
|
|
65
|
+
if ((check_route_access_overide && !check_route_access_overide(authStore.user, to)) || (!check_route_access_overide && !rightCheck)) {
|
|
64
66
|
if (logoutOnUnsufisantRights) {
|
|
65
|
-
|
|
67
|
+
authStore.logout();
|
|
66
68
|
next(helper.getLoginRoute());
|
|
67
69
|
} else {
|
|
68
70
|
next(from && from.path ? from.path : helper.getLoginRoute());
|
|
@@ -133,23 +135,23 @@ export default boot(({ app, router, store }) => {
|
|
|
133
135
|
let helper = {};
|
|
134
136
|
|
|
135
137
|
helper.getRedirectRoute = () => {
|
|
136
|
-
return
|
|
138
|
+
return authStore.routes.currentRedirect;
|
|
137
139
|
};
|
|
138
140
|
|
|
139
141
|
helper.getLoginRoute = () => {
|
|
140
|
-
return
|
|
142
|
+
return authStore.routes.currentLogin;
|
|
141
143
|
};
|
|
142
144
|
|
|
143
145
|
helper.getPasswordCreateRoute = () => {
|
|
144
|
-
return
|
|
146
|
+
return authStore.routes.currentPasswordCreateRoute;
|
|
145
147
|
};
|
|
146
148
|
|
|
147
149
|
helper.getPasswordLostRoute = () => {
|
|
148
|
-
return
|
|
150
|
+
return authStore.routes.currentPasswordLostRoute;
|
|
149
151
|
};
|
|
150
152
|
|
|
151
153
|
helper.getWantedRoute = () => {
|
|
152
|
-
return
|
|
154
|
+
return authStore.routes.currentWantedRoute;
|
|
153
155
|
};
|
|
154
156
|
|
|
155
157
|
helper.isFunctionalRoute = (routePath) => {
|
|
@@ -167,15 +169,15 @@ export default boot(({ app, router, store }) => {
|
|
|
167
169
|
*/
|
|
168
170
|
helper.fetch = () => {
|
|
169
171
|
return new Promise((resolve, reject) => {
|
|
170
|
-
|
|
171
|
-
.
|
|
172
|
+
authStore
|
|
173
|
+
.me()
|
|
172
174
|
.then(() => {
|
|
173
|
-
|
|
175
|
+
authStore.setHasCheck();
|
|
174
176
|
|
|
175
177
|
const wantedRoute = helper.getWantedRoute();
|
|
176
178
|
let route_to_go = null;
|
|
177
179
|
if (wantedRoute) {
|
|
178
|
-
|
|
180
|
+
authStore.setWantedRoute(null);
|
|
179
181
|
route_to_go = wantedRoute;
|
|
180
182
|
} else {
|
|
181
183
|
let redirectRoute = helper.getRedirectRoute()
|
|
@@ -192,7 +194,7 @@ export default boot(({ app, router, store }) => {
|
|
|
192
194
|
resolve();
|
|
193
195
|
})
|
|
194
196
|
.catch((err) => {
|
|
195
|
-
|
|
197
|
+
authStore.setHasCheck();
|
|
196
198
|
reject(err);
|
|
197
199
|
});
|
|
198
200
|
});
|
|
@@ -203,8 +205,8 @@ export default boot(({ app, router, store }) => {
|
|
|
203
205
|
*/
|
|
204
206
|
helper.login = (data) => {
|
|
205
207
|
return new Promise((resolve, reject) => {
|
|
206
|
-
|
|
207
|
-
.
|
|
208
|
+
authStore
|
|
209
|
+
.login(data)
|
|
208
210
|
.then(() => {
|
|
209
211
|
helper.fetch().then(resolve).catch(reject);
|
|
210
212
|
})
|
|
@@ -231,17 +233,17 @@ export default boot(({ app, router, store }) => {
|
|
|
231
233
|
*/
|
|
232
234
|
helper.logout = () => {
|
|
233
235
|
return new Promise((resolve, reject) => {
|
|
234
|
-
|
|
236
|
+
authStore.logout()
|
|
235
237
|
.then(() => {
|
|
236
238
|
let isPrivate = router.currentRoute._value.matched.some((match) => {
|
|
237
239
|
return match.meta.requiresAuth;
|
|
238
240
|
});
|
|
239
241
|
if (isPrivate) {
|
|
240
|
-
|
|
242
|
+
authStore.setWantedRoute(null);
|
|
241
243
|
router.push(helper.getLoginRoute());
|
|
242
244
|
}
|
|
243
|
-
|
|
244
|
-
|
|
245
|
+
authStore.setLogout();
|
|
246
|
+
authStore.setHasCheck();
|
|
245
247
|
resolve()
|
|
246
248
|
})
|
|
247
249
|
.catch(reject)
|
|
@@ -252,55 +254,55 @@ export default boot(({ app, router, store }) => {
|
|
|
252
254
|
* @param {*} data
|
|
253
255
|
*/
|
|
254
256
|
helper.updatePassword = (data) => {
|
|
255
|
-
return
|
|
257
|
+
return authStore.updatePassword(data);
|
|
256
258
|
};
|
|
257
259
|
/**
|
|
258
260
|
* reset le password
|
|
259
261
|
* @param {*} data
|
|
260
262
|
*/
|
|
261
263
|
helper.resetPassword = (data) => {
|
|
262
|
-
return
|
|
264
|
+
return authStore.resetPassword(data);
|
|
263
265
|
};
|
|
264
266
|
/**
|
|
265
267
|
* met à jour les informations de l'utilisateur
|
|
266
268
|
* @param {*} data
|
|
267
269
|
*/
|
|
268
270
|
helper.updateUser = (data) => {
|
|
269
|
-
return
|
|
271
|
+
return authStore.update(data);
|
|
270
272
|
};
|
|
271
273
|
/**
|
|
272
274
|
* Retourne l'utilisateur dans le store
|
|
273
275
|
*/
|
|
274
276
|
helper.user = () => {
|
|
275
|
-
return
|
|
277
|
+
return authStore.user;
|
|
276
278
|
};
|
|
277
279
|
/**
|
|
278
280
|
* Vérfie si un droit est présent
|
|
279
281
|
* @param {*} right
|
|
280
282
|
*/
|
|
281
283
|
helper.check = (right) => {
|
|
282
|
-
return
|
|
284
|
+
return authStore.checkSingle(right);
|
|
283
285
|
};
|
|
284
286
|
/**
|
|
285
287
|
* Vérfie si tous les droits sont validés
|
|
286
288
|
* @param {*} rights
|
|
287
289
|
*/
|
|
288
290
|
helper.checkAll = (rights) => {
|
|
289
|
-
return
|
|
291
|
+
return authStore.checkAll(rights);
|
|
290
292
|
};
|
|
291
293
|
/**
|
|
292
294
|
* Vérfie si un droit au moins est disponible.
|
|
293
295
|
* @param {*} rights
|
|
294
296
|
*/
|
|
295
297
|
helper.checkAny = (rights) => {
|
|
296
|
-
return
|
|
298
|
+
return authStore.checkAny(rights);
|
|
297
299
|
};
|
|
298
300
|
/**
|
|
299
301
|
* Envoi l'email de réinitialisation du password
|
|
300
302
|
* @param {*} data
|
|
301
303
|
*/
|
|
302
304
|
helper.passwordLost = (data) => {
|
|
303
|
-
return
|
|
305
|
+
return authStore.passwordLost(data);
|
|
304
306
|
};
|
|
305
307
|
|
|
306
308
|
app.config.globalProperties.$auth = helper;
|
|
@@ -68,10 +68,12 @@
|
|
|
68
68
|
|
|
69
69
|
<script setup>
|
|
70
70
|
import { ref, onMounted, computed, watch, inject } from 'vue'
|
|
71
|
-
import { useStore } from 'vuex'
|
|
72
71
|
import { useQuasar } from 'quasar'
|
|
72
|
+
import { useAuthStore } from '../../stores/auth'
|
|
73
|
+
import logoUrl from 'vlank-auth-logo'
|
|
74
|
+
import logoTextUrl from 'vlank-auth-logo-text'
|
|
73
75
|
|
|
74
|
-
const
|
|
76
|
+
const authStore = useAuthStore()
|
|
75
77
|
const $q = useQuasar()
|
|
76
78
|
const $auth = inject('vlank-auth')
|
|
77
79
|
|
|
@@ -79,7 +81,7 @@ const isPwd = ref(true)
|
|
|
79
81
|
const login = ref("")
|
|
80
82
|
const password = ref("")
|
|
81
83
|
|
|
82
|
-
const has_check = computed(() =>
|
|
84
|
+
const has_check = computed(() => authStore.hasCheck)
|
|
83
85
|
|
|
84
86
|
const getUrlPasswordLost = computed(() => {
|
|
85
87
|
return $q.config.onitiVlankAuth.defaultPasswordLostRoute
|
|
@@ -93,15 +95,11 @@ const submitConnexion = function () {
|
|
|
93
95
|
});
|
|
94
96
|
}
|
|
95
97
|
|
|
96
|
-
const getLogoImage =
|
|
97
|
-
return require('vlank-auth-logo')
|
|
98
|
-
}
|
|
99
|
-
|
|
98
|
+
const getLogoImage = () => logoUrl
|
|
100
99
|
|
|
101
|
-
const getLogoBottomImage =
|
|
102
|
-
if ($q.config.onitiVlankAuth.hideBottomTextLogo !== true)
|
|
103
|
-
|
|
104
|
-
return require('vlank-auth-logo-text')
|
|
100
|
+
const getLogoBottomImage = () => {
|
|
101
|
+
if ($q.config.onitiVlankAuth.hideBottomTextLogo !== true) {
|
|
102
|
+
return logoTextUrl
|
|
105
103
|
}
|
|
106
104
|
}
|
|
107
105
|
|
|
@@ -113,7 +111,7 @@ watch(has_check, (newValue, oldValue) => {
|
|
|
113
111
|
})
|
|
114
112
|
|
|
115
113
|
onMounted(() => {
|
|
116
|
-
if(!
|
|
114
|
+
if(!authStore.hasCheck){
|
|
117
115
|
$q.loading.show({
|
|
118
116
|
delay: 0, // ms
|
|
119
117
|
})
|
|
@@ -45,6 +45,8 @@
|
|
|
45
45
|
import { ref, inject } from 'vue'
|
|
46
46
|
import { useRouter } from 'vue-router'
|
|
47
47
|
import { useQuasar } from 'quasar'
|
|
48
|
+
import logoUrl from 'vlank-auth-logo'
|
|
49
|
+
import logoTextUrl from 'vlank-auth-logo-text'
|
|
48
50
|
|
|
49
51
|
const $auth = inject('vlank-auth')
|
|
50
52
|
const $router = useRouter()
|
|
@@ -60,14 +62,11 @@ const submitPasswordLost = function () {
|
|
|
60
62
|
})
|
|
61
63
|
}
|
|
62
64
|
|
|
63
|
-
const getLogoImage =
|
|
64
|
-
return require('vlank-auth-logo')
|
|
65
|
-
}
|
|
65
|
+
const getLogoImage = () => logoUrl
|
|
66
66
|
|
|
67
|
-
const getLogoBottomImage =
|
|
68
|
-
if ($q.config.onitiVlankAuth.hideBottomTextLogo !== true)
|
|
69
|
-
|
|
70
|
-
return require('vlank-auth-logo-text')
|
|
67
|
+
const getLogoBottomImage = () => {
|
|
68
|
+
if ($q.config.onitiVlankAuth.hideBottomTextLogo !== true) {
|
|
69
|
+
return logoTextUrl
|
|
71
70
|
}
|
|
72
71
|
}
|
|
73
72
|
|
|
@@ -65,12 +65,14 @@
|
|
|
65
65
|
<script setup>
|
|
66
66
|
import { ref, computed, watch, inject, onMounted } from 'vue'
|
|
67
67
|
import { useRoute, useRouter } from 'vue-router'
|
|
68
|
-
import { useStore } from 'vuex'
|
|
69
68
|
import { useQuasar } from 'quasar'
|
|
69
|
+
import { useAuthStore } from '../../stores/auth'
|
|
70
|
+
import logoUrl from 'vlank-auth-logo'
|
|
71
|
+
import logoTextUrl from 'vlank-auth-logo-text'
|
|
70
72
|
|
|
71
73
|
const $route = useRoute()
|
|
72
74
|
const $router = useRouter()
|
|
73
|
-
const
|
|
75
|
+
const authStore = useAuthStore()
|
|
74
76
|
const $q = useQuasar()
|
|
75
77
|
const $auth = inject('vlank-auth')
|
|
76
78
|
|
|
@@ -80,9 +82,7 @@ const token = ref($route.params.token)
|
|
|
80
82
|
const new_password = ref("")
|
|
81
83
|
const password_confirm = ref("")
|
|
82
84
|
|
|
83
|
-
const has_check = computed(() =>
|
|
84
|
-
return store.state.auth.has_check
|
|
85
|
-
})
|
|
85
|
+
const has_check = computed(() => authStore.hasCheck)
|
|
86
86
|
|
|
87
87
|
const submitPassword = function () {
|
|
88
88
|
$auth.resetPassword({
|
|
@@ -94,14 +94,11 @@ $auth.resetPassword({
|
|
|
94
94
|
});
|
|
95
95
|
}
|
|
96
96
|
|
|
97
|
-
const getLogoImage =
|
|
98
|
-
return require('vlank-auth-logo')
|
|
99
|
-
}
|
|
97
|
+
const getLogoImage = () => logoUrl
|
|
100
98
|
|
|
101
|
-
const getLogoBottomImage =
|
|
102
|
-
if ($q.config.onitiVlankAuth.hideBottomTextLogo !== true)
|
|
103
|
-
|
|
104
|
-
return require('vlank-auth-logo-text')
|
|
99
|
+
const getLogoBottomImage = () => {
|
|
100
|
+
if ($q.config.onitiVlankAuth.hideBottomTextLogo !== true) {
|
|
101
|
+
return logoTextUrl
|
|
105
102
|
}
|
|
106
103
|
}
|
|
107
104
|
|
|
@@ -112,11 +109,11 @@ if(newValue) {
|
|
|
112
109
|
})
|
|
113
110
|
|
|
114
111
|
onMounted(() => {
|
|
115
|
-
if(!
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
}
|
|
112
|
+
if(!authStore.hasCheck){
|
|
113
|
+
$q.loading.show({
|
|
114
|
+
delay: 0, // ms
|
|
115
|
+
})
|
|
116
|
+
}
|
|
120
117
|
})
|
|
121
118
|
</script>
|
|
122
119
|
|
package/src/index.js
CHANGED
|
@@ -7,9 +7,9 @@
|
|
|
7
7
|
*/
|
|
8
8
|
|
|
9
9
|
const extendWithComponent = (conf, api) => {
|
|
10
|
+
conf.boot = conf.boot || []
|
|
10
11
|
conf.boot.push('~@oniti/quasar-app-extension-vlank-auth/src/boot/index.js')
|
|
11
|
-
|
|
12
|
-
|
|
12
|
+
|
|
13
13
|
conf.framework.config.onitiVlankAuth = {
|
|
14
14
|
...api.prompts
|
|
15
15
|
}
|
package/src/install.js
CHANGED
|
@@ -6,11 +6,7 @@
|
|
|
6
6
|
*/
|
|
7
7
|
|
|
8
8
|
module.exports = function (api) {
|
|
9
|
-
api.compatibleWith('@quasar/app', '^
|
|
10
|
-
|
|
11
|
-
if (!api.hasExtension('@oniti/vlank-starter')) {
|
|
12
|
-
throw new Error('Extention Vlank-starter nécéssaire avant d\'installer celle ci')
|
|
13
|
-
}
|
|
9
|
+
api.compatibleWith('@quasar/app-vite', '^2.0.0')
|
|
14
10
|
|
|
15
11
|
api.onExitLog('Vlank-Auth bien installé Merci :)')
|
|
16
12
|
}
|
|
@@ -0,0 +1,165 @@
|
|
|
1
|
+
import { defineStore } from "pinia";
|
|
2
|
+
import { ref } from "vue";
|
|
3
|
+
import { axiosClient } from "axios-oniti";
|
|
4
|
+
|
|
5
|
+
export const useAuthStore = defineStore("auth", () => {
|
|
6
|
+
const user = ref(null);
|
|
7
|
+
const logged = ref(false);
|
|
8
|
+
const hasCheck = ref(false);
|
|
9
|
+
const routes = ref({
|
|
10
|
+
currentRedirect: null,
|
|
11
|
+
currentLogin: null,
|
|
12
|
+
currentPasswordCreateRoute: null,
|
|
13
|
+
currentPasswordLostRoute: null,
|
|
14
|
+
currentWantedRoute: null,
|
|
15
|
+
});
|
|
16
|
+
|
|
17
|
+
// Mutateurs (remplacent les commits Vuex)
|
|
18
|
+
function setAuth(newUser) {
|
|
19
|
+
user.value = newUser;
|
|
20
|
+
logged.value = true;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
function setLogout() {
|
|
24
|
+
user.value = null;
|
|
25
|
+
logged.value = false;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
function setHasCheck() {
|
|
29
|
+
hasCheck.value = true;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
function setRedirectRoute(route) {
|
|
33
|
+
routes.value.currentRedirect = route;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
function setLoginRoute(route) {
|
|
37
|
+
routes.value.currentLogin = route;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
function setLostPasswordRoute(route) {
|
|
41
|
+
routes.value.currentPasswordLostRoute = route;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
function setCreatePasswordRoute(route) {
|
|
45
|
+
routes.value.currentPasswordCreateRoute = route;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
function setWantedRoute(route) {
|
|
49
|
+
routes.value.currentWantedRoute = route;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
// Actions API
|
|
53
|
+
function login(data) {
|
|
54
|
+
return axiosClient.post("/auth/login", data, {
|
|
55
|
+
disable_oniti_success_notification: true,
|
|
56
|
+
disable_oniti_error_notification: true,
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
function logout() {
|
|
61
|
+
return new Promise((resolve, reject) => {
|
|
62
|
+
axiosClient
|
|
63
|
+
.post("/auth/logout", null, { disable_oniti_success_notification: true })
|
|
64
|
+
.then((response) => {
|
|
65
|
+
setLogout();
|
|
66
|
+
resolve(response.data);
|
|
67
|
+
})
|
|
68
|
+
.catch(reject);
|
|
69
|
+
});
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
function me() {
|
|
73
|
+
return new Promise((resolve, reject) => {
|
|
74
|
+
axiosClient
|
|
75
|
+
.get("/auth/me", { disable_oniti_error_notification: true })
|
|
76
|
+
.then((response) => {
|
|
77
|
+
setAuth(response.data);
|
|
78
|
+
resolve();
|
|
79
|
+
})
|
|
80
|
+
.catch(reject);
|
|
81
|
+
});
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
function updatePassword(data) {
|
|
85
|
+
return axiosClient.post("/auth/password/change", data, {
|
|
86
|
+
oniti_success_notification_message: "Mot de passe mis à jour.",
|
|
87
|
+
});
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
function resetPassword(data) {
|
|
91
|
+
return axiosClient.post("/auth/password/reset", data, {
|
|
92
|
+
oniti_success_notification_message: "Mot de passe mis à jour.",
|
|
93
|
+
});
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
function update(data) {
|
|
97
|
+
return new Promise((resolve, reject) => {
|
|
98
|
+
axiosClient
|
|
99
|
+
.put("/auth/update", data)
|
|
100
|
+
.then((response) => {
|
|
101
|
+
setAuth(response.data);
|
|
102
|
+
resolve();
|
|
103
|
+
})
|
|
104
|
+
.catch(reject);
|
|
105
|
+
});
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
function passwordLost(data) {
|
|
109
|
+
return axiosClient.post("/auth/password/lost", data, {
|
|
110
|
+
oniti_success_notification_message:
|
|
111
|
+
"Email de réinitialisation de mot de passe envoyé.",
|
|
112
|
+
});
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
// Helpers de vérification des droits
|
|
116
|
+
function checkSingle(right) {
|
|
117
|
+
if (!user.value) return false;
|
|
118
|
+
return user.value.rights.includes(right);
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
function checkAll(rights) {
|
|
122
|
+
if (!user.value) return false;
|
|
123
|
+
for (const right of rights) {
|
|
124
|
+
if (!user.value.rights.includes(right)) return false;
|
|
125
|
+
}
|
|
126
|
+
return true;
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
function checkAny(rights) {
|
|
130
|
+
if (!user.value) return false;
|
|
131
|
+
for (const right of rights) {
|
|
132
|
+
if (user.value.rights.includes(right)) return true;
|
|
133
|
+
}
|
|
134
|
+
return false;
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
return {
|
|
138
|
+
// state
|
|
139
|
+
user,
|
|
140
|
+
logged,
|
|
141
|
+
hasCheck,
|
|
142
|
+
routes,
|
|
143
|
+
// mutateurs
|
|
144
|
+
setAuth,
|
|
145
|
+
setLogout,
|
|
146
|
+
setHasCheck,
|
|
147
|
+
setRedirectRoute,
|
|
148
|
+
setLoginRoute,
|
|
149
|
+
setLostPasswordRoute,
|
|
150
|
+
setCreatePasswordRoute,
|
|
151
|
+
setWantedRoute,
|
|
152
|
+
// actions
|
|
153
|
+
login,
|
|
154
|
+
logout,
|
|
155
|
+
me,
|
|
156
|
+
updatePassword,
|
|
157
|
+
resetPassword,
|
|
158
|
+
update,
|
|
159
|
+
passwordLost,
|
|
160
|
+
// helpers droits
|
|
161
|
+
checkSingle,
|
|
162
|
+
checkAll,
|
|
163
|
+
checkAny,
|
|
164
|
+
};
|
|
165
|
+
});
|
|
@@ -1,80 +0,0 @@
|
|
|
1
|
-
import {axiosClient} from 'axios-oniti'
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Fonction de login
|
|
5
|
-
* @param { ActionContext } ctx
|
|
6
|
-
* @param { object } data
|
|
7
|
-
*/
|
|
8
|
-
export function login (ctx,data){
|
|
9
|
-
return axiosClient.post('/auth/login', data, { disable_oniti_success_notification: true, disable_oniti_error_notification: true })
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
/**
|
|
13
|
-
* Fonction de changement de mot de passe
|
|
14
|
-
* @param { ActionContext } ctx
|
|
15
|
-
* @param { object } data
|
|
16
|
-
*/
|
|
17
|
-
export function updatePassword (ctx, data) {
|
|
18
|
-
return axiosClient.post('/auth/password/change', data, { oniti_success_notification_message: 'Mot de passe mis à jour.'})
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
/**
|
|
22
|
-
* Fonction de reset de mot de passe
|
|
23
|
-
* @param { ActionContext } ctx
|
|
24
|
-
* @param { object } data
|
|
25
|
-
*/
|
|
26
|
-
export function resetPassword (ctx, data) {
|
|
27
|
-
return axiosClient.post('/auth/password/reset', data, { oniti_success_notification_message: 'Mot de passe mis à jour.' })
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
/**
|
|
31
|
-
* Fonction de update user
|
|
32
|
-
* @param { ActionContext } ctx
|
|
33
|
-
* @param { object } data
|
|
34
|
-
*/
|
|
35
|
-
export function update ({ commit },data){
|
|
36
|
-
return new Promise((resolve, reject) => {
|
|
37
|
-
axiosClient.put('/auth/update', data)
|
|
38
|
-
.then( response => {
|
|
39
|
-
commit('SET_AUTH', response.data)
|
|
40
|
-
resolve()
|
|
41
|
-
}).catch(reject)
|
|
42
|
-
})
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
/**
|
|
46
|
-
* Déconnection
|
|
47
|
-
*/
|
|
48
|
-
export function logout ({ commit }){
|
|
49
|
-
return new Promise((resolve,reject)=>{
|
|
50
|
-
axiosClient.post('/auth/logout', null, { disable_oniti_success_notification: true })
|
|
51
|
-
.then( response => {
|
|
52
|
-
commit('SET_LOGOUT')
|
|
53
|
-
resolve(response.data)
|
|
54
|
-
}).catch(reject)
|
|
55
|
-
})
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
/**
|
|
59
|
-
* Récupère l'utilisateur Courrant
|
|
60
|
-
* @param { ActionContext } state
|
|
61
|
-
*/
|
|
62
|
-
export function me ({ commit }){
|
|
63
|
-
return new Promise((resolve,reject)=>{
|
|
64
|
-
axiosClient.get('/auth/me',{ disable_oniti_error_notification: true })
|
|
65
|
-
.then( response => {
|
|
66
|
-
commit('SET_AUTH', response.data)
|
|
67
|
-
resolve()
|
|
68
|
-
}).catch(reject)
|
|
69
|
-
})
|
|
70
|
-
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
/**
|
|
74
|
-
* Fonction de mot de passe perdu
|
|
75
|
-
* @param { ActionContext } ctx
|
|
76
|
-
* @param { object } data
|
|
77
|
-
*/
|
|
78
|
-
export function passwordLost (ctx, data) {
|
|
79
|
-
return axiosClient.post('/auth/password/lost', data, { oniti_success_notification_message: 'Email de réinitialisation de mot de passe envoyé.' })
|
|
80
|
-
}
|
|
@@ -1,78 +0,0 @@
|
|
|
1
|
-
export function getRedirectRoute ( state ) {
|
|
2
|
-
return state.routes.currentRedirect
|
|
3
|
-
}
|
|
4
|
-
|
|
5
|
-
export function getPasswordCreateRoute ( state ) {
|
|
6
|
-
return state.routes.currentPasswordCreateRoute
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
export function getPasswordLostRoute ( state ) {
|
|
10
|
-
return state.routes.currentPasswordLostRoute
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
export function getLoginRoute ( state ) {
|
|
14
|
-
return state.routes.currentLogin
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
export function getWantedRoute ( state ) {
|
|
18
|
-
return state.routes.currentWantedRoute
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
export function getRights ( state ){
|
|
22
|
-
return state.user ? state.user.rights : []
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
export function isAuthenticated ( state ) {
|
|
26
|
-
return state.logged
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
export function hasCheckAuth ( state ) {
|
|
30
|
-
return state.has_check
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
export function user ( state ) {
|
|
34
|
-
return state.user
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
/**
|
|
38
|
-
* Vérifie la présence d'un droit spécifique
|
|
39
|
-
* @param {*} state
|
|
40
|
-
* @param {*} right
|
|
41
|
-
*/
|
|
42
|
-
export const checkSingle = ( state ) => ( right ) => {
|
|
43
|
-
const user = state.user
|
|
44
|
-
if(!user) return false
|
|
45
|
-
|
|
46
|
-
return user.rights.includes(right)
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
/**
|
|
50
|
-
* Vérifie si tous les droits sont vérfiés
|
|
51
|
-
* @param {*} state
|
|
52
|
-
* @param {*} rights
|
|
53
|
-
*/
|
|
54
|
-
export const checkAll = ( state ) => ( rights ) =>{
|
|
55
|
-
const user = state.user
|
|
56
|
-
if(!user) return false
|
|
57
|
-
|
|
58
|
-
for(const right of rights){
|
|
59
|
-
if(!user.rights.includes(right)) return false
|
|
60
|
-
}
|
|
61
|
-
return true
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
/**
|
|
65
|
-
* Vérifie si au moins un des droits est présent.
|
|
66
|
-
* @param {*} state
|
|
67
|
-
* @param {*} rights
|
|
68
|
-
*/
|
|
69
|
-
export const checkAny = ( state ) => ( rights ) => {
|
|
70
|
-
const user = state.user
|
|
71
|
-
if(!user) return false
|
|
72
|
-
|
|
73
|
-
for(const right of rights){
|
|
74
|
-
if(user.rights.includes(right)) return true
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
return false
|
|
78
|
-
}
|
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
export function SET_AUTH(state,user){
|
|
2
|
-
state.user = user
|
|
3
|
-
state.logged = true
|
|
4
|
-
}
|
|
5
|
-
export function SET_LOGOUT(state){
|
|
6
|
-
state.user = null
|
|
7
|
-
state.logged = false
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
export function HAS_CHECK_AUTH ( state ) {
|
|
11
|
-
state.has_check = true
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
export function SET_REDIRECT_ROUTE ( state, redirectRoute ) {
|
|
15
|
-
state.routes.currentRedirect = redirectRoute
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
export function SET_LOGIN_ROUTE ( state, loginRoute ) {
|
|
19
|
-
state.routes.currentLogin = loginRoute
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
export function SET_LOST_PASSWORD_ROUTE ( state, PasswordLostRoute ) {
|
|
23
|
-
state.routes.currentPasswordLostRoute = PasswordLostRoute
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
export function SET_CREATE_PASSWORD_ROUTE ( state, PasswordCreateRoute ) {
|
|
27
|
-
state.routes.currentPasswordCreateRoute = PasswordCreateRoute
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
export function SET_WANTED_ROUTE ( state, wantedRoute ) {
|
|
31
|
-
state.routes.currentWantedRoute = wantedRoute
|
|
32
|
-
}
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
export default function () {
|
|
2
|
-
return {
|
|
3
|
-
user: null,
|
|
4
|
-
logged: false,
|
|
5
|
-
has_check: false,
|
|
6
|
-
routes: {
|
|
7
|
-
currentRedirect: null,
|
|
8
|
-
currentLogin: null,
|
|
9
|
-
currentPasswordCreateRoute: null,
|
|
10
|
-
currentPasswordLostRoute: null,
|
|
11
|
-
currentWantedRoute: null
|
|
12
|
-
}
|
|
13
|
-
}
|
|
14
|
-
}
|