@daffodil/auth 0.94.1-rc.0 → 0.95.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/fesm2022/daffodil-auth-driver-in-memory.mjs +356 -249
- package/fesm2022/daffodil-auth-driver-in-memory.mjs.map +1 -1
- package/fesm2022/daffodil-auth-driver-magento-2.4.7.mjs +459 -0
- package/fesm2022/daffodil-auth-driver-magento-2.4.7.mjs.map +1 -0
- package/fesm2022/daffodil-auth-driver-magento-auto.mjs +7 -0
- package/fesm2022/daffodil-auth-driver-magento-auto.mjs.map +1 -0
- package/fesm2022/daffodil-auth-driver-testing.mjs +220 -126
- package/fesm2022/daffodil-auth-driver-testing.mjs.map +1 -1
- package/fesm2022/daffodil-auth-driver.mjs +99 -126
- package/fesm2022/daffodil-auth-driver.mjs.map +1 -1
- package/fesm2022/daffodil-auth-routing.mjs +392 -257
- package/fesm2022/daffodil-auth-routing.mjs.map +1 -1
- package/fesm2022/daffodil-auth-state-testing.mjs +209 -106
- package/fesm2022/daffodil-auth-state-testing.mjs.map +1 -1
- package/fesm2022/daffodil-auth-state.mjs +867 -852
- package/fesm2022/daffodil-auth-state.mjs.map +1 -1
- package/fesm2022/daffodil-auth-testing.mjs +132 -76
- package/fesm2022/daffodil-auth-testing.mjs.map +1 -1
- package/fesm2022/daffodil-auth.mjs +65 -57
- package/fesm2022/daffodil-auth.mjs.map +1 -1
- package/package.json +1 -1
- package/types/daffodil-auth-driver-in-memory.d.ts +62 -62
- package/types/daffodil-auth-driver-magento-2.4.7.d.ts +119 -0
- package/types/daffodil-auth-driver-magento-auto.d.ts +1 -0
- package/types/daffodil-auth-driver-testing.d.ts +37 -36
- package/types/daffodil-auth-driver.d.ts +93 -112
- package/types/daffodil-auth-routing.d.ts +100 -104
- package/types/daffodil-auth-state-testing.d.ts +44 -43
- package/types/daffodil-auth-state.d.ts +265 -306
- package/types/daffodil-auth-testing.d.ts +28 -33
- package/types/daffodil-auth.d.ts +51 -62
- package/fesm2022/daffodil-auth-driver-magento.mjs +0 -385
- package/fesm2022/daffodil-auth-driver-magento.mjs.map +0 -1
- package/types/daffodil-auth-driver-magento.d.ts +0 -135
|
@@ -1,250 +1,357 @@
|
|
|
1
|
-
import { CommonModule } from
|
|
2
|
-
import * as i0 from
|
|
3
|
-
import { Injectable, NgModule } from
|
|
4
|
-
import { provideDaffLoginDriver, provideDaffRegisterDriver,
|
|
5
|
-
import { DaffInMemoryDriverBase, provideDaffInMemoryBackends } from
|
|
6
|
-
import
|
|
7
|
-
import * as i2 from
|
|
8
|
-
import { STATUS } from
|
|
9
|
-
import
|
|
10
|
-
import {
|
|
11
|
-
import {
|
|
1
|
+
import { CommonModule } from "@angular/common";
|
|
2
|
+
import * as i0 from "@angular/core";
|
|
3
|
+
import { Injectable, NgModule, makeEnvironmentProviders } from "@angular/core";
|
|
4
|
+
import { provideDaffAuthDriver, provideDaffLoginDriver, provideDaffRegisterDriver, provideDaffResetPasswordDriver } from "@daffodil/auth/driver";
|
|
5
|
+
import { DaffInMemoryDriverBase, provideDaffInMemoryBackends } from "@daffodil/driver/in-memory";
|
|
6
|
+
import { faker } from "@faker-js/faker/locale/en_US";
|
|
7
|
+
import * as i2 from "angular-in-memory-web-api";
|
|
8
|
+
import { STATUS } from "angular-in-memory-web-api";
|
|
9
|
+
import * as i1 from "@angular/common/http";
|
|
10
|
+
import { map, switchMap } from "rxjs/operators";
|
|
11
|
+
import { of, throwError } from "rxjs";
|
|
12
|
+
const DAFF_AUTH_IN_MEMORY_COLLECTION_NAME = "auth";
|
|
13
|
+
var DaffInMemoryBackendAuthService = class DaffInMemoryBackendAuthService {
|
|
14
|
+
constructor() {
|
|
15
|
+
this.collectionName = DAFF_AUTH_IN_MEMORY_COLLECTION_NAME;
|
|
16
|
+
this.customers = {};
|
|
17
|
+
}
|
|
18
|
+
generateToken() {
|
|
19
|
+
return faker.string.alphanumeric(16);
|
|
20
|
+
}
|
|
21
|
+
createDb() {
|
|
22
|
+
return { auth: this.customers };
|
|
23
|
+
}
|
|
24
|
+
post(reqInfo) {
|
|
25
|
+
if (reqInfo.id === "login") return this.login(reqInfo);
|
|
26
|
+
else if (reqInfo.id === "register") return this.register(reqInfo);
|
|
27
|
+
else if (reqInfo.id === "logout") return this.logout(reqInfo);
|
|
28
|
+
else if (reqInfo.id === "check") return this.check(reqInfo);
|
|
29
|
+
else if (reqInfo.id === "resetPassword") return this.resetPassword(reqInfo);
|
|
30
|
+
else if (reqInfo.id === "sendResetEmail") return this.sendResetEmail(reqInfo);
|
|
31
|
+
}
|
|
32
|
+
login(reqInfo) {
|
|
33
|
+
const { email, password } = reqInfo.utils.getJsonBody(reqInfo.req);
|
|
34
|
+
const customer = this.customers[email];
|
|
35
|
+
if (password && customer?.password === password) {
|
|
36
|
+
this.customers[email].token = this.generateToken();
|
|
37
|
+
return reqInfo.utils.createResponse$(() => ({
|
|
38
|
+
body: { token: customer.token },
|
|
39
|
+
status: STATUS.OK
|
|
40
|
+
}));
|
|
41
|
+
}
|
|
42
|
+
return reqInfo.utils.createResponse$(() => ({ status: STATUS.UNAUTHORIZED }));
|
|
43
|
+
}
|
|
44
|
+
register(reqInfo) {
|
|
45
|
+
const { email, password } = reqInfo.utils.getJsonBody(reqInfo.req);
|
|
46
|
+
this.customers[email] = {
|
|
47
|
+
email,
|
|
48
|
+
password
|
|
49
|
+
};
|
|
50
|
+
return reqInfo.utils.createResponse$(() => ({ status: STATUS.CREATED }));
|
|
51
|
+
}
|
|
52
|
+
logout(reqInfo) {
|
|
53
|
+
const { email } = reqInfo.utils.getJsonBody(reqInfo.req);
|
|
54
|
+
if (this.customers[email]) this.customers[email].token = null;
|
|
55
|
+
return reqInfo.utils.createResponse$(() => ({
|
|
56
|
+
body: { success: true },
|
|
57
|
+
status: STATUS.OK
|
|
58
|
+
}));
|
|
59
|
+
}
|
|
60
|
+
check(reqInfo) {
|
|
61
|
+
return reqInfo.utils.createResponse$(() => ({
|
|
62
|
+
body: {},
|
|
63
|
+
status: STATUS.OK
|
|
64
|
+
}));
|
|
65
|
+
}
|
|
66
|
+
resetPassword(reqInfo) {
|
|
67
|
+
const { email, password } = reqInfo.utils.getJsonBody(reqInfo.req);
|
|
68
|
+
if (this.customers[email]) {
|
|
69
|
+
this.customers[email].password = password;
|
|
70
|
+
return reqInfo.utils.createResponse$(() => ({ status: STATUS.OK }));
|
|
71
|
+
}
|
|
72
|
+
return reqInfo.utils.createResponse$(() => ({ status: STATUS.UNAUTHORIZED }));
|
|
73
|
+
}
|
|
74
|
+
sendResetEmail(reqInfo) {
|
|
75
|
+
return reqInfo.utils.createResponse$(() => ({
|
|
76
|
+
body: {},
|
|
77
|
+
status: STATUS.OK
|
|
78
|
+
}));
|
|
79
|
+
}
|
|
80
|
+
static {
|
|
81
|
+
this.ɵfac = i0.ɵɵngDeclareFactory({
|
|
82
|
+
minVersion: "12.0.0",
|
|
83
|
+
version: "22.2.4",
|
|
84
|
+
ngImport: i0,
|
|
85
|
+
type: DaffInMemoryBackendAuthService,
|
|
86
|
+
deps: [],
|
|
87
|
+
target: i0.ɵɵFactoryTarget.Injectable
|
|
88
|
+
});
|
|
89
|
+
}
|
|
90
|
+
static {
|
|
91
|
+
this.ɵprov = i0.ɵɵngDeclareInjectable({
|
|
92
|
+
minVersion: "12.0.0",
|
|
93
|
+
version: "22.2.4",
|
|
94
|
+
ngImport: i0,
|
|
95
|
+
type: DaffInMemoryBackendAuthService,
|
|
96
|
+
providedIn: "root"
|
|
97
|
+
});
|
|
98
|
+
}
|
|
99
|
+
};
|
|
100
|
+
i0.ɵɵngDeclareClassMetadata({
|
|
101
|
+
minVersion: "12.0.0",
|
|
102
|
+
version: "22.2.4",
|
|
103
|
+
ngImport: i0,
|
|
104
|
+
type: DaffInMemoryBackendAuthService,
|
|
105
|
+
decorators: [{
|
|
106
|
+
type: Injectable,
|
|
107
|
+
args: [{ providedIn: "root" }]
|
|
108
|
+
}]
|
|
109
|
+
});
|
|
110
|
+
var DaffInMemoryAuthService = class DaffInMemoryAuthService extends DaffInMemoryDriverBase {
|
|
111
|
+
constructor(http, config) {
|
|
112
|
+
super(config, DAFF_AUTH_IN_MEMORY_COLLECTION_NAME);
|
|
113
|
+
this.http = http;
|
|
114
|
+
}
|
|
115
|
+
check() {
|
|
116
|
+
return this.http.post(`${this.url}/check`, {}).pipe(map(() => void 0));
|
|
117
|
+
}
|
|
118
|
+
static {
|
|
119
|
+
this.ɵfac = i0.ɵɵngDeclareFactory({
|
|
120
|
+
minVersion: "12.0.0",
|
|
121
|
+
version: "22.2.4",
|
|
122
|
+
ngImport: i0,
|
|
123
|
+
type: DaffInMemoryAuthService,
|
|
124
|
+
deps: [{ token: i1.HttpClient }, { token: i2.InMemoryBackendConfig }],
|
|
125
|
+
target: i0.ɵɵFactoryTarget.Injectable
|
|
126
|
+
});
|
|
127
|
+
}
|
|
128
|
+
static {
|
|
129
|
+
this.ɵprov = i0.ɵɵngDeclareInjectable({
|
|
130
|
+
minVersion: "12.0.0",
|
|
131
|
+
version: "22.2.4",
|
|
132
|
+
ngImport: i0,
|
|
133
|
+
type: DaffInMemoryAuthService,
|
|
134
|
+
providedIn: "root"
|
|
135
|
+
});
|
|
136
|
+
}
|
|
137
|
+
};
|
|
138
|
+
i0.ɵɵngDeclareClassMetadata({
|
|
139
|
+
minVersion: "12.0.0",
|
|
140
|
+
version: "22.2.4",
|
|
141
|
+
ngImport: i0,
|
|
142
|
+
type: DaffInMemoryAuthService,
|
|
143
|
+
decorators: [{
|
|
144
|
+
type: Injectable,
|
|
145
|
+
args: [{ providedIn: "root" }]
|
|
146
|
+
}],
|
|
147
|
+
ctorParameters: () => [{ type: i1.HttpClient }, { type: i2.InMemoryBackendConfig }]
|
|
148
|
+
});
|
|
149
|
+
var DaffInMemoryLoginService = class DaffInMemoryLoginService extends DaffInMemoryDriverBase {
|
|
150
|
+
constructor(http, config) {
|
|
151
|
+
super(config, DAFF_AUTH_IN_MEMORY_COLLECTION_NAME);
|
|
152
|
+
this.http = http;
|
|
153
|
+
}
|
|
154
|
+
login(request) {
|
|
155
|
+
return this.http.post(`${this.url}/login`, request);
|
|
156
|
+
}
|
|
157
|
+
logout() {
|
|
158
|
+
return this.http.post(`${this.url}/logout`, {}).pipe(switchMap(({ success }) => success ? of(void 0) : throwError(() => /* @__PURE__ */ new Error("Logout failed"))));
|
|
159
|
+
}
|
|
160
|
+
static {
|
|
161
|
+
this.ɵfac = i0.ɵɵngDeclareFactory({
|
|
162
|
+
minVersion: "12.0.0",
|
|
163
|
+
version: "22.2.4",
|
|
164
|
+
ngImport: i0,
|
|
165
|
+
type: DaffInMemoryLoginService,
|
|
166
|
+
deps: [{ token: i1.HttpClient }, { token: i2.InMemoryBackendConfig }],
|
|
167
|
+
target: i0.ɵɵFactoryTarget.Injectable
|
|
168
|
+
});
|
|
169
|
+
}
|
|
170
|
+
static {
|
|
171
|
+
this.ɵprov = i0.ɵɵngDeclareInjectable({
|
|
172
|
+
minVersion: "12.0.0",
|
|
173
|
+
version: "22.2.4",
|
|
174
|
+
ngImport: i0,
|
|
175
|
+
type: DaffInMemoryLoginService,
|
|
176
|
+
providedIn: "root"
|
|
177
|
+
});
|
|
178
|
+
}
|
|
179
|
+
};
|
|
180
|
+
i0.ɵɵngDeclareClassMetadata({
|
|
181
|
+
minVersion: "12.0.0",
|
|
182
|
+
version: "22.2.4",
|
|
183
|
+
ngImport: i0,
|
|
184
|
+
type: DaffInMemoryLoginService,
|
|
185
|
+
decorators: [{
|
|
186
|
+
type: Injectable,
|
|
187
|
+
args: [{ providedIn: "root" }]
|
|
188
|
+
}],
|
|
189
|
+
ctorParameters: () => [{ type: i1.HttpClient }, { type: i2.InMemoryBackendConfig }]
|
|
190
|
+
});
|
|
191
|
+
var DaffInMemoryRegisterService = class DaffInMemoryRegisterService extends DaffInMemoryDriverBase {
|
|
192
|
+
constructor(http, loginService, config) {
|
|
193
|
+
super(config, DAFF_AUTH_IN_MEMORY_COLLECTION_NAME);
|
|
194
|
+
this.http = http;
|
|
195
|
+
this.loginService = loginService;
|
|
196
|
+
}
|
|
197
|
+
register(registration) {
|
|
198
|
+
return this.registerOnly(registration).pipe(switchMap(() => this.loginService.login({
|
|
199
|
+
email: registration.email,
|
|
200
|
+
password: registration.password
|
|
201
|
+
})), map(({ token }) => token));
|
|
202
|
+
}
|
|
203
|
+
registerOnly(registration) {
|
|
204
|
+
return this.http.post(`${this.url}/register`, registration);
|
|
205
|
+
}
|
|
206
|
+
static {
|
|
207
|
+
this.ɵfac = i0.ɵɵngDeclareFactory({
|
|
208
|
+
minVersion: "12.0.0",
|
|
209
|
+
version: "22.2.4",
|
|
210
|
+
ngImport: i0,
|
|
211
|
+
type: DaffInMemoryRegisterService,
|
|
212
|
+
deps: [
|
|
213
|
+
{ token: i1.HttpClient },
|
|
214
|
+
{ token: DaffInMemoryLoginService },
|
|
215
|
+
{ token: i2.InMemoryBackendConfig }
|
|
216
|
+
],
|
|
217
|
+
target: i0.ɵɵFactoryTarget.Injectable
|
|
218
|
+
});
|
|
219
|
+
}
|
|
220
|
+
static {
|
|
221
|
+
this.ɵprov = i0.ɵɵngDeclareInjectable({
|
|
222
|
+
minVersion: "12.0.0",
|
|
223
|
+
version: "22.2.4",
|
|
224
|
+
ngImport: i0,
|
|
225
|
+
type: DaffInMemoryRegisterService,
|
|
226
|
+
providedIn: "root"
|
|
227
|
+
});
|
|
228
|
+
}
|
|
229
|
+
};
|
|
230
|
+
i0.ɵɵngDeclareClassMetadata({
|
|
231
|
+
minVersion: "12.0.0",
|
|
232
|
+
version: "22.2.4",
|
|
233
|
+
ngImport: i0,
|
|
234
|
+
type: DaffInMemoryRegisterService,
|
|
235
|
+
decorators: [{
|
|
236
|
+
type: Injectable,
|
|
237
|
+
args: [{ providedIn: "root" }]
|
|
238
|
+
}],
|
|
239
|
+
ctorParameters: () => [
|
|
240
|
+
{ type: i1.HttpClient },
|
|
241
|
+
{ type: DaffInMemoryLoginService },
|
|
242
|
+
{ type: i2.InMemoryBackendConfig }
|
|
243
|
+
]
|
|
244
|
+
});
|
|
245
|
+
var DaffInMemoryResetPasswordService = class DaffInMemoryResetPasswordService extends DaffInMemoryDriverBase {
|
|
246
|
+
constructor(http, loginService, config) {
|
|
247
|
+
super(config, DAFF_AUTH_IN_MEMORY_COLLECTION_NAME);
|
|
248
|
+
this.http = http;
|
|
249
|
+
this.loginService = loginService;
|
|
250
|
+
}
|
|
251
|
+
resetPassword(info) {
|
|
252
|
+
return this.resetPasswordOnly(info).pipe(switchMap(() => this.loginService.login({
|
|
253
|
+
email: info.email,
|
|
254
|
+
password: info.password
|
|
255
|
+
})), map(({ token }) => token));
|
|
256
|
+
}
|
|
257
|
+
resetPasswordOnly(info) {
|
|
258
|
+
return this.http.post(`${this.url}/resetPassword`, info);
|
|
259
|
+
}
|
|
260
|
+
sendResetEmail(email) {
|
|
261
|
+
return this.http.post(`${this.url}/sendResetEmail`, { email });
|
|
262
|
+
}
|
|
263
|
+
static {
|
|
264
|
+
this.ɵfac = i0.ɵɵngDeclareFactory({
|
|
265
|
+
minVersion: "12.0.0",
|
|
266
|
+
version: "22.2.4",
|
|
267
|
+
ngImport: i0,
|
|
268
|
+
type: DaffInMemoryResetPasswordService,
|
|
269
|
+
deps: [
|
|
270
|
+
{ token: i1.HttpClient },
|
|
271
|
+
{ token: DaffInMemoryLoginService },
|
|
272
|
+
{ token: i2.InMemoryBackendConfig }
|
|
273
|
+
],
|
|
274
|
+
target: i0.ɵɵFactoryTarget.Injectable
|
|
275
|
+
});
|
|
276
|
+
}
|
|
277
|
+
static {
|
|
278
|
+
this.ɵprov = i0.ɵɵngDeclareInjectable({
|
|
279
|
+
minVersion: "12.0.0",
|
|
280
|
+
version: "22.2.4",
|
|
281
|
+
ngImport: i0,
|
|
282
|
+
type: DaffInMemoryResetPasswordService,
|
|
283
|
+
providedIn: "root"
|
|
284
|
+
});
|
|
285
|
+
}
|
|
286
|
+
};
|
|
287
|
+
i0.ɵɵngDeclareClassMetadata({
|
|
288
|
+
minVersion: "12.0.0",
|
|
289
|
+
version: "22.2.4",
|
|
290
|
+
ngImport: i0,
|
|
291
|
+
type: DaffInMemoryResetPasswordService,
|
|
292
|
+
decorators: [{
|
|
293
|
+
type: Injectable,
|
|
294
|
+
args: [{ providedIn: "root" }]
|
|
295
|
+
}],
|
|
296
|
+
ctorParameters: () => [
|
|
297
|
+
{ type: i1.HttpClient },
|
|
298
|
+
{ type: DaffInMemoryLoginService },
|
|
299
|
+
{ type: i2.InMemoryBackendConfig }
|
|
300
|
+
]
|
|
301
|
+
});
|
|
302
|
+
const provideDaffAuthInMemoryDriver = () => makeEnvironmentProviders([
|
|
303
|
+
provideDaffLoginDriver(DaffInMemoryLoginService),
|
|
304
|
+
provideDaffRegisterDriver(DaffInMemoryRegisterService),
|
|
305
|
+
provideDaffAuthDriver(DaffInMemoryAuthService),
|
|
306
|
+
provideDaffResetPasswordDriver(DaffInMemoryResetPasswordService),
|
|
307
|
+
provideDaffInMemoryBackends(DaffInMemoryBackendAuthService)
|
|
308
|
+
]);
|
|
309
|
+
var DaffAuthInMemoryDriverModule = class DaffAuthInMemoryDriverModule {
|
|
310
|
+
static forRoot() {
|
|
311
|
+
return {
|
|
312
|
+
ngModule: DaffAuthInMemoryDriverModule,
|
|
313
|
+
providers: [provideDaffAuthInMemoryDriver()]
|
|
314
|
+
};
|
|
315
|
+
}
|
|
316
|
+
static {
|
|
317
|
+
this.ɵfac = i0.ɵɵngDeclareFactory({
|
|
318
|
+
minVersion: "12.0.0",
|
|
319
|
+
version: "22.2.4",
|
|
320
|
+
ngImport: i0,
|
|
321
|
+
type: DaffAuthInMemoryDriverModule,
|
|
322
|
+
deps: [],
|
|
323
|
+
target: i0.ɵɵFactoryTarget.NgModule
|
|
324
|
+
});
|
|
325
|
+
}
|
|
326
|
+
static {
|
|
327
|
+
this.ɵmod = i0.ɵɵngDeclareNgModule({
|
|
328
|
+
minVersion: "14.0.0",
|
|
329
|
+
version: "22.2.4",
|
|
330
|
+
ngImport: i0,
|
|
331
|
+
type: DaffAuthInMemoryDriverModule,
|
|
332
|
+
imports: [CommonModule]
|
|
333
|
+
});
|
|
334
|
+
}
|
|
335
|
+
static {
|
|
336
|
+
this.ɵinj = i0.ɵɵngDeclareInjector({
|
|
337
|
+
minVersion: "12.0.0",
|
|
338
|
+
version: "22.2.4",
|
|
339
|
+
ngImport: i0,
|
|
340
|
+
type: DaffAuthInMemoryDriverModule,
|
|
341
|
+
imports: [CommonModule]
|
|
342
|
+
});
|
|
343
|
+
}
|
|
344
|
+
};
|
|
345
|
+
i0.ɵɵngDeclareClassMetadata({
|
|
346
|
+
minVersion: "12.0.0",
|
|
347
|
+
version: "22.2.4",
|
|
348
|
+
ngImport: i0,
|
|
349
|
+
type: DaffAuthInMemoryDriverModule,
|
|
350
|
+
decorators: [{
|
|
351
|
+
type: NgModule,
|
|
352
|
+
args: [{ imports: [CommonModule] }]
|
|
353
|
+
}]
|
|
354
|
+
});
|
|
355
|
+
export { DaffAuthInMemoryDriverModule, DaffInMemoryAuthService, DaffInMemoryBackendAuthService, DaffInMemoryLoginService, DaffInMemoryRegisterService, provideDaffAuthInMemoryDriver };
|
|
12
356
|
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
/**
|
|
16
|
-
* @inheritdoc DaffAuthServiceInterface
|
|
17
|
-
*/
|
|
18
|
-
class DaffInMemoryAuthService extends DaffInMemoryDriverBase {
|
|
19
|
-
constructor(http, config) {
|
|
20
|
-
super(config, DAFF_AUTH_IN_MEMORY_COLLECTION_NAME);
|
|
21
|
-
this.http = http;
|
|
22
|
-
}
|
|
23
|
-
check() {
|
|
24
|
-
return this.http.post(`${this.url}/check`, {}).pipe(map(() => undefined));
|
|
25
|
-
}
|
|
26
|
-
/** @nocollapse */ static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.2.9", ngImport: i0, type: DaffInMemoryAuthService, deps: [{ token: i1.HttpClient }, { token: i2.InMemoryBackendConfig }], target: i0.ɵɵFactoryTarget.Injectable }); }
|
|
27
|
-
/** @nocollapse */ static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "21.2.9", ngImport: i0, type: DaffInMemoryAuthService, providedIn: 'root' }); }
|
|
28
|
-
}
|
|
29
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.9", ngImport: i0, type: DaffInMemoryAuthService, decorators: [{
|
|
30
|
-
type: Injectable,
|
|
31
|
-
args: [{
|
|
32
|
-
providedIn: 'root',
|
|
33
|
-
}]
|
|
34
|
-
}], ctorParameters: () => [{ type: i1.HttpClient }, { type: i2.InMemoryBackendConfig }] });
|
|
35
|
-
|
|
36
|
-
/**
|
|
37
|
-
* @inheritdoc
|
|
38
|
-
*/
|
|
39
|
-
class DaffInMemoryLoginService extends DaffInMemoryDriverBase {
|
|
40
|
-
constructor(http, config) {
|
|
41
|
-
super(config, DAFF_AUTH_IN_MEMORY_COLLECTION_NAME);
|
|
42
|
-
this.http = http;
|
|
43
|
-
}
|
|
44
|
-
login(request) {
|
|
45
|
-
return this.http.post(`${this.url}/login`, request);
|
|
46
|
-
}
|
|
47
|
-
logout() {
|
|
48
|
-
return this.http.post(`${this.url}/logout`, {}).pipe(switchMap(({ success }) => success ? of(undefined) : throwError(() => new Error('Logout failed'))));
|
|
49
|
-
}
|
|
50
|
-
/** @nocollapse */ static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.2.9", ngImport: i0, type: DaffInMemoryLoginService, deps: [{ token: i1.HttpClient }, { token: i2.InMemoryBackendConfig }], target: i0.ɵɵFactoryTarget.Injectable }); }
|
|
51
|
-
/** @nocollapse */ static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "21.2.9", ngImport: i0, type: DaffInMemoryLoginService, providedIn: 'root' }); }
|
|
52
|
-
}
|
|
53
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.9", ngImport: i0, type: DaffInMemoryLoginService, decorators: [{
|
|
54
|
-
type: Injectable,
|
|
55
|
-
args: [{
|
|
56
|
-
providedIn: 'root',
|
|
57
|
-
}]
|
|
58
|
-
}], ctorParameters: () => [{ type: i1.HttpClient }, { type: i2.InMemoryBackendConfig }] });
|
|
59
|
-
|
|
60
|
-
/**
|
|
61
|
-
* @inheritdoc
|
|
62
|
-
*/
|
|
63
|
-
class DaffInMemoryRegisterService extends DaffInMemoryDriverBase {
|
|
64
|
-
constructor(http, loginService, config) {
|
|
65
|
-
super(config, DAFF_AUTH_IN_MEMORY_COLLECTION_NAME);
|
|
66
|
-
this.http = http;
|
|
67
|
-
this.loginService = loginService;
|
|
68
|
-
}
|
|
69
|
-
register(registration) {
|
|
70
|
-
return this.registerOnly(registration).pipe(switchMap(() => this.loginService.login({ email: registration.email, password: registration.password })), map(({ token }) => token));
|
|
71
|
-
}
|
|
72
|
-
registerOnly(registration) {
|
|
73
|
-
return this.http.post(`${this.url}/register`, registration);
|
|
74
|
-
}
|
|
75
|
-
/** @nocollapse */ static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.2.9", ngImport: i0, type: DaffInMemoryRegisterService, deps: [{ token: i1.HttpClient }, { token: DaffInMemoryLoginService }, { token: i2.InMemoryBackendConfig }], target: i0.ɵɵFactoryTarget.Injectable }); }
|
|
76
|
-
/** @nocollapse */ static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "21.2.9", ngImport: i0, type: DaffInMemoryRegisterService, providedIn: 'root' }); }
|
|
77
|
-
}
|
|
78
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.9", ngImport: i0, type: DaffInMemoryRegisterService, decorators: [{
|
|
79
|
-
type: Injectable,
|
|
80
|
-
args: [{
|
|
81
|
-
providedIn: 'root',
|
|
82
|
-
}]
|
|
83
|
-
}], ctorParameters: () => [{ type: i1.HttpClient }, { type: DaffInMemoryLoginService }, { type: i2.InMemoryBackendConfig }] });
|
|
84
|
-
|
|
85
|
-
/**
|
|
86
|
-
* @inheritdoc
|
|
87
|
-
*/
|
|
88
|
-
class DaffInMemoryResetPasswordService extends DaffInMemoryDriverBase {
|
|
89
|
-
constructor(http, loginService, config) {
|
|
90
|
-
super(config, DAFF_AUTH_IN_MEMORY_COLLECTION_NAME);
|
|
91
|
-
this.http = http;
|
|
92
|
-
this.loginService = loginService;
|
|
93
|
-
}
|
|
94
|
-
resetPassword(info) {
|
|
95
|
-
return this.resetPasswordOnly(info).pipe(switchMap(() => this.loginService.login({ email: info.email, password: info.password })), map(({ token }) => token));
|
|
96
|
-
}
|
|
97
|
-
resetPasswordOnly(info) {
|
|
98
|
-
return this.http.post(`${this.url}/resetPassword`, info);
|
|
99
|
-
}
|
|
100
|
-
sendResetEmail(email) {
|
|
101
|
-
return this.http.post(`${this.url}/sendResetEmail`, { email });
|
|
102
|
-
}
|
|
103
|
-
/** @nocollapse */ static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.2.9", ngImport: i0, type: DaffInMemoryResetPasswordService, deps: [{ token: i1.HttpClient }, { token: DaffInMemoryLoginService }, { token: i2.InMemoryBackendConfig }], target: i0.ɵɵFactoryTarget.Injectable }); }
|
|
104
|
-
/** @nocollapse */ static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "21.2.9", ngImport: i0, type: DaffInMemoryResetPasswordService, providedIn: 'root' }); }
|
|
105
|
-
}
|
|
106
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.9", ngImport: i0, type: DaffInMemoryResetPasswordService, decorators: [{
|
|
107
|
-
type: Injectable,
|
|
108
|
-
args: [{
|
|
109
|
-
providedIn: 'root',
|
|
110
|
-
}]
|
|
111
|
-
}], ctorParameters: () => [{ type: i1.HttpClient }, { type: DaffInMemoryLoginService }, { type: i2.InMemoryBackendConfig }] });
|
|
112
|
-
|
|
113
|
-
/**
|
|
114
|
-
* @inheritdoc DaffInMemorySingleRouteableBackend
|
|
115
|
-
*/
|
|
116
|
-
class DaffInMemoryBackendAuthService {
|
|
117
|
-
constructor() {
|
|
118
|
-
this.collectionName = DAFF_AUTH_IN_MEMORY_COLLECTION_NAME;
|
|
119
|
-
this.customers = {};
|
|
120
|
-
}
|
|
121
|
-
generateToken() {
|
|
122
|
-
return faker.string.alphanumeric(16);
|
|
123
|
-
}
|
|
124
|
-
createDb() {
|
|
125
|
-
return {
|
|
126
|
-
auth: this.customers,
|
|
127
|
-
};
|
|
128
|
-
}
|
|
129
|
-
post(reqInfo) {
|
|
130
|
-
if (reqInfo.id === 'login') {
|
|
131
|
-
return this.login(reqInfo);
|
|
132
|
-
}
|
|
133
|
-
else if (reqInfo.id === 'register') {
|
|
134
|
-
return this.register(reqInfo);
|
|
135
|
-
}
|
|
136
|
-
else if (reqInfo.id === 'logout') {
|
|
137
|
-
return this.logout(reqInfo);
|
|
138
|
-
}
|
|
139
|
-
else if (reqInfo.id === 'check') {
|
|
140
|
-
return this.check(reqInfo);
|
|
141
|
-
}
|
|
142
|
-
else if (reqInfo.id === 'resetPassword') {
|
|
143
|
-
return this.resetPassword(reqInfo);
|
|
144
|
-
}
|
|
145
|
-
else if (reqInfo.id === 'sendResetEmail') {
|
|
146
|
-
return this.sendResetEmail(reqInfo);
|
|
147
|
-
}
|
|
148
|
-
}
|
|
149
|
-
login(reqInfo) {
|
|
150
|
-
const { email, password, } = reqInfo.utils.getJsonBody(reqInfo.req);
|
|
151
|
-
const customer = this.customers[email];
|
|
152
|
-
if (password && customer?.password === password) {
|
|
153
|
-
this.customers[email].token = this.generateToken();
|
|
154
|
-
return reqInfo.utils.createResponse$(() => ({
|
|
155
|
-
body: {
|
|
156
|
-
token: customer.token,
|
|
157
|
-
},
|
|
158
|
-
status: STATUS.OK,
|
|
159
|
-
}));
|
|
160
|
-
}
|
|
161
|
-
return reqInfo.utils.createResponse$(() => ({
|
|
162
|
-
status: STATUS.UNAUTHORIZED,
|
|
163
|
-
}));
|
|
164
|
-
}
|
|
165
|
-
register(reqInfo) {
|
|
166
|
-
const { email, password, } = reqInfo.utils.getJsonBody(reqInfo.req);
|
|
167
|
-
this.customers[email] = {
|
|
168
|
-
email,
|
|
169
|
-
password,
|
|
170
|
-
};
|
|
171
|
-
return reqInfo.utils.createResponse$(() => ({
|
|
172
|
-
status: STATUS.CREATED,
|
|
173
|
-
}));
|
|
174
|
-
}
|
|
175
|
-
logout(reqInfo) {
|
|
176
|
-
const { email, } = reqInfo.utils.getJsonBody(reqInfo.req);
|
|
177
|
-
if (this.customers[email]) {
|
|
178
|
-
this.customers[email].token = null;
|
|
179
|
-
}
|
|
180
|
-
return reqInfo.utils.createResponse$(() => ({
|
|
181
|
-
body: { success: true },
|
|
182
|
-
status: STATUS.OK,
|
|
183
|
-
}));
|
|
184
|
-
}
|
|
185
|
-
check(reqInfo) {
|
|
186
|
-
return reqInfo.utils.createResponse$(() => ({
|
|
187
|
-
body: {},
|
|
188
|
-
status: STATUS.OK,
|
|
189
|
-
}));
|
|
190
|
-
}
|
|
191
|
-
resetPassword(reqInfo) {
|
|
192
|
-
const { email, password, } = reqInfo.utils.getJsonBody(reqInfo.req);
|
|
193
|
-
if (this.customers[email]) {
|
|
194
|
-
this.customers[email].password = password;
|
|
195
|
-
return reqInfo.utils.createResponse$(() => ({
|
|
196
|
-
status: STATUS.OK,
|
|
197
|
-
}));
|
|
198
|
-
}
|
|
199
|
-
return reqInfo.utils.createResponse$(() => ({
|
|
200
|
-
status: STATUS.UNAUTHORIZED,
|
|
201
|
-
}));
|
|
202
|
-
}
|
|
203
|
-
sendResetEmail(reqInfo) {
|
|
204
|
-
return reqInfo.utils.createResponse$(() => ({
|
|
205
|
-
body: {},
|
|
206
|
-
status: STATUS.OK,
|
|
207
|
-
}));
|
|
208
|
-
}
|
|
209
|
-
/** @nocollapse */ static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.2.9", ngImport: i0, type: DaffInMemoryBackendAuthService, deps: [], target: i0.ɵɵFactoryTarget.Injectable }); }
|
|
210
|
-
/** @nocollapse */ static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "21.2.9", ngImport: i0, type: DaffInMemoryBackendAuthService, providedIn: 'root' }); }
|
|
211
|
-
}
|
|
212
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.9", ngImport: i0, type: DaffInMemoryBackendAuthService, decorators: [{
|
|
213
|
-
type: Injectable,
|
|
214
|
-
args: [{
|
|
215
|
-
providedIn: 'root',
|
|
216
|
-
}]
|
|
217
|
-
}] });
|
|
218
|
-
|
|
219
|
-
class DaffAuthInMemoryDriverModule {
|
|
220
|
-
static forRoot() {
|
|
221
|
-
return {
|
|
222
|
-
ngModule: DaffAuthInMemoryDriverModule,
|
|
223
|
-
providers: [
|
|
224
|
-
provideDaffLoginDriver(DaffInMemoryLoginService),
|
|
225
|
-
provideDaffRegisterDriver(DaffInMemoryRegisterService),
|
|
226
|
-
provideDaffAuthDriver(DaffInMemoryAuthService),
|
|
227
|
-
provideDaffResetPasswordDriver(DaffInMemoryResetPasswordService),
|
|
228
|
-
provideDaffInMemoryBackends(DaffInMemoryBackendAuthService),
|
|
229
|
-
],
|
|
230
|
-
};
|
|
231
|
-
}
|
|
232
|
-
/** @nocollapse */ static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.2.9", ngImport: i0, type: DaffAuthInMemoryDriverModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule }); }
|
|
233
|
-
/** @nocollapse */ static { this.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "21.2.9", ngImport: i0, type: DaffAuthInMemoryDriverModule, imports: [CommonModule] }); }
|
|
234
|
-
/** @nocollapse */ static { this.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "21.2.9", ngImport: i0, type: DaffAuthInMemoryDriverModule, imports: [CommonModule] }); }
|
|
235
|
-
}
|
|
236
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.9", ngImport: i0, type: DaffAuthInMemoryDriverModule, decorators: [{
|
|
237
|
-
type: NgModule,
|
|
238
|
-
args: [{
|
|
239
|
-
imports: [
|
|
240
|
-
CommonModule,
|
|
241
|
-
],
|
|
242
|
-
}]
|
|
243
|
-
}] });
|
|
244
|
-
|
|
245
|
-
/**
|
|
246
|
-
* Generated bundle index. Do not edit.
|
|
247
|
-
*/
|
|
248
|
-
|
|
249
|
-
export { DaffAuthInMemoryDriverModule, DaffInMemoryAuthService, DaffInMemoryBackendAuthService, DaffInMemoryLoginService, DaffInMemoryRegisterService };
|
|
250
|
-
//# sourceMappingURL=daffodil-auth-driver-in-memory.mjs.map
|
|
357
|
+
//# sourceMappingURL=daffodil-auth-driver-in-memory.mjs.map
|