UNPKG

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