1 | (function (global, factory) {
|
2 | typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('@soushians/shared'), require('@soushians/config'), require('@angular/material/snack-bar'), require('@angular/common'), require('@angular/flex-layout'), require('@angular/platform-browser/animations'), require('@angular/forms'), require('@soushians/form'), require('rxjs/add/operator/do'), require('@angular/common/http'), require('@angular/router'), require('rxjs'), require('@angular/material'), require('@ngrx/effects'), require('rxjs/operators'), require('@angular/core'), require('@ngrx/store')) :
|
3 | typeof define === 'function' && define.amd ? define('@soushians/authentication', ['exports', '@soushians/shared', '@soushians/config', '@angular/material/snack-bar', '@angular/common', '@angular/flex-layout', '@angular/platform-browser/animations', '@angular/forms', '@soushians/form', 'rxjs/add/operator/do', '@angular/common/http', '@angular/router', 'rxjs', '@angular/material', '@ngrx/effects', 'rxjs/operators', '@angular/core', '@ngrx/store'], factory) :
|
4 | (factory((global.soushians = global.soushians || {}, global.soushians.authentication = {}),global.shared,global.config,global.ng.material['snack-bar'],global.ng.common,global.ng['flex-layout'],global.ng.platformBrowser.animations,global.ng.forms,global.form,global.rxjs['add/operator/do'],global.ng.common.http,global.ng.router,global.rxjs,global.ng.material,global.effects,global.rxjs.operators,global.ng.core,global.i2));
|
5 | }(this, (function (exports,shared,config,i4,common,flexLayout,animations,forms,form,_do,i1,router,rxjs,material,effects,operators,i0,i2) { 'use strict';
|
6 |
|
7 | |
8 |
|
9 |
|
10 |
|
11 | var UserModel = (function () {
|
12 | function UserModel(params) {
|
13 | var _this = this;
|
14 |
|
15 |
|
16 |
|
17 |
|
18 | this.Roles = [];
|
19 | params &&
|
20 | Object.keys(params).forEach(function (key) {
|
21 | if (key in params)
|
22 | (( (_this)))[key] = params[key];
|
23 | });
|
24 | }
|
25 | return UserModel;
|
26 | }());
|
27 |
|
28 | |
29 |
|
30 |
|
31 |
|
32 |
|
33 | var SignInActionTypes = {
|
34 | WHO_AM_I: "[AUTHENTICATION] who am i",
|
35 | SIGNUP: "[AUTHENTICATION][SIGNUP] start",
|
36 | SIGNUP_SUCCEED: "[AUTHENTICATION][SIGNUP] Success",
|
37 | SIGNUP_FAILURE: "[AUTHENTICATION][SIGNUP] Failure",
|
38 | SIGNIN: "[AUTHENTICATION] Signin",
|
39 | DO_SIGNOUT: "[AUTHENTICATION] Do Signout",
|
40 | SIGNOUT: "[AUTHENTICATION] Signout",
|
41 | SIGNIN_SUCCEED: "[AUTHENTICATION][Signin] Success",
|
42 | SIGNIN_FAILURE: "[AUTHENTICATION][Signin] Failure",
|
43 | SIGNIN_REDIRECT: "[AUTHENTICATION][Signin] Redirect",
|
44 | SIGNIN_REQUIRED: "[AUTHENTICATION][Signin] Required",
|
45 | };
|
46 | var WhoAmIAction = (function () {
|
47 | function WhoAmIAction() {
|
48 | this.type = SignInActionTypes.WHO_AM_I;
|
49 | }
|
50 | return WhoAmIAction;
|
51 | }());
|
52 | |
53 |
|
54 |
|
55 | var |
56 |
|
57 | Signup = (function () {
|
58 | function Signup(payload) {
|
59 | this.payload = payload;
|
60 | this.type = SignInActionTypes.SIGNUP;
|
61 | }
|
62 | return Signup;
|
63 | }());
|
64 | var SignupSecceed = (function () {
|
65 | function SignupSecceed(payload) {
|
66 | this.payload = payload;
|
67 | this.type = SignInActionTypes.SIGNUP_SUCCEED;
|
68 | }
|
69 | return SignupSecceed;
|
70 | }());
|
71 | var SignupFailed = (function () {
|
72 | function SignupFailed(payload) {
|
73 | this.payload = payload;
|
74 | this.type = SignInActionTypes.SIGNUP_FAILURE;
|
75 | }
|
76 | return SignupFailed;
|
77 | }());
|
78 | |
79 |
|
80 |
|
81 | var |
82 |
|
83 | Signin = (function () {
|
84 | function Signin(payload) {
|
85 | this.payload = payload;
|
86 | this.type = SignInActionTypes.SIGNIN;
|
87 | }
|
88 | return Signin;
|
89 | }());
|
90 | var SigninSecceed = (function () {
|
91 | function SigninSecceed(payload) {
|
92 | this.payload = payload;
|
93 | this.type = SignInActionTypes.SIGNIN_SUCCEED;
|
94 | }
|
95 | return SigninSecceed;
|
96 | }());
|
97 | var SigninFailed = (function () {
|
98 | function SigninFailed(payload) {
|
99 | this.payload = payload;
|
100 | this.type = SignInActionTypes.SIGNIN_FAILURE;
|
101 | }
|
102 | return SigninFailed;
|
103 | }());
|
104 | var DoSignoutAction = (function () {
|
105 | function DoSignoutAction() {
|
106 | this.type = SignInActionTypes.DO_SIGNOUT;
|
107 | }
|
108 | return DoSignoutAction;
|
109 | }());
|
110 | var SignoutAction = (function () {
|
111 | function SignoutAction() {
|
112 | this.type = SignInActionTypes.SIGNOUT;
|
113 | }
|
114 | return SignoutAction;
|
115 | }());
|
116 | var SigninRequiredAction = (function () {
|
117 | function SigninRequiredAction() {
|
118 | this.type = SignInActionTypes.SIGNIN_REQUIRED;
|
119 | }
|
120 | return SigninRequiredAction;
|
121 | }());
|
122 |
|
123 | |
124 |
|
125 |
|
126 |
|
127 |
|
128 | var MODULE_DEFAULT_CONFIG = {
|
129 | mode: "cookie-base",
|
130 | token: {
|
131 | time: 24 * 12 * 60 * 60
|
132 | },
|
133 | server: "frontend_server",
|
134 | endpoints: {
|
135 | signOut: "",
|
136 | signOutMethod: "get",
|
137 | signIn: "",
|
138 | signUp: "",
|
139 | whoAmI: ""
|
140 | },
|
141 | forms: {
|
142 | signIn: "",
|
143 | signUp: ""
|
144 | },
|
145 | env: {
|
146 | production: false,
|
147 | frontend_server: "auth/module/frontend_server/did/not/set",
|
148 | server: "auth/module/server/did/not/set"
|
149 | },
|
150 | afterSignoutRedirectTo: "/",
|
151 | signupValidator: function (value) { return rxjs.of(true); },
|
152 | afterSignin: function (user) { },
|
153 | responseToUser: function (user) { return user; }
|
154 | };
|
155 |
|
156 | var MODULE_CONFIG_TOKEN = new i0.InjectionToken("ModuleConfig");
|
157 |
|
158 | |
159 |
|
160 |
|
161 |
|
162 | var AuthenticationConfigurationService = (function () {
|
163 | function AuthenticationConfigurationService(configFile, store) {
|
164 | var _this = this;
|
165 | this.store = store;
|
166 | this.config$ = new rxjs.BehaviorSubject(this._config);
|
167 | this._config = Object.assign({}, MODULE_DEFAULT_CONFIG, configFile);
|
168 | this.config$.next(this._config);
|
169 | this.store.select(config.getAuthenticationModuleConfig).subscribe(function (storeConfig) {
|
170 | if (!storeConfig)
|
171 | return;
|
172 | _this._config = Object.assign({}, _this._config, storeConfig.Config);
|
173 | _this.config$.next(_this._config);
|
174 | });
|
175 | }
|
176 | Object.defineProperty(AuthenticationConfigurationService.prototype, "config", {
|
177 | get: /**
|
178 | * @return {?}
|
179 | */ function () {
|
180 | return this._config;
|
181 | },
|
182 | enumerable: true,
|
183 | configurable: true
|
184 | });
|
185 | AuthenticationConfigurationService.decorators = [
|
186 | { type: i0.Injectable, args: [{
|
187 | providedIn: "root"
|
188 | },] }
|
189 | ];
|
190 |
|
191 | AuthenticationConfigurationService.ctorParameters = function () {
|
192 | return [
|
193 | { type: undefined, decorators: [{ type: i0.Inject, args: [MODULE_CONFIG_TOKEN,] }] },
|
194 | { type: i2.Store }
|
195 | ];
|
196 | };
|
197 | AuthenticationConfigurationService.ngInjectableDef = i0.defineInjectable({ factory: function AuthenticationConfigurationService_Factory() { return new AuthenticationConfigurationService(i0.inject(MODULE_CONFIG_TOKEN), i0.inject(i2.Store)); }, token: AuthenticationConfigurationService, providedIn: "root" });
|
198 | return AuthenticationConfigurationService;
|
199 | }());
|
200 |
|
201 | |
202 |
|
203 |
|
204 |
|
205 | var ProgressingStarted = (function () {
|
206 | function ProgressingStarted() {
|
207 | this.type = "[AUTHENTICATION] PROGRESSING_STARTED" ;
|
208 | }
|
209 | return ProgressingStarted;
|
210 | }());
|
211 | var ProgressingFinished = (function () {
|
212 | function ProgressingFinished() {
|
213 | this.type = "[AUTHENTICATION] PROGRESSING_FINISHED" ;
|
214 | }
|
215 | return ProgressingFinished;
|
216 | }());
|
217 |
|
218 | |
219 |
|
220 |
|
221 |
|
222 |
|
223 | var NEW_CAPTCHA = '[captcha] new captcha';
|
224 | var NewCaptcha = (function () {
|
225 | function NewCaptcha() {
|
226 | this.type = NEW_CAPTCHA;
|
227 | }
|
228 | return NewCaptcha;
|
229 | }());
|
230 |
|
231 | |
232 |
|
233 |
|
234 |
|
235 |
|
236 | |
237 |
|
238 |
|
239 |
|
240 |
|
241 | var COOKIE_NAME = "ngs-authentication";
|
242 | var SigninService = (function () {
|
243 | function SigninService(http, store, configurationService, snackBar) {
|
244 | var _this = this;
|
245 | this.http = http;
|
246 | this.store = store;
|
247 | this.configurationService = configurationService;
|
248 | this.snackBar = snackBar;
|
249 | setTimeout(function () { return _this.store.dispatch(new WhoAmIAction()); }, 300);
|
250 | }
|
251 | |
252 |
|
253 |
|
254 |
|
255 | SigninService.prototype.signup = |
256 |
|
257 |
|
258 |
|
259 | function (model) {
|
260 | var _this = this;
|
261 | return this.configurationService.config$.pipe(operators.filter(function (config$$1) { return config$$1.endpoints.signUp != ""; }), operators.take(1), operators.switchMap(function (config$$1) {
|
262 | return _this.http.post(config$$1.env[config$$1.server] + config$$1.endpoints.signUp, model);
|
263 | }), operators.map(function (response) {
|
264 |
|
265 | var user = Object.assign({}, response.Result);
|
266 | if (user.Role) {
|
267 | user.Roles = [user.Role];
|
268 | }
|
269 | return user;
|
270 | }));
|
271 | };
|
272 | |
273 |
|
274 |
|
275 |
|
276 | SigninService.prototype.signin = |
277 |
|
278 |
|
279 |
|
280 | function (model) {
|
281 | var _this = this;
|
282 | return this.configurationService.config$.pipe(operators.filter(function (config$$1) { return config$$1.endpoints.signIn != ""; }), operators.take(1), operators.switchMap(function (config$$1) { return _this.http.post(config$$1.env[config$$1.server] + config$$1.endpoints.signIn, model); }), operators.map(this.configurationService.config.responseToUser), operators.map(function (user) {
|
283 | if (user.Role) {
|
284 | user.Roles = [user.Role];
|
285 | }
|
286 | return user;
|
287 | }), operators.tap(function (user) {
|
288 | if (_this.configurationService.config.mode == "token-base")
|
289 | shared.Cookie.setCookie(COOKIE_NAME, JSON.stringify(user), _this.configurationService.config.token.time);
|
290 | }), operators.tap(function (user) { return _this.configurationService.config.afterSignin(user); }));
|
291 | };
|
292 |
|
293 |
|
294 | |
295 |
|
296 |
|
297 | SigninService.prototype.signout =
|
298 |
|
299 | |
300 |
|
301 |
|
302 | function () {
|
303 |
|
304 | var config$$1 = this.configurationService.config;
|
305 |
|
306 | var tokenObject = JSON.parse(shared.Cookie.getCookie(COOKIE_NAME));
|
307 |
|
308 | var endpoint = shared.stringTemplate(config$$1.env[config$$1.server] + config$$1.endpoints.signOut, tokenObject);
|
309 |
|
310 | var method = config$$1.endpoints.signOutMethod || "get";
|
311 | if (["get", "put", "post", "patch", "delete"].indexOf(method) === -1) {
|
312 | rxjs.throwError(method + " is not valid http method. [ @starter/authentication/signinservice/singout ]");
|
313 | }
|
314 | return this.http[method](endpoint).pipe(operators.tap(function () {
|
315 | shared.Cookie.deleteCookie(COOKIE_NAME);
|
316 | }));
|
317 | };
|
318 | |
319 |
|
320 |
|
321 | SigninService.prototype.whoAmI = |
322 |
|
323 |
|
324 | function () {
|
325 | var _this = this;
|
326 | debugger;
|
327 |
|
328 | var user = { Token: "--" };
|
329 | if (this.configurationService.config.mode == "token-base") {
|
330 | try {
|
331 | user = JSON.parse(shared.Cookie.getCookie(COOKIE_NAME));
|
332 | }
|
333 | catch (error) { }
|
334 | }
|
335 | return this.configurationService.config$.pipe(operators.filter(function (config$$1) { return config$$1.endpoints.whoAmI != ""; }), operators.take(1), operators.switchMap(function (config$$1) {
|
336 | return _this.http.get(shared.stringTemplate(config$$1.env[config$$1.server] + config$$1.endpoints.whoAmI, { user: user }));
|
337 | }));
|
338 | };
|
339 | SigninService.decorators = [
|
340 | { type: i0.Injectable, args: [{
|
341 | providedIn: "root"
|
342 | },] }
|
343 | ];
|
344 |
|
345 | SigninService.ctorParameters = function () {
|
346 | return [
|
347 | { type: i1.HttpClient },
|
348 | { type: i2.Store },
|
349 | { type: AuthenticationConfigurationService },
|
350 | { type: material.MatSnackBar }
|
351 | ];
|
352 | };
|
353 | SigninService.ngInjectableDef = i0.defineInjectable({ factory: function SigninService_Factory() { return new SigninService(i0.inject(i1.HttpClient), i0.inject(i2.Store), i0.inject(AuthenticationConfigurationService), i0.inject(i4.MatSnackBar)); }, token: SigninService, providedIn: "root" });
|
354 | return SigninService;
|
355 | }());
|
356 |
|
357 | |
358 |
|
359 |
|
360 |
|
361 | var SigninContainerComponent = (function () {
|
362 | function SigninContainerComponent(configurationService, store) {
|
363 | this.configurationService = configurationService;
|
364 | this.store = store;
|
365 | this.signedIn$ = new i0.EventEmitter();
|
366 | this.formId$ = this.configurationService.config$.map(function (config$$1) { return config$$1.forms.signIn; });
|
367 | }
|
368 | |
369 |
|
370 |
|
371 |
|
372 | SigninContainerComponent.prototype.signIn = |
373 |
|
374 |
|
375 |
|
376 | function (formValue) {
|
377 | this.store.dispatch(new Signin(formValue));
|
378 | this.signedIn$.emit(true);
|
379 | };
|
380 | SigninContainerComponent.decorators = [
|
381 | { type: i0.Component, args: [{
|
382 | template: "\n <auth-signin \n [formId]='(formId$ | async)'\n (signedin)=\"signIn($event)\"\n ></auth-signin>\n "
|
383 | }] }
|
384 | ];
|
385 |
|
386 | SigninContainerComponent.ctorParameters = function () {
|
387 | return [
|
388 | { type: AuthenticationConfigurationService },
|
389 | { type: i2.Store }
|
390 | ];
|
391 | };
|
392 | SigninContainerComponent.propDecorators = {
|
393 | signedIn$: [{ type: i0.Output }]
|
394 | };
|
395 | return SigninContainerComponent;
|
396 | }());
|
397 |
|
398 | |
399 |
|
400 |
|
401 |
|
402 | var AuthenticationContainerComponent = (function () {
|
403 | function AuthenticationContainerComponent() {
|
404 | }
|
405 | AuthenticationContainerComponent.decorators = [
|
406 | { type: i0.Component, args: [{
|
407 | template: "\n <router-outlet></router-outlet>\n "
|
408 | }] }
|
409 | ];
|
410 | return AuthenticationContainerComponent;
|
411 | }());
|
412 |
|
413 | |
414 |
|
415 |
|
416 |
|
417 | var SignupContainerComponent = (function () {
|
418 | function SignupContainerComponent(configurationService, store, snackBar) {
|
419 | this.configurationService = configurationService;
|
420 | this.store = store;
|
421 | this.snackBar = snackBar;
|
422 | this.signedUp$ = new i0.EventEmitter();
|
423 | this.formId$ = this.configurationService.config$.map(function (config$$1) { return config$$1.forms.signUp; });
|
424 | }
|
425 | |
426 |
|
427 |
|
428 |
|
429 | SignupContainerComponent.prototype.signup = |
430 |
|
431 |
|
432 |
|
433 | function (formValue) {
|
434 | var _this = this;
|
435 | this.configurationService.config$
|
436 | .pipe(operators.take(1), operators.switchMap(function (config$$1) { return config$$1.signupValidator(formValue); }))
|
437 | .subscribe(function (validation) {
|
438 | if (validation) {
|
439 | _this.store.dispatch(new Signup(formValue));
|
440 | _this.signedUp$.emit(true);
|
441 | }
|
442 | else {
|
443 | _this.snackBar.open("رمز عبور یکسان نیست", null, {
|
444 | duration: 2222
|
445 | });
|
446 | }
|
447 | });
|
448 | };
|
449 | SignupContainerComponent.decorators = [
|
450 | { type: i0.Component, args: [{
|
451 | template: "\n <auth-signup \n [formId]='(formId$ | async)'\n (signedup)=\"signup($event)\"\n ></auth-signup>\n "
|
452 | }] }
|
453 | ];
|
454 |
|
455 | SignupContainerComponent.ctorParameters = function () {
|
456 | return [
|
457 | { type: AuthenticationConfigurationService },
|
458 | { type: i2.Store },
|
459 | { type: material.MatSnackBar }
|
460 | ];
|
461 | };
|
462 | SignupContainerComponent.propDecorators = {
|
463 | signedUp$: [{ type: i0.Output }]
|
464 | };
|
465 | return SignupContainerComponent;
|
466 | }());
|
467 |
|
468 | |
469 |
|
470 |
|
471 |
|
472 |
|
473 | var routes = [
|
474 | {
|
475 | path: "auth",
|
476 | component: AuthenticationContainerComponent,
|
477 | children: [
|
478 | {
|
479 | path: "signin",
|
480 |
|
481 | component: SigninContainerComponent
|
482 | },
|
483 | {
|
484 | path: "signup",
|
485 |
|
486 | component: SignupContainerComponent
|
487 | }
|
488 | ]
|
489 | }
|
490 | ];
|
491 |
|
492 | var AuthenticationRoutingModule = router.RouterModule.forChild(routes);
|
493 |
|
494 | |
495 |
|
496 |
|
497 |
|
498 | var SigninComponent = (function () {
|
499 | function SigninComponent() {
|
500 | this.signedin = new i0.EventEmitter();
|
501 | }
|
502 | |
503 |
|
504 |
|
505 |
|
506 | SigninComponent.prototype.signin = |
507 |
|
508 |
|
509 |
|
510 | function (formGroup) {
|
511 | if (!formGroup.valid)
|
512 | return;
|
513 | this.signedin.emit(formGroup.value);
|
514 | };
|
515 | SigninComponent.decorators = [
|
516 | { type: i0.Component, args: [{
|
517 | selector: "auth-signin",
|
518 | template: "<div fxLayout='row' fxLayoutAlign=\"center center\">\r\n <ngs-form-view \r\n [id]=\"formId\"\r\n [card]=\"true\"\r\n (accept)=\"signin($event)\"\r\n ></ngs-form-view>\r\n</div>\r\n<!-- <div>\r\n <a fxFlex=\"nogrow\" routerLink=\"/user/password/reset\" mat-raised-button fxFlexFill>\u06A9\u0644\u0645\u0647 \u0639\u0628\u0648\u0631 \u062E\u0648\u062F \u0631\u0627 \u0641\u0631\u0627\u0645\u0648\u0634 \u06A9\u0631\u062F\u0647 \u0627\u06CC\u062F\u061F</a>\r\n</div> -->",
|
519 | styles: [""]
|
520 | }] }
|
521 | ];
|
522 |
|
523 | SigninComponent.ctorParameters = function () { return []; };
|
524 | SigninComponent.propDecorators = {
|
525 | signedin: [{ type: i0.Output }],
|
526 | formId: [{ type: i0.Input }]
|
527 | };
|
528 | return SigninComponent;
|
529 | }());
|
530 |
|
531 | |
532 |
|
533 |
|
534 |
|
535 |
|
536 | var WithCredentialInterceptor = (function () {
|
537 | function WithCredentialInterceptor(configurationService) {
|
538 | this.configurationService = configurationService;
|
539 | }
|
540 | |
541 |
|
542 |
|
543 |
|
544 |
|
545 | WithCredentialInterceptor.prototype.intercept = |
546 |
|
547 |
|
548 |
|
549 |
|
550 | function (request, next) {
|
551 |
|
552 | (( (request))).withCredentials = true;
|
553 | return next.handle(request);
|
554 | };
|
555 | WithCredentialInterceptor.decorators = [
|
556 | { type: i0.Injectable }
|
557 | ];
|
558 |
|
559 | WithCredentialInterceptor.ctorParameters = function () {
|
560 | return [
|
561 | { type: AuthenticationConfigurationService }
|
562 | ];
|
563 | };
|
564 | return WithCredentialInterceptor;
|
565 | }());
|
566 |
|
567 | |
568 |
|
569 |
|
570 |
|
571 | var UnauthorizedInterceptor = (function () {
|
572 | function UnauthorizedInterceptor(router$$1, store // private signinService: SigninService
|
573 | ) {
|
574 | this.router = router$$1;
|
575 | this.store = store;
|
576 | }
|
577 | |
578 |
|
579 |
|
580 |
|
581 |
|
582 | UnauthorizedInterceptor.prototype.intercept = |
583 |
|
584 |
|
585 |
|
586 |
|
587 | function (request, next) {
|
588 | var _this = this;
|
589 | return next
|
590 | .handle(request)
|
591 | .map(function (event) {
|
592 | if (event instanceof i1.HttpResponse)
|
593 | return event;
|
594 | })
|
595 | .catch(function (err) {
|
596 | if (!(err instanceof i1.HttpErrorResponse))
|
597 | return rxjs.throwError(err);
|
598 | if (err.status != 401)
|
599 | return rxjs.throwError(err);
|
600 | if (err.url.includes("logout"))
|
601 | return rxjs.throwError(err);
|
602 | if (err.url.includes("user/account/profile"))
|
603 | return rxjs.throwError(err);
|
604 | _this.store.dispatch(new SignoutAction());
|
605 | return rxjs.throwError("Unauthorized");
|
606 | });
|
607 | };
|
608 | UnauthorizedInterceptor.decorators = [
|
609 | { type: i0.Injectable }
|
610 | ];
|
611 |
|
612 | UnauthorizedInterceptor.ctorParameters = function () {
|
613 | return [
|
614 | { type: router.Router },
|
615 | { type: i2.Store }
|
616 | ];
|
617 | };
|
618 | return UnauthorizedInterceptor;
|
619 | }());
|
620 |
|
621 | |
622 |
|
623 |
|
624 |
|
625 |
|
626 |
|
627 |
|
628 |
|
629 |
|
630 |
|
631 |
|
632 |
|
633 |
|
634 |
|
635 | var __assign = function () {
|
636 | __assign = Object.assign || function __assign(t) {
|
637 | for (var s, i = 1, n = arguments.length; i < n; i++) {
|
638 | s = arguments[i];
|
639 | for (var p in s)
|
640 | if (Object.prototype.hasOwnProperty.call(s, p))
|
641 | t[p] = s[p];
|
642 | }
|
643 | return t;
|
644 | };
|
645 | return __assign.apply(this, arguments);
|
646 | };
|
647 | function __decorate(decorators, target, key, desc) {
|
648 | var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
649 | if (typeof Reflect === "object" && typeof Reflect.decorate === "function")
|
650 | r = Reflect.decorate(decorators, target, key, desc);
|
651 | else
|
652 | for (var i = decorators.length - 1; i >= 0; i--)
|
653 | if (d = decorators[i])
|
654 | r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
655 | return c > 3 && r && Object.defineProperty(target, key, r), r;
|
656 | }
|
657 | function __metadata(metadataKey, metadataValue) {
|
658 | if (typeof Reflect === "object" && typeof Reflect.metadata === "function")
|
659 | return Reflect.metadata(metadataKey, metadataValue);
|
660 | }
|
661 |
|
662 | |
663 |
|
664 |
|
665 |
|
666 |
|
667 | var initialState = {
|
668 | loggedIn: false,
|
669 | user: new UserModel({ Id: 1 })
|
670 | };
|
671 | |
672 |
|
673 |
|
674 |
|
675 |
|
676 | function UserReducer(state, action) {
|
677 | if (state === void 0) {
|
678 | state = initialState;
|
679 | }
|
680 | switch (action.type) {
|
681 | case SignInActionTypes.SIGNIN_SUCCEED: {
|
682 | return __assign({}, state, { loggedIn: true, user: action.payload });
|
683 | }
|
684 | case SignInActionTypes.SIGNOUT: {
|
685 | return __assign({}, state, { loggedIn: false, user: new UserModel() });
|
686 | }
|
687 | default: {
|
688 | return state;
|
689 | }
|
690 | }
|
691 | }
|
692 |
|
693 |
|
694 | var getLoggedIn = function (state) { return state.loggedIn; };
|
695 |
|
696 | var getUser = function (state) { return state.user; };
|
697 |
|
698 | |
699 |
|
700 |
|
701 |
|
702 |
|
703 | var AuthenticationReducers = {
|
704 | userStatus: UserReducer
|
705 |
|
706 | };
|
707 |
|
708 |
|
709 | var selectAuthenticationState = i2.createFeatureSelector("authentication");
|
710 |
|
711 | var selectAuthState = i2.createSelector(selectAuthenticationState, function (state) { return state.userStatus; });
|
712 |
|
713 | var getLoggedIn$1 = i2.createSelector(selectAuthState, getLoggedIn);
|
714 |
|
715 | var getUser$1 = i2.createSelector(selectAuthState, getUser);
|
716 |
|
717 | |
718 |
|
719 |
|
720 |
|
721 |
|
722 | |
723 |
|
724 |
|
725 |
|
726 | var SigninEffects = (function () {
|
727 | function SigninEffects(actions$, router$$1, signinService, configurationService, bottomSheet) {
|
728 | var _this = this;
|
729 | this.actions$ = actions$;
|
730 | this.router = router$$1;
|
731 | this.signinService = signinService;
|
732 | this.configurationService = configurationService;
|
733 | this.bottomSheet = bottomSheet;
|
734 | this.whoAmI$ = this.actions$.pipe(effects.ofType(SignInActionTypes.WHO_AM_I), operators.switchMap(function () {
|
735 | return _this.signinService
|
736 | .whoAmI()
|
737 | .pipe(operators.map(function (user) { return new SigninSecceed(user); }), operators.catchError(function (error) { return rxjs.of(new SigninFailed(error)); }));
|
738 | }));
|
739 | this.Signin$ = this.actions$.pipe(effects.ofType(SignInActionTypes.SIGNIN), operators.pluck("payload"), operators.switchMap(function (payload) {
|
740 | return _this.signinService
|
741 | .signin(payload)
|
742 | .pipe(operators.map(function (user) { return new SigninSecceed(user); }), operators.catchError(function (error) { return rxjs.of(new SigninFailed(error)); }));
|
743 | }));
|
744 | this.signup$ = this.actions$.pipe(effects.ofType(SignInActionTypes.SIGNUP), operators.pluck("payload"), operators.switchMap(function (payload) {
|
745 | return _this.signinService
|
746 | .signup(payload)
|
747 | .pipe(operators.map(function (user) { return new SignupSecceed(user); }), operators.catchError(function (error) { return rxjs.of(new SignupFailed(error)); }));
|
748 | }));
|
749 | this.signupSucceed$ = this.actions$.pipe(effects.ofType(SignInActionTypes.SIGNUP_SUCCEED), operators.tap(function () {
|
750 | debugger;
|
751 | _this.router.navigate(["auth/signin"]);
|
752 | }));
|
753 | this.SignInRequired$ = this.actions$.pipe(effects.ofType(SignInActionTypes.SIGNIN_REQUIRED), operators.tap(function (data) {
|
754 |
|
755 | var signinBottomSheetRef = _this.bottomSheet.open(SigninContainerComponent, {
|
756 | panelClass: "clear-mat-card-box"
|
757 | });
|
758 | signinBottomSheetRef.instance.signedIn$.subscribe(function () {
|
759 | signinBottomSheetRef.dismiss();
|
760 | });
|
761 | return signinBottomSheetRef;
|
762 | }));
|
763 | this.SigninSucceed$ = this.actions$.pipe(effects.ofType(SignInActionTypes.SIGNIN_SUCCEED), operators.tap(function (data) {
|
764 | if (location.pathname.indexOf("signin") > -1)
|
765 | _this.router.navigate(["/"]);
|
766 | }));
|
767 | this.AfterSigninFiled$ = this.actions$.pipe(effects.ofType(SignInActionTypes.SIGNIN_FAILURE), operators.map(function () { return new NewCaptcha(); }));
|
768 | this.DoSignout$ = this.actions$.pipe(effects.ofType(SignInActionTypes.DO_SIGNOUT), operators.switchMap(function (data) {
|
769 | return _this.signinService.signout().pipe(operators.map(function () { return new SignoutAction(); }), operators.catchError(function (err) {
|
770 |
|
771 | debugger;
|
772 | return rxjs.of(err);
|
773 | }));
|
774 | }));
|
775 |
|
776 |
|
777 | this.redirectToLoginPage$ = this.actions$.pipe(effects.ofType(SignInActionTypes.SIGNIN_REDIRECT), operators.tap(function (authed) { return _this.router.navigate(["auth/signin"]); }));
|
778 | this.redirectAfterSignout$ = this.actions$.pipe(effects.ofType(SignInActionTypes.SIGNOUT), operators.tap(function (authed) { return _this.router.navigate([_this.configurationService.config$.getValue().afterSignoutRedirectTo]); }));
|
779 | }
|
780 | SigninEffects.decorators = [
|
781 | { type: i0.Injectable }
|
782 | ];
|
783 |
|
784 | SigninEffects.ctorParameters = function () {
|
785 | return [
|
786 | { type: effects.Actions },
|
787 | { type: router.Router },
|
788 | { type: SigninService },
|
789 | { type: AuthenticationConfigurationService },
|
790 | { type: material.MatBottomSheet }
|
791 | ];
|
792 | };
|
793 | __decorate([
|
794 | effects.Effect(),
|
795 | __metadata("design:type", Object)
|
796 | ], SigninEffects.prototype, "whoAmI$", void 0);
|
797 | __decorate([
|
798 | effects.Effect(),
|
799 | __metadata("design:type", Object)
|
800 | ], SigninEffects.prototype, "Signin$", void 0);
|
801 | __decorate([
|
802 | effects.Effect(),
|
803 | __metadata("design:type", Object)
|
804 | ], SigninEffects.prototype, "signup$", void 0);
|
805 | __decorate([
|
806 | effects.Effect({ dispatch: false }),
|
807 | __metadata("design:type", Object)
|
808 | ], SigninEffects.prototype, "signupSucceed$", void 0);
|
809 | __decorate([
|
810 | effects.Effect({ dispatch: false }),
|
811 | __metadata("design:type", Object)
|
812 | ], SigninEffects.prototype, "SignInRequired$", void 0);
|
813 | __decorate([
|
814 | effects.Effect({ dispatch: false }),
|
815 | __metadata("design:type", Object)
|
816 | ], SigninEffects.prototype, "SigninSucceed$", void 0);
|
817 | __decorate([
|
818 | effects.Effect(),
|
819 | __metadata("design:type", Object)
|
820 | ], SigninEffects.prototype, "AfterSigninFiled$", void 0);
|
821 | __decorate([
|
822 | effects.Effect(),
|
823 | __metadata("design:type", Object)
|
824 | ], SigninEffects.prototype, "DoSignout$", void 0);
|
825 | __decorate([
|
826 | effects.Effect({ dispatch: false }),
|
827 | __metadata("design:type", Object)
|
828 | ], SigninEffects.prototype, "redirectToLoginPage$", void 0);
|
829 | __decorate([
|
830 | effects.Effect({ dispatch: false }),
|
831 | __metadata("design:type", Object)
|
832 | ], SigninEffects.prototype, "redirectAfterSignout$", void 0);
|
833 | return SigninEffects;
|
834 | }());
|
835 |
|
836 | |
837 |
|
838 |
|
839 |
|
840 | var AuthenticationEffects = (function () {
|
841 | function AuthenticationEffects(actions$) {
|
842 | this.actions$ = actions$;
|
843 | this.dispachProgressingStarted$ = this.actions$.pipe(effects.ofType(SignInActionTypes.SIGNIN), operators.map(function () { return new ProgressingStarted(); }));
|
844 | this.dispachProgressingFinished$ = this.actions$.pipe(effects.ofType(SignInActionTypes.SIGNIN_FAILURE, SignInActionTypes.SIGNIN_SUCCEED), operators.map(function () { return new ProgressingFinished(); }));
|
845 | }
|
846 | AuthenticationEffects.decorators = [
|
847 | { type: i0.Injectable }
|
848 | ];
|
849 |
|
850 | AuthenticationEffects.ctorParameters = function () {
|
851 | return [
|
852 | { type: effects.Actions }
|
853 | ];
|
854 | };
|
855 | __decorate([
|
856 | effects.Effect(),
|
857 | __metadata("design:type", Object)
|
858 | ], AuthenticationEffects.prototype, "dispachProgressingStarted$", void 0);
|
859 | __decorate([
|
860 | effects.Effect(),
|
861 | __metadata("design:type", Object)
|
862 | ], AuthenticationEffects.prototype, "dispachProgressingFinished$", void 0);
|
863 | return AuthenticationEffects;
|
864 | }());
|
865 |
|
866 | |
867 |
|
868 |
|
869 |
|
870 | var SignupComponent = (function () {
|
871 | function SignupComponent() {
|
872 | this.signedup = new i0.EventEmitter();
|
873 | }
|
874 | |
875 |
|
876 |
|
877 |
|
878 | SignupComponent.prototype.signup = |
879 |
|
880 |
|
881 |
|
882 | function (formGroup) {
|
883 | if (!formGroup.valid)
|
884 | return;
|
885 | this.signedup.emit(formGroup.value);
|
886 | };
|
887 | SignupComponent.decorators = [
|
888 | { type: i0.Component, args: [{
|
889 | selector: "auth-signup",
|
890 | template: "<div fxLayout='row' fxLayoutAlign=\"center center\">\r\n <ngs-form-view \r\n [id]=\"formId\"\r\n [card]=\"true\"\r\n (accept)=\"signup($event)\"\r\n ></ngs-form-view>\r\n</div>\r\n<!-- <div>\r\n <a fxFlex=\"nogrow\" routerLink=\"/user/password/reset\" mat-raised-button fxFlexFill>\u06A9\u0644\u0645\u0647 \u0639\u0628\u0648\u0631 \u062E\u0648\u062F \u0631\u0627 \u0641\u0631\u0627\u0645\u0648\u0634 \u06A9\u0631\u062F\u0647 \u0627\u06CC\u062F\u061F</a>\r\n</div> -->",
|
891 | styles: [""]
|
892 | }] }
|
893 | ];
|
894 |
|
895 | SignupComponent.ctorParameters = function () { return []; };
|
896 | SignupComponent.propDecorators = {
|
897 | signedup: [{ type: i0.Output }],
|
898 | formId: [{ type: i0.Input }]
|
899 | };
|
900 | return SignupComponent;
|
901 | }());
|
902 |
|
903 | |
904 |
|
905 |
|
906 |
|
907 | var SigninGuard = (function () {
|
908 | function SigninGuard(store) {
|
909 | this.store = store;
|
910 | }
|
911 | |
912 |
|
913 |
|
914 |
|
915 |
|
916 | SigninGuard.prototype.canActivate = |
917 |
|
918 |
|
919 |
|
920 |
|
921 | function (route, state) {
|
922 | return this.store.select(getLoggedIn$1).take(1).map(function (authed) { return !authed; });
|
923 | };
|
924 | SigninGuard.decorators = [
|
925 | { type: i0.Injectable }
|
926 | ];
|
927 |
|
928 | SigninGuard.ctorParameters = function () {
|
929 | return [
|
930 | { type: i2.Store }
|
931 | ];
|
932 | };
|
933 | return SigninGuard;
|
934 | }());
|
935 |
|
936 | |
937 |
|
938 |
|
939 |
|
940 | var NgsAuthenticationModule = (function () {
|
941 | function NgsAuthenticationModule() {
|
942 | }
|
943 | |
944 |
|
945 |
|
946 |
|
947 | NgsAuthenticationModule.forRoot = |
948 |
|
949 |
|
950 |
|
951 | function (config$$1) {
|
952 | if (config$$1 === void 0) {
|
953 | config$$1 = ( ({}));
|
954 | }
|
955 | return {
|
956 | ngModule: RootNgsAuthenticationModule,
|
957 | providers: [
|
958 | { provide: MODULE_CONFIG_TOKEN, useValue: config$$1 },
|
959 | {
|
960 | provide: i1.HTTP_INTERCEPTORS,
|
961 | useClass: UnauthorizedInterceptor,
|
962 | multi: true
|
963 | },
|
964 | {
|
965 | provide: i1.HTTP_INTERCEPTORS,
|
966 | useClass: WithCredentialInterceptor,
|
967 | multi: true
|
968 | },
|
969 | SigninService
|
970 | ]
|
971 | };
|
972 | };
|
973 | NgsAuthenticationModule.decorators = [
|
974 | { type: i0.NgModule, args: [{
|
975 | imports: [
|
976 | common.CommonModule,
|
977 | router.RouterModule,
|
978 | forms.FormsModule,
|
979 | i1.HttpClientModule,
|
980 | flexLayout.FlexLayoutModule,
|
981 | material.MatIconModule,
|
982 | material.MatButtonModule,
|
983 | material.MatCardModule,
|
984 | material.MatSnackBarModule,
|
985 | material.MatSidenavModule,
|
986 | material.MatExpansionModule,
|
987 | material.MatSelectModule,
|
988 | material.MatBottomSheetModule,
|
989 | material.MatFormFieldModule,
|
990 | material.MatListModule,
|
991 | material.MatMenuModule,
|
992 | material.MatRadioModule,
|
993 | material.MatInputModule,
|
994 | material.MatToolbarModule,
|
995 | material.MatDatepickerModule,
|
996 | material.MatProgressBarModule,
|
997 | animations.BrowserAnimationsModule,
|
998 | forms.ReactiveFormsModule,
|
999 | forms.FormsModule,
|
1000 | form.NgsFormModule
|
1001 | ],
|
1002 | declarations: [
|
1003 | SigninContainerComponent,
|
1004 | SigninComponent,
|
1005 | AuthenticationContainerComponent,
|
1006 | SignupContainerComponent,
|
1007 | SignupComponent
|
1008 | ],
|
1009 | entryComponents: [SigninContainerComponent],
|
1010 | providers: [SigninGuard],
|
1011 | exports: []
|
1012 | },] }
|
1013 | ];
|
1014 | return NgsAuthenticationModule;
|
1015 | }());
|
1016 | var RootNgsAuthenticationModule = (function () {
|
1017 | function RootNgsAuthenticationModule() {
|
1018 | (( (window))).___starter = (( (window))).___starter || {};
|
1019 | (( (window))).___starter.authentication = "7.8.0";
|
1020 | }
|
1021 | RootNgsAuthenticationModule.decorators = [
|
1022 | { type: i0.NgModule, args: [{
|
1023 | imports: [
|
1024 | i2.StoreModule.forFeature("authentication", AuthenticationReducers),
|
1025 | effects.EffectsModule.forFeature([SigninEffects, AuthenticationEffects]),
|
1026 | AuthenticationRoutingModule,
|
1027 | NgsAuthenticationModule
|
1028 | ]
|
1029 | },] }
|
1030 | ];
|
1031 |
|
1032 | RootNgsAuthenticationModule.ctorParameters = function () { return []; };
|
1033 | return RootNgsAuthenticationModule;
|
1034 | }());
|
1035 |
|
1036 | |
1037 |
|
1038 |
|
1039 |
|
1040 |
|
1041 | |
1042 |
|
1043 |
|
1044 |
|
1045 |
|
1046 | exports.UserModel = UserModel;
|
1047 | exports.SignInActionTypes = SignInActionTypes;
|
1048 | exports.DoSignoutAction = DoSignoutAction;
|
1049 | exports.SigninRequiredAction = SigninRequiredAction;
|
1050 | exports.SigninService = SigninService;
|
1051 | exports.SigninContainerComponent = SigninContainerComponent;
|
1052 | exports.NgsAuthenticationModule = NgsAuthenticationModule;
|
1053 | exports.getUser = getUser$1;
|
1054 | exports.ɵr = AuthenticationRoutingModule;
|
1055 | exports.ɵa = MODULE_CONFIG_TOKEN;
|
1056 | exports.ɵb = RootNgsAuthenticationModule;
|
1057 | exports.ɵi = SigninComponent;
|
1058 | exports.ɵl = SignupComponent;
|
1059 | exports.ɵq = AuthenticationEffects;
|
1060 | exports.ɵp = SigninEffects;
|
1061 | exports.ɵs = UnauthorizedInterceptor;
|
1062 | exports.ɵt = WithCredentialInterceptor;
|
1063 | exports.ɵc = AuthenticationReducers;
|
1064 | exports.ɵe = selectAuthState;
|
1065 | exports.ɵd = selectAuthenticationState;
|
1066 | exports.ɵn = UserReducer;
|
1067 | exports.ɵo = getUser;
|
1068 | exports.ɵm = SigninGuard;
|
1069 | exports.ɵh = AuthenticationConfigurationService;
|
1070 | exports.ɵj = AuthenticationContainerComponent;
|
1071 | exports.ɵk = SignupContainerComponent;
|
1072 |
|
1073 | Object.defineProperty(exports, '__esModule', { value: true });
|
1074 |
|
1075 | })));
|
1076 |
|
1077 |
|
\ | No newline at end of file |