@metano/quasar_rest_auth 1.0.1
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/.gitattributes +17 -0
- package/LICENSE +21 -0
- package/Makefile +18 -0
- package/README.md +6 -0
- package/boot/alerts.js +152 -0
- package/boot/api.js +155 -0
- package/boot/app.js +111 -0
- package/boot/base.js +242 -0
- package/boot/config.js +117 -0
- package/boot/cripto.js +35 -0
- package/boot/data.js +28 -0
- package/boot/storage.js +74 -0
- package/components/DefinicoesLayout.vue +34 -0
- package/components/FormLogin.vue +217 -0
- package/components/LeftMenu.vue +93 -0
- package/components/LeftMenuSegundo.vue +96 -0
- package/components/MyTest.vue +41 -0
- package/components/RightMenu.vue +36 -0
- package/components/SearchMenu.vue +88 -0
- package/components/SettingsLayout.vue +34 -0
- package/components/TopMenu.vue +68 -0
- package/components/TopMenuSegundo.vue +85 -0
- package/components/footer/Comments.vue +77 -0
- package/components/footer/MainFooter.vue +71 -0
- package/components/header/HeaderBrand.vue +64 -0
- package/components/header/HeaderDarkModeToggle.vue +40 -0
- package/components/header/HeaderFullScreen.vue +55 -0
- package/components/header/HeaderLanguage.vue +56 -0
- package/components/header/HeaderNotifications.vue +53 -0
- package/components/header/HeaderServices.vue +118 -0
- package/components/header/HeaderUser.vue +210 -0
- package/components/header/HeaderUserMenu.vue +0 -0
- package/components/header/RegistarEntidade.vue +309 -0
- package/gitignore +3 -0
- package/help +9 -0
- package/index.js +9 -0
- package/layouts/AuthLayout.vue +74 -0
- package/layouts/MainLayout.vue +190 -0
- package/package.json +31 -0
- package/pages/auth/LoginPage.vue +32 -0
- package/pages/routes.js +33 -0
- package/stores/AuthStore.js +587 -0
- package/stores/example-store.js +21 -0
- package/stores/index.js +20 -0
- package/stores/settings.js +12 -0
|
@@ -0,0 +1,587 @@
|
|
|
1
|
+
import { defineStore } from 'pinia'
|
|
2
|
+
import { getStorage, setStorage, deleteStorage } from '../boot/storage'
|
|
3
|
+
import { HTTPAuth, HTTPClient, url } from '../boot/api'
|
|
4
|
+
import { tdc } from '../boot/app'
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
export const LoadStore = defineStore('load', {
|
|
10
|
+
state: () => ({
|
|
11
|
+
count: 0
|
|
12
|
+
}),
|
|
13
|
+
getters: {
|
|
14
|
+
value: (state) => state.counter,
|
|
15
|
+
},
|
|
16
|
+
actions: {
|
|
17
|
+
inc() {
|
|
18
|
+
this.count++
|
|
19
|
+
},
|
|
20
|
+
dec() {
|
|
21
|
+
this.count--
|
|
22
|
+
},
|
|
23
|
+
}
|
|
24
|
+
})
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
export const AlertStore = defineStore('alert', {
|
|
28
|
+
state: () => ({
|
|
29
|
+
data: []
|
|
30
|
+
}),
|
|
31
|
+
actions: {
|
|
32
|
+
add(alert) {
|
|
33
|
+
this.data.push(alert)
|
|
34
|
+
},
|
|
35
|
+
remove(alert) {
|
|
36
|
+
this.data = this.data.filter(a => a.id !== alert.id)
|
|
37
|
+
},
|
|
38
|
+
clear() {
|
|
39
|
+
this.data = []
|
|
40
|
+
},
|
|
41
|
+
}
|
|
42
|
+
})
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
export const AuthStore = defineStore('auth', {
|
|
47
|
+
state: () => ({
|
|
48
|
+
TipoEntidades: [],
|
|
49
|
+
TipoEntidade: { },
|
|
50
|
+
TipoEntidadeMenus: [],
|
|
51
|
+
search: '',
|
|
52
|
+
TipoEntidadeAllMenus: [],
|
|
53
|
+
Idiomas: [ ]
|
|
54
|
+
}),
|
|
55
|
+
|
|
56
|
+
getters: {
|
|
57
|
+
|
|
58
|
+
},
|
|
59
|
+
|
|
60
|
+
actions: {
|
|
61
|
+
async getTipoEntidades(){
|
|
62
|
+
await HTTPClient.get(url({type: "u", url: "auth/tipoEntidades", params: {}}) )
|
|
63
|
+
.then(res => {
|
|
64
|
+
this.TipoEntidades = res.data
|
|
65
|
+
}).catch(err => {
|
|
66
|
+
|
|
67
|
+
})
|
|
68
|
+
},
|
|
69
|
+
async setTipoEntidadeMenus () {
|
|
70
|
+
await HTTPAuth.get(url({ type: 'u', url: 'auth/tipoEntidades/' + this.TipoEntidade.id + '/menus', params: {} }))
|
|
71
|
+
.then(res => {
|
|
72
|
+
this.TipoEntidadeAllMenus = res.data
|
|
73
|
+
this.TipoEntidadeMenus = this.TipoEntidadeAllMenus
|
|
74
|
+
}).catch(err => {
|
|
75
|
+
console.log(err)
|
|
76
|
+
})
|
|
77
|
+
},
|
|
78
|
+
}
|
|
79
|
+
})
|
|
80
|
+
|
|
81
|
+
export const LanguageStore = defineStore("lang", {
|
|
82
|
+
state: () => ({
|
|
83
|
+
current: {} ,
|
|
84
|
+
list: [],
|
|
85
|
+
}),
|
|
86
|
+
|
|
87
|
+
actions: {
|
|
88
|
+
change(lang) {
|
|
89
|
+
this.current = lang
|
|
90
|
+
},
|
|
91
|
+
|
|
92
|
+
async get() {
|
|
93
|
+
await HTTPClient.get(url({type: "u", url: "auth/idiomas", params: {}}) )
|
|
94
|
+
.then(res => {
|
|
95
|
+
this.list = res.data
|
|
96
|
+
this.current = this.list[0]
|
|
97
|
+
}).catch(err => {
|
|
98
|
+
})
|
|
99
|
+
}
|
|
100
|
+
},
|
|
101
|
+
})
|
|
102
|
+
|
|
103
|
+
|
|
104
|
+
export const UserStore = defineStore("user", {
|
|
105
|
+
state: () => ({
|
|
106
|
+
data: null,
|
|
107
|
+
TipoEntidade: [],
|
|
108
|
+
Entidades: [],
|
|
109
|
+
Entidade: null,
|
|
110
|
+
EntidadeModelos: [],
|
|
111
|
+
EntidadeModulos: [],
|
|
112
|
+
Sucursals: [],
|
|
113
|
+
Sucursal: null,
|
|
114
|
+
Grupos: [],
|
|
115
|
+
Grupo: {id: '1', name: 'Gest' },
|
|
116
|
+
Settings: false,
|
|
117
|
+
Permicoes: [],
|
|
118
|
+
access: null,
|
|
119
|
+
refresh: null,
|
|
120
|
+
LeftTop: true,
|
|
121
|
+
RigthTop: true,
|
|
122
|
+
LeftMenu: true,
|
|
123
|
+
isLogin: false,
|
|
124
|
+
isLogout: false,
|
|
125
|
+
manterLogado: false,
|
|
126
|
+
}),
|
|
127
|
+
|
|
128
|
+
getters: {
|
|
129
|
+
username: (state) => state.data?.username || ".",
|
|
130
|
+
perfil: (state) =>
|
|
131
|
+
state.data?.perfil.url ||
|
|
132
|
+
"https://awsacademy.instructure.com/images/messages/avatar-50.png",
|
|
133
|
+
},
|
|
134
|
+
|
|
135
|
+
actions: {
|
|
136
|
+
async setEntidadeModelos () {
|
|
137
|
+
await HTTPAuth.get(url({ type: 'u', url: 'auth/entidades/' + this.Entidade?.id + '/modelos', params: {} }))
|
|
138
|
+
.then(res => {
|
|
139
|
+
this.EntidadeModelos = res.data
|
|
140
|
+
}).catch(err => {
|
|
141
|
+
console.log(err)
|
|
142
|
+
})
|
|
143
|
+
},
|
|
144
|
+
isTokenExpired (token) {
|
|
145
|
+
if (!token) return true
|
|
146
|
+
try {
|
|
147
|
+
const payload = JSON.parse(atob(token.split('.')[1]))
|
|
148
|
+
const now = Math.floor(Date.now() / 1000)
|
|
149
|
+
return payload.exp < now
|
|
150
|
+
} catch (e) {
|
|
151
|
+
return true
|
|
152
|
+
}
|
|
153
|
+
},
|
|
154
|
+
safeParse (value) {
|
|
155
|
+
try {
|
|
156
|
+
return value ? JSON.parse(value) : null
|
|
157
|
+
} catch {
|
|
158
|
+
return null
|
|
159
|
+
}
|
|
160
|
+
},
|
|
161
|
+
setIdioma(idioma){
|
|
162
|
+
this.Idioma = idioma
|
|
163
|
+
},
|
|
164
|
+
selectGroup(grupo){
|
|
165
|
+
this.Grupo = grupo
|
|
166
|
+
},
|
|
167
|
+
toggleSettings(){
|
|
168
|
+
this.Settings = !this.Settings
|
|
169
|
+
setStorage('c', 'settings', this.Settings)
|
|
170
|
+
},
|
|
171
|
+
toggleLeftTop(){
|
|
172
|
+
this.LeftTop = !this.LeftTop
|
|
173
|
+
setStorage('c', 'left_top', this.LeftTop)
|
|
174
|
+
},
|
|
175
|
+
toggleRightTop(){
|
|
176
|
+
this.RightTop = !this.RightTop
|
|
177
|
+
setStorage('c', 'right_top', this.RightTop)
|
|
178
|
+
},
|
|
179
|
+
|
|
180
|
+
async login(data, q) {
|
|
181
|
+
const rsp = await HTTPClient.post(url({type: "u", url: "auth/login/", params: {}}), data )
|
|
182
|
+
.then(async res => {
|
|
183
|
+
this.access = res.data.tokens.access
|
|
184
|
+
this.refresh = res.data.tokens.refresh
|
|
185
|
+
setStorage('c', 'access', this.access, 365)
|
|
186
|
+
setStorage('c', 'refresh', this.refresh, 365)
|
|
187
|
+
|
|
188
|
+
if (this.manterLogado) {
|
|
189
|
+
setStorage('c', 'username', data.email, 365)
|
|
190
|
+
setStorage('c', 'password', data.password, 365)
|
|
191
|
+
} else {
|
|
192
|
+
deleteStorage('c', 'username')
|
|
193
|
+
deleteStorage('c', 'password')
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
await this.me()
|
|
197
|
+
await this.getEntidades_(q)
|
|
198
|
+
}).catch(err => {
|
|
199
|
+
console.log(err)
|
|
200
|
+
|
|
201
|
+
})
|
|
202
|
+
return rsp
|
|
203
|
+
},
|
|
204
|
+
|
|
205
|
+
async me() {
|
|
206
|
+
const rsp = await HTTPAuth.get(url({type: "u", url: "auth/me", params: {}}) )
|
|
207
|
+
.then(res => {
|
|
208
|
+
this.data = res.data
|
|
209
|
+
setStorage('c', 'user', JSON.stringify(this.data), 365)
|
|
210
|
+
}).catch(err => {
|
|
211
|
+
console.log(err)
|
|
212
|
+
})
|
|
213
|
+
return rsp
|
|
214
|
+
},
|
|
215
|
+
|
|
216
|
+
|
|
217
|
+
async refreshToken() {
|
|
218
|
+
const data = {refresh: this.refresh }
|
|
219
|
+
const rsp = await HTTPAuth.post(url({type: "u", url: "auth/refresh_token/", params: {}}), data )
|
|
220
|
+
.then(res => {
|
|
221
|
+
this.access = res.data.access
|
|
222
|
+
console.log('deu access')
|
|
223
|
+
}).catch(err => {
|
|
224
|
+
console.log('nao deu access')
|
|
225
|
+
})
|
|
226
|
+
return rsp
|
|
227
|
+
},
|
|
228
|
+
|
|
229
|
+
async change_password_email(email, antiga, nova) {
|
|
230
|
+
const data = { email: email, password: antiga, passwordNova: nova }
|
|
231
|
+
const rsp = await HTTPAuth.post(url({type: "u", url: "auth/change_password_email/", params: {}}), data )
|
|
232
|
+
.then(res => {
|
|
233
|
+
}).catch(err => {
|
|
234
|
+
|
|
235
|
+
})
|
|
236
|
+
return rsp
|
|
237
|
+
},
|
|
238
|
+
|
|
239
|
+
async change_password_numero(mobile, otp, nova) {
|
|
240
|
+
const data = { mobile: mobile, otp: otp, password: nova }
|
|
241
|
+
const rsp = await HTTPAuth.post(url({type: "u", url: "auth/change_password_email/", params: {}}), data )
|
|
242
|
+
.then(res => {
|
|
243
|
+
}).catch(err => {
|
|
244
|
+
|
|
245
|
+
})
|
|
246
|
+
return rsp
|
|
247
|
+
},
|
|
248
|
+
|
|
249
|
+
async getEntidades () {
|
|
250
|
+
if (!this.data?.id) return
|
|
251
|
+
const rsp = await HTTPAuth.get( url({ type: 'u', url: `auth/users/${this.data.id}/userEntidades/`,params: {}}))
|
|
252
|
+
setStorage('c', 'userEntidades', JSON.stringify(rsp.data), 365)
|
|
253
|
+
this.Entidades = rsp.data
|
|
254
|
+
return rsp
|
|
255
|
+
},
|
|
256
|
+
|
|
257
|
+
async getEntidades_ (q) {
|
|
258
|
+
|
|
259
|
+
if (!this.data?.id) return
|
|
260
|
+
|
|
261
|
+
try {
|
|
262
|
+
const res = await HTTPAuth.get(
|
|
263
|
+
url({
|
|
264
|
+
type: 'u',
|
|
265
|
+
url: `auth/users/${this.data.id}/userEntidades/`,
|
|
266
|
+
params: {}
|
|
267
|
+
})
|
|
268
|
+
)
|
|
269
|
+
|
|
270
|
+
setStorage('c', 'userEntidades', JSON.stringify(res.data), 365)
|
|
271
|
+
this.Entidades = res.data
|
|
272
|
+
|
|
273
|
+
if (res.data.length === 1) {
|
|
274
|
+
this.selectEntidade_(res.data[0], q)
|
|
275
|
+
} else {
|
|
276
|
+
if (res.data.length === 0) {
|
|
277
|
+
this.Grupo = {id: '1', name: 'Gest' }
|
|
278
|
+
return
|
|
279
|
+
}
|
|
280
|
+
const entidades = res.data.map(e => ({
|
|
281
|
+
label: this.perfilSplint(e.nome),
|
|
282
|
+
value: e
|
|
283
|
+
}))
|
|
284
|
+
|
|
285
|
+
q.dialog({
|
|
286
|
+
title: tdc('Seleccione a Entidade'),
|
|
287
|
+
options: {
|
|
288
|
+
type: 'radio',
|
|
289
|
+
model: 'opt1',
|
|
290
|
+
items: entidades
|
|
291
|
+
},
|
|
292
|
+
cancel: true,
|
|
293
|
+
persistent: true
|
|
294
|
+
}).onOk(data => this.selectEntidade_(data, q))
|
|
295
|
+
.onCancel(() => {
|
|
296
|
+
this.Grupo = {id: '1', name: 'Gest' }
|
|
297
|
+
})
|
|
298
|
+
}
|
|
299
|
+
} catch (err) {
|
|
300
|
+
console.error(err)
|
|
301
|
+
}
|
|
302
|
+
},
|
|
303
|
+
|
|
304
|
+
selectEntidade_ (entidade, q) {
|
|
305
|
+
this.Entidade = entidade
|
|
306
|
+
setStorage('c', 'userEntidade', JSON.stringify(entidade), 365)
|
|
307
|
+
this.getSucursals_(q)
|
|
308
|
+
},
|
|
309
|
+
|
|
310
|
+
async getSucursals_ (q) {
|
|
311
|
+
await HTTPAuth.get(url({ type: 'u', url: 'auth/users/' + this.data?.id + '/userSucursals/', params: { } }))
|
|
312
|
+
.then(async res => {
|
|
313
|
+
setStorage('c', 'userSucursals', JSON.stringify(res.data), 365)
|
|
314
|
+
if (res.data.length === 1) {
|
|
315
|
+
this.selectSucursal_(res.data[0], q)
|
|
316
|
+
} else {
|
|
317
|
+
if (res.data.length === 0) {
|
|
318
|
+
this.Grupo = {id: '1', name: 'Gest' }
|
|
319
|
+
return
|
|
320
|
+
}
|
|
321
|
+
const sucursals = []
|
|
322
|
+
res.data.forEach(element => {
|
|
323
|
+
sucursals.push({ label: this.perfilSplint(element.nome), value: element })
|
|
324
|
+
})
|
|
325
|
+
q.dialog({
|
|
326
|
+
title: tdc('Seleccione a Sucursal'),
|
|
327
|
+
options: {
|
|
328
|
+
type: 'radio',
|
|
329
|
+
model: 'opt1',
|
|
330
|
+
isValid: val => true,
|
|
331
|
+
items: sucursals
|
|
332
|
+
},
|
|
333
|
+
cancel: true,
|
|
334
|
+
persistent: true
|
|
335
|
+
}).onOk(data => {
|
|
336
|
+
this.selectSucursal_(data, q)
|
|
337
|
+
}).onCancel(() => {
|
|
338
|
+
this.Grupo = {id: '1', name: 'Gest' }
|
|
339
|
+
})
|
|
340
|
+
}
|
|
341
|
+
}).catch(err => {
|
|
342
|
+
console.log(err)
|
|
343
|
+
})
|
|
344
|
+
},
|
|
345
|
+
|
|
346
|
+
selectSucursal_ (sucursal, q) {
|
|
347
|
+
this.Sucursal = sucursal
|
|
348
|
+
setStorage('c', 'userSucursal', JSON.stringify(sucursal), 365)
|
|
349
|
+
this.getGrupos_(q)
|
|
350
|
+
},
|
|
351
|
+
|
|
352
|
+
selectEntidade (entidade) {
|
|
353
|
+
setStorage('c', 'userEntidade', JSON.stringify(entidade), 365)
|
|
354
|
+
this.Entidade = JSON.parse(getStorage('c', 'userEntidade'))
|
|
355
|
+
this.getSucursals()
|
|
356
|
+
this.setEntidadeModulos()
|
|
357
|
+
},
|
|
358
|
+
|
|
359
|
+
selectSucursal (sucursal) {
|
|
360
|
+
this.Sucursal = sucursal
|
|
361
|
+
setStorage('c', 'userSucursal', JSON.stringify(sucursal), 365)
|
|
362
|
+
this.getGrupos()
|
|
363
|
+
},
|
|
364
|
+
|
|
365
|
+
async getSucursals () {
|
|
366
|
+
this.spiner = true
|
|
367
|
+
if (getStorage('c', 'userEntidade') !== null) {
|
|
368
|
+
|
|
369
|
+
const rsp = await HTTPAuth.get(url({ type: 'u', url: 'auth/users/' + this.data?.id + '/userSucursals/', params: { } }))
|
|
370
|
+
.then(res => {
|
|
371
|
+
setStorage('c', 'userSucursals', JSON.stringify(res.data), 365)
|
|
372
|
+
this.Sucursals = res.data
|
|
373
|
+
}).catch(err => {
|
|
374
|
+
console.log(err)
|
|
375
|
+
})
|
|
376
|
+
return rsp
|
|
377
|
+
}
|
|
378
|
+
},
|
|
379
|
+
|
|
380
|
+
|
|
381
|
+
|
|
382
|
+
async selectGrupo (grupo) {
|
|
383
|
+
setStorage('c', 'userGrupo', JSON.stringify(grupo), 365)
|
|
384
|
+
this.Grupo = grupo
|
|
385
|
+
await this.getPermicoes()
|
|
386
|
+
},
|
|
387
|
+
|
|
388
|
+
async getGrupos () {
|
|
389
|
+
|
|
390
|
+
const res = await HTTPAuth.get(
|
|
391
|
+
url({ type: 'u', url: `auth/users/${this.data?.id}/userGrupos/`, params: {} })
|
|
392
|
+
)
|
|
393
|
+
|
|
394
|
+
setStorage('c', 'userGrupos', JSON.stringify(res.data), 365)
|
|
395
|
+
this.Grupos = res.data
|
|
396
|
+
|
|
397
|
+
if (res.data.length === 1) {
|
|
398
|
+
this.selectGrupo_(res.data[0])
|
|
399
|
+
}
|
|
400
|
+
return res
|
|
401
|
+
},
|
|
402
|
+
|
|
403
|
+
async getGrupos_ (q) {
|
|
404
|
+
|
|
405
|
+
const res = await HTTPAuth.get(
|
|
406
|
+
url({ type: 'u', url: `auth/users/${this.data?.id}/userGrupos/`, params: {} })
|
|
407
|
+
)
|
|
408
|
+
|
|
409
|
+
setStorage('c', 'userGrupos', JSON.stringify(res.data), 365)
|
|
410
|
+
this.Grupos = res.data
|
|
411
|
+
|
|
412
|
+
if (res.data.length === 1) {
|
|
413
|
+
this.selectGrupo_(res.data[0])
|
|
414
|
+
}else{
|
|
415
|
+
if (res.data.length === 0) {
|
|
416
|
+
this.Grupo = {id: '1', name: 'Gest' }
|
|
417
|
+
return
|
|
418
|
+
}
|
|
419
|
+
const grupos = []
|
|
420
|
+
grupos.push( { label: 'Gest', value: {id: '1', name: 'Gest' } })
|
|
421
|
+
res.data.forEach(element => {
|
|
422
|
+
grupos.push({ label: this.perfilSplint(element.name), value: element })
|
|
423
|
+
})
|
|
424
|
+
q.dialog({
|
|
425
|
+
title: tdc('Seleccione o Grupo'),
|
|
426
|
+
options: {
|
|
427
|
+
type: 'radio',
|
|
428
|
+
model: 'opt1',
|
|
429
|
+
isValid: val => true,
|
|
430
|
+
items: grupos
|
|
431
|
+
},
|
|
432
|
+
cancel: true,
|
|
433
|
+
persistent: true
|
|
434
|
+
}).onOk(data => {
|
|
435
|
+
this.selectGrupo_(data)
|
|
436
|
+
}).onCancel(() => {
|
|
437
|
+
this.Grupo = {id: '1', name: 'Gest' }
|
|
438
|
+
})
|
|
439
|
+
}
|
|
440
|
+
return res
|
|
441
|
+
},
|
|
442
|
+
|
|
443
|
+
selectGrupo_ (group) {
|
|
444
|
+
this.Grupo = group
|
|
445
|
+
setStorage('c', 'userGrupo', JSON.stringify(group), 365)
|
|
446
|
+
this.getPermicoes()
|
|
447
|
+
},
|
|
448
|
+
|
|
449
|
+
async setEntidadeModulos () {
|
|
450
|
+
if (getStorage('c', 'userEntidade') !== null) {
|
|
451
|
+
|
|
452
|
+
const rsp = await HTTPAuth.get(url({ type: 'u', url: 'auth/entidades/' + this.Entidade.id + '/modulos/', params: { } }))
|
|
453
|
+
.then(res => {
|
|
454
|
+
setStorage('c', 'entidadeModulos', JSON.stringify(res.data), 365)
|
|
455
|
+
this.EntidadeModulos = res.data
|
|
456
|
+
}).catch(err => {
|
|
457
|
+
console.log(err)
|
|
458
|
+
})
|
|
459
|
+
return rsp
|
|
460
|
+
}
|
|
461
|
+
},
|
|
462
|
+
|
|
463
|
+
async getPermicoes () {
|
|
464
|
+
if (getStorage('c', 'userSucursal') !== null) {
|
|
465
|
+
|
|
466
|
+
const rsp = await HTTPAuth.get(url({ type: 'u', url: 'auth/users/' + this.data?.id + '/userPermicoes/', params: { } }))
|
|
467
|
+
.then(res => {
|
|
468
|
+
setStorage('l', 'userPermicoes', JSON.stringify(res.data), 365)
|
|
469
|
+
this.Permicoes = res.data
|
|
470
|
+
}).catch(err => {
|
|
471
|
+
console.log(err)
|
|
472
|
+
})
|
|
473
|
+
return rsp
|
|
474
|
+
}
|
|
475
|
+
},
|
|
476
|
+
|
|
477
|
+
|
|
478
|
+
isAuthorized (permission) {
|
|
479
|
+
let result = false
|
|
480
|
+
if (Array.isArray(this.Permicoes)) {
|
|
481
|
+
this.Permicoes.forEach(element => {
|
|
482
|
+
if (element.nome === permission) {
|
|
483
|
+
result = true
|
|
484
|
+
} else {
|
|
485
|
+
|
|
486
|
+
}
|
|
487
|
+
})
|
|
488
|
+
}
|
|
489
|
+
return true
|
|
490
|
+
// return result
|
|
491
|
+
},
|
|
492
|
+
|
|
493
|
+
perfilSplint (txt) {
|
|
494
|
+
if (!txt) return null
|
|
495
|
+
const p = txt.split('_')
|
|
496
|
+
return p[1] ?? p[0]
|
|
497
|
+
},
|
|
498
|
+
|
|
499
|
+
isTokenExpired (token) {
|
|
500
|
+
if (!token) return true
|
|
501
|
+
|
|
502
|
+
try {
|
|
503
|
+
const payload = JSON.parse(atob(token.split('.')[1]))
|
|
504
|
+
const now = Math.floor(Date.now() / 1000)
|
|
505
|
+
|
|
506
|
+
return payload.exp < now
|
|
507
|
+
} catch (e) {
|
|
508
|
+
return true
|
|
509
|
+
}
|
|
510
|
+
},
|
|
511
|
+
async checkSession () {
|
|
512
|
+
console.log('checkSession')
|
|
513
|
+
// access ainda válido → nada a fazer
|
|
514
|
+
if (!this.isTokenExpired(this.access)) {
|
|
515
|
+
console.log('access valido')
|
|
516
|
+
return
|
|
517
|
+
}
|
|
518
|
+
// access expirou → tenta refresh
|
|
519
|
+
if (!this.isTokenExpired(this.refresh)) {
|
|
520
|
+
console.log('access invalido')
|
|
521
|
+
try {
|
|
522
|
+
console.log('pedir access')
|
|
523
|
+
await this.refreshToken()
|
|
524
|
+
return
|
|
525
|
+
} catch (e) {
|
|
526
|
+
}
|
|
527
|
+
}
|
|
528
|
+
},
|
|
529
|
+
|
|
530
|
+
async logout(x) {
|
|
531
|
+
if (x == 'N') {
|
|
532
|
+
this.isLogout = !this.isLogout
|
|
533
|
+
this.isLogin = false
|
|
534
|
+
return
|
|
535
|
+
}
|
|
536
|
+
|
|
537
|
+
const rsp = await HTTPAuth.post(url({type: "u", url: "auth/logout/", params: {}}), {refresh: this.refresh} )
|
|
538
|
+
.then(res => {
|
|
539
|
+
this.data = null
|
|
540
|
+
this.refresh = null
|
|
541
|
+
this.access = null
|
|
542
|
+
this.Grupos = []
|
|
543
|
+
this.Entidades = []
|
|
544
|
+
this.Entidade = null
|
|
545
|
+
this.Sucursals = []
|
|
546
|
+
this.Sucursal = null
|
|
547
|
+
this.Grupo = {id:'1', name:'Hóspede'}
|
|
548
|
+
|
|
549
|
+
const userEntidade = getStorage('c', 'userEntidade')
|
|
550
|
+
|
|
551
|
+
deleteStorage('c', 'access')
|
|
552
|
+
deleteStorage('c', 'refresh')
|
|
553
|
+
deleteStorage('c', 'userEntidades')
|
|
554
|
+
deleteStorage('c', 'userEntidade')
|
|
555
|
+
deleteStorage('c', 'userSucursals')
|
|
556
|
+
deleteStorage('c', 'userSucursal')
|
|
557
|
+
deleteStorage('c', 'user')
|
|
558
|
+
deleteStorage('c', 'userGrupos')
|
|
559
|
+
deleteStorage('c', 'userGrupo')
|
|
560
|
+
deleteStorage('c', 'linga')
|
|
561
|
+
deleteStorage('c', 'entidadeModulos')
|
|
562
|
+
deleteStorage('c', 'entidadeModelos')
|
|
563
|
+
|
|
564
|
+
deleteStorage('l', 'traducao')
|
|
565
|
+
deleteStorage('l', 'userPermicoes')
|
|
566
|
+
deleteStorage('l', 'manterlogado')
|
|
567
|
+
deleteStorage('l', 'username')
|
|
568
|
+
deleteStorage('l', 'password')
|
|
569
|
+
|
|
570
|
+
if (x !== 'x') {
|
|
571
|
+
setStorage('c', 'userEntidade', userEntidade, 365)
|
|
572
|
+
}
|
|
573
|
+
|
|
574
|
+
setStorage('c', 'userGrupo', this.Grupo, 365)
|
|
575
|
+
this.isLogout = !this.isLogout
|
|
576
|
+
this.isLogin = false
|
|
577
|
+
}).catch(err => {
|
|
578
|
+
this.isLogout = !this.isLogout
|
|
579
|
+
this.isLogin = false
|
|
580
|
+
})
|
|
581
|
+
|
|
582
|
+
return rsp
|
|
583
|
+
}
|
|
584
|
+
|
|
585
|
+
},
|
|
586
|
+
})
|
|
587
|
+
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { defineStore, acceptHMRUpdate } from 'pinia'
|
|
2
|
+
|
|
3
|
+
export const useCounterStore = defineStore('counter', {
|
|
4
|
+
state: () => ({
|
|
5
|
+
counter: 0,
|
|
6
|
+
}),
|
|
7
|
+
|
|
8
|
+
getters: {
|
|
9
|
+
doubleCount: (state) => state.counter * 2,
|
|
10
|
+
},
|
|
11
|
+
|
|
12
|
+
actions: {
|
|
13
|
+
increment() {
|
|
14
|
+
this.counter++
|
|
15
|
+
},
|
|
16
|
+
},
|
|
17
|
+
})
|
|
18
|
+
|
|
19
|
+
if (import.meta.hot) {
|
|
20
|
+
import.meta.hot.accept(acceptHMRUpdate(useCounterStore, import.meta.hot))
|
|
21
|
+
}
|
package/stores/index.js
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { defineStore } from '#q-app/wrappers'
|
|
2
|
+
import { createPinia } from 'pinia'
|
|
3
|
+
|
|
4
|
+
/*
|
|
5
|
+
* If not building with SSR mode, you can
|
|
6
|
+
* directly export the Store instantiation;
|
|
7
|
+
*
|
|
8
|
+
* The function below can be async too; either use
|
|
9
|
+
* async/await or return a Promise which resolves
|
|
10
|
+
* with the Store instance.
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
export default defineStore((/* { ssrContext } */) => {
|
|
14
|
+
const pinia = createPinia()
|
|
15
|
+
|
|
16
|
+
// You can add Pinia plugins here
|
|
17
|
+
// pinia.use(SomePiniaPlugin)
|
|
18
|
+
|
|
19
|
+
return pinia
|
|
20
|
+
})
|