flamerest 1.0.67 → 1.0.69
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/REST.d.ts +1 -0
- package/REST.js +25 -6
- package/package.json +1 -1
package/REST.d.ts
CHANGED
package/REST.js
CHANGED
|
@@ -30,6 +30,12 @@ class FLAMEREST {
|
|
|
30
30
|
*/
|
|
31
31
|
this.version = version ? version : 'v1';
|
|
32
32
|
|
|
33
|
+
/**
|
|
34
|
+
* Если авторизация по токену, то он сюда подставляется
|
|
35
|
+
*/
|
|
36
|
+
this.isAuthByJWTQuery = true;
|
|
37
|
+
this.token = null;
|
|
38
|
+
|
|
33
39
|
}
|
|
34
40
|
|
|
35
41
|
install(Vue, options) {
|
|
@@ -44,7 +50,7 @@ class FLAMEREST {
|
|
|
44
50
|
* @param {string} type Тип
|
|
45
51
|
* @param {string} responseType Тип ответа: json или blob
|
|
46
52
|
*/
|
|
47
|
-
request(url, params, type = 'GET', responseType = 'json') {
|
|
53
|
+
request(url, params, type = 'GET', responseType = 'json', isNeedToken = true) {
|
|
48
54
|
|
|
49
55
|
// Нормализуем параметры, если они есть
|
|
50
56
|
if (typeof params === "object") {
|
|
@@ -60,6 +66,11 @@ class FLAMEREST {
|
|
|
60
66
|
|
|
61
67
|
try {
|
|
62
68
|
|
|
69
|
+
// Авторизация
|
|
70
|
+
if (this.isAuthByJWTQuery && isNeedToken === true && this.token !== null) {
|
|
71
|
+
url = url + "?access-token=" + this.token;
|
|
72
|
+
}
|
|
73
|
+
|
|
63
74
|
// Тело запроса
|
|
64
75
|
let requestBody = {
|
|
65
76
|
method: type,
|
|
@@ -468,20 +479,29 @@ class FLAMEREST {
|
|
|
468
479
|
return new Promise((resolve, reject) => { resolve(JSON.parse(window.sessionStorage.getItem("crudschema"))) });
|
|
469
480
|
}
|
|
470
481
|
|
|
471
|
-
async auth(username, password) {
|
|
482
|
+
async auth(username, password, isNeedToken) {
|
|
472
483
|
|
|
473
|
-
let resp =
|
|
484
|
+
let resp = null;
|
|
485
|
+
if (this.token !== null && (username === null || username === undefined)) {
|
|
486
|
+
resp = await this.request(this.SERVER + '/auth/auth', JSON.stringify({}), 'POST', 'json', true);
|
|
487
|
+
}
|
|
488
|
+
else {
|
|
489
|
+
resp = await this.request(this.SERVER + '/auth/auth', JSON.stringify({ login: username, password: password }), 'POST', 'json', false);
|
|
490
|
+
}
|
|
474
491
|
|
|
475
492
|
if (resp.errors) return resp;
|
|
476
493
|
if (resp.data.length === 0) { resp.errors = []; return resp; }
|
|
477
494
|
|
|
495
|
+
// после успешной авторизации устанавливаем токен
|
|
496
|
+
if (typeof resp.token === 'string') this.token = resp.token;
|
|
497
|
+
|
|
478
498
|
return resp.data;
|
|
479
499
|
|
|
480
500
|
}
|
|
481
501
|
|
|
482
502
|
async signup(email, username, password, name) {
|
|
483
503
|
|
|
484
|
-
let resp = await this.request(this.SERVER + '/auth/signup', JSON.stringify({ login: username, email: email, password: password, name: name }), 'POST');
|
|
504
|
+
let resp = await this.request(this.SERVER + '/auth/signup', JSON.stringify({ login: username, email: email, password: password, name: name }), 'POST', 'json', false);
|
|
485
505
|
|
|
486
506
|
if (resp.errors) return resp;
|
|
487
507
|
if (resp.data.length === 0) { resp.errors = []; return resp; }
|
|
@@ -553,14 +573,13 @@ class FLAMEREST {
|
|
|
553
573
|
*/
|
|
554
574
|
|
|
555
575
|
if (values[val] instanceof Array) {
|
|
556
|
-
values[val].splice(valueKey);
|
|
576
|
+
values[val].splice(valueKey, 1);
|
|
557
577
|
values[val].push(...newValues);
|
|
558
578
|
}
|
|
559
579
|
else {
|
|
560
580
|
values[val] = newValues;
|
|
561
581
|
}
|
|
562
582
|
|
|
563
|
-
|
|
564
583
|
}
|
|
565
584
|
}
|
|
566
585
|
}
|