UNPKG

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