1 | import { stringTemplate, Cookie } from '@soushians/shared';
|
2 | import { getAuthenticationModuleConfig } from '@soushians/config';
|
3 | import { MatSnackBar as MatSnackBar$1 } from '@angular/material/snack-bar';
|
4 | import { CommonModule } from '@angular/common';
|
5 | import { FlexLayoutModule } from '@angular/flex-layout';
|
6 | import { BrowserAnimationsModule } from '@angular/platform-browser/animations';
|
7 | import { FormsModule, ReactiveFormsModule } from '@angular/forms';
|
8 | import { NgsFormModule } from '@soushians/form';
|
9 | import 'rxjs/add/operator/do';
|
10 | import { HttpClient, HttpResponse, HttpErrorResponse, HTTP_INTERCEPTORS, HttpClientModule } from '@angular/common/http';
|
11 | import { RouterModule, Router } from '@angular/router';
|
12 | import { of, BehaviorSubject, throwError } from 'rxjs';
|
13 | import { MatSnackBar, MatBottomSheet, MatIconModule, MatButtonModule, MatCardModule, MatSnackBarModule, MatSidenavModule, MatExpansionModule, MatSelectModule, MatFormFieldModule, MatListModule, MatMenuModule, MatRadioModule, MatInputModule, MatToolbarModule, MatDatepickerModule, MatProgressBarModule, MatBottomSheetModule } from '@angular/material';
|
14 | import { __decorate, __metadata, __assign } from 'tslib';
|
15 | import { Actions, Effect, ofType, EffectsModule } from '@ngrx/effects';
|
16 | import { map, switchMap, take, filter, tap, catchError, pluck } from 'rxjs/operators';
|
17 | import { InjectionToken, Injectable, Inject, NgModule, Component, Input, Output, EventEmitter, defineInjectable, inject } from '@angular/core';
|
18 | import { Store, createSelector, createFeatureSelector, StoreModule } from '@ngrx/store';
|
19 |
|
20 |
|
21 |
|
22 |
|
23 |
|
24 | var UserModel = (function () {
|
25 | function UserModel(params) {
|
26 | var _this = this;
|
27 |
|
28 |
|
29 |
|
30 |
|
31 | this.Roles = [];
|
32 | params &&
|
33 | Object.keys(params).forEach(function (key) {
|
34 | if (key in params)
|
35 | (( (_this)))[key] = params[key];
|
36 | });
|
37 | }
|
38 | return UserModel;
|
39 | }());
|
40 |
|
41 |
|
42 |
|
43 |
|
44 |
|
45 |
|
46 | var 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 | };
|
59 | var WhoAmIAction = (function () {
|
60 | function WhoAmIAction() {
|
61 | this.type = SignInActionTypes.WHO_AM_I;
|
62 | }
|
63 | return WhoAmIAction;
|
64 | }());
|
65 |
|
66 |
|
67 |
|
68 | var |
69 |
|
70 |
|
71 | Signup = (function () {
|
72 | function Signup(payload) {
|
73 | this.payload = payload;
|
74 | this.type = SignInActionTypes.SIGNUP;
|
75 | }
|
76 | return Signup;
|
77 | }());
|
78 | var SignupSecceed = (function () {
|
79 | function SignupSecceed(payload) {
|
80 | this.payload = payload;
|
81 | this.type = SignInActionTypes.SIGNUP_SUCCEED;
|
82 | }
|
83 | return SignupSecceed;
|
84 | }());
|
85 | var SignupFailed = (function () {
|
86 | function SignupFailed(payload) {
|
87 | this.payload = payload;
|
88 | this.type = SignInActionTypes.SIGNUP_FAILURE;
|
89 | }
|
90 | return SignupFailed;
|
91 | }());
|
92 |
|
93 |
|
94 |
|
95 | var |
96 |
|
97 |
|
98 | Signin = (function () {
|
99 | function Signin(payload) {
|
100 | this.payload = payload;
|
101 | this.type = SignInActionTypes.SIGNIN;
|
102 | }
|
103 | return Signin;
|
104 | }());
|
105 | var SigninSecceed = (function () {
|
106 | function SigninSecceed(payload) {
|
107 | this.payload = payload;
|
108 | this.type = SignInActionTypes.SIGNIN_SUCCEED;
|
109 | }
|
110 | return SigninSecceed;
|
111 | }());
|
112 | var SigninFailed = (function () {
|
113 | function SigninFailed(payload) {
|
114 | this.payload = payload;
|
115 | this.type = SignInActionTypes.SIGNIN_FAILURE;
|
116 | }
|
117 | return SigninFailed;
|
118 | }());
|
119 | var DoSignoutAction = (function () {
|
120 | function DoSignoutAction() {
|
121 | this.type = SignInActionTypes.DO_SIGNOUT;
|
122 | }
|
123 | return DoSignoutAction;
|
124 | }());
|
125 | var SignoutAction = (function () {
|
126 | function SignoutAction() {
|
127 | this.type = SignInActionTypes.SIGNOUT;
|
128 | }
|
129 | return SignoutAction;
|
130 | }());
|
131 | var SigninRequiredAction = (function () {
|
132 | function SigninRequiredAction() {
|
133 | this.type = SignInActionTypes.SIGNIN_REQUIRED;
|
134 | }
|
135 | return SigninRequiredAction;
|
136 | }());
|
137 |
|
138 |
|
139 |
|
140 |
|
141 |
|
142 |
|
143 | var 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 |
|
171 | var MODULE_CONFIG_TOKEN = new InjectionToken("ModuleConfig");
|
172 |
|
173 |
|
174 |
|
175 |
|
176 |
|
177 | var AuthenticationConfigurationService = (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 |
|
207 | AuthenticationConfigurationService.ctorParameters = function () { return [
|
208 | { type: undefined, decorators: [{ type: Inject, args: [MODULE_CONFIG_TOKEN,] }] },
|
209 | { type: Store }
|
210 | ]; };
|
211 | 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 |
|
217 |
|
218 |
|
219 | var ProgressingStarted = (function () {
|
220 | function ProgressingStarted() {
|
221 | this.type = "[AUTHENTICATION] PROGRESSING_STARTED" ;
|
222 | }
|
223 | return ProgressingStarted;
|
224 | }());
|
225 | var ProgressingFinished = (function () {
|
226 | function ProgressingFinished() {
|
227 | this.type = "[AUTHENTICATION] PROGRESSING_FINISHED" ;
|
228 | }
|
229 | return ProgressingFinished;
|
230 | }());
|
231 |
|
232 |
|
233 |
|
234 |
|
235 |
|
236 |
|
237 | var NEW_CAPTCHA = '[captcha] new captcha';
|
238 | var NewCaptcha = (function () {
|
239 | function NewCaptcha() {
|
240 | this.type = NEW_CAPTCHA;
|
241 | }
|
242 | return NewCaptcha;
|
243 | }());
|
244 |
|
245 |
|
246 |
|
247 |
|
248 |
|
249 |
|
250 |
|
251 |
|
252 |
|
253 |
|
254 |
|
255 | var COOKIE_NAME = "ngs-authentication";
|
256 | var SigninService = (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 |
|
267 |
|
268 |
|
269 | SigninService.prototype.signup = |
270 |
|
271 |
|
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 |
|
279 | var user = Object.assign({}, response.Result);
|
280 | if (user.Role) {
|
281 | user.Roles = [user.Role];
|
282 | }
|
283 | return user;
|
284 | }));
|
285 | };
|
286 | |
287 |
|
288 |
|
289 |
|
290 | SigninService.prototype.signin = |
291 |
|
292 |
|
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 |
|
307 |
|
308 | |
309 |
|
310 |
|
311 | SigninService.prototype.signout =
|
312 |
|
313 | |
314 |
|
315 |
|
316 | function () {
|
317 |
|
318 | var config = this.configurationService.config;
|
319 |
|
320 | var tokenObject = JSON.parse(Cookie.getCookie(COOKIE_NAME));
|
321 |
|
322 | var endpoint = stringTemplate(config.env[config.server] + config.endpoints.signOut, tokenObject);
|
323 |
|
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 |
|
334 |
|
335 | SigninService.prototype.whoAmI = |
336 |
|
337 |
|
338 | function () {
|
339 | var _this = this;
|
340 | debugger;
|
341 |
|
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 |
|
359 | SigninService.ctorParameters = function () { return [
|
360 | { type: HttpClient },
|
361 | { type: Store },
|
362 | { type: AuthenticationConfigurationService },
|
363 | { type: MatSnackBar }
|
364 | ]; };
|
365 | 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 |
|
371 |
|
372 |
|
373 | var SigninContainerComponent = (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 |
|
382 |
|
383 |
|
384 | SigninContainerComponent.prototype.signIn = |
385 |
|
386 |
|
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 |
|
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 |
|
410 |
|
411 |
|
412 | var AuthenticationContainerComponent = (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 |
|
425 |
|
426 |
|
427 | var SignupContainerComponent = (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 |
|
437 |
|
438 |
|
439 | SignupContainerComponent.prototype.signup = |
440 |
|
441 |
|
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 |
|
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 |
|
478 |
|
479 |
|
480 |
|
481 | var routes = [
|
482 | {
|
483 | path: "auth",
|
484 | component: AuthenticationContainerComponent,
|
485 | children: [
|
486 | {
|
487 | path: "signin",
|
488 |
|
489 | component: SigninContainerComponent
|
490 | },
|
491 | {
|
492 | path: "signup",
|
493 |
|
494 | component: SignupContainerComponent
|
495 | }
|
496 | ]
|
497 | }
|
498 | ];
|
499 |
|
500 | var AuthenticationRoutingModule = RouterModule.forChild(routes);
|
501 |
|
502 |
|
503 |
|
504 |
|
505 |
|
506 | var SigninComponent = (function () {
|
507 | function SigninComponent() {
|
508 | this.signedin = new EventEmitter();
|
509 | }
|
510 | |
511 |
|
512 |
|
513 |
|
514 | SigninComponent.prototype.signin = |
515 |
|
516 |
|
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 |
|
531 | SigninComponent.ctorParameters = function () { return []; };
|
532 | SigninComponent.propDecorators = {
|
533 | signedin: [{ type: Output }],
|
534 | formId: [{ type: Input }]
|
535 | };
|
536 | return SigninComponent;
|
537 | }());
|
538 |
|
539 |
|
540 |
|
541 |
|
542 |
|
543 |
|
544 | var WithCredentialInterceptor = (function () {
|
545 | function WithCredentialInterceptor(configurationService) {
|
546 | this.configurationService = configurationService;
|
547 | }
|
548 | |
549 |
|
550 |
|
551 |
|
552 |
|
553 | WithCredentialInterceptor.prototype.intercept = |
554 |
|
555 |
|
556 |
|
557 |
|
558 | function (request, next) {
|
559 |
|
560 | (( (request))).withCredentials = true;
|
561 | return next.handle(request);
|
562 | };
|
563 | WithCredentialInterceptor.decorators = [
|
564 | { type: Injectable }
|
565 | ];
|
566 |
|
567 | WithCredentialInterceptor.ctorParameters = function () { return [
|
568 | { type: AuthenticationConfigurationService }
|
569 | ]; };
|
570 | return WithCredentialInterceptor;
|
571 | }());
|
572 |
|
573 |
|
574 |
|
575 |
|
576 |
|
577 | var UnauthorizedInterceptor = (function () {
|
578 | function UnauthorizedInterceptor(router, store // private signinService: SigninService
|
579 | ) {
|
580 | this.router = router;
|
581 | this.store = store;
|
582 | }
|
583 | |
584 |
|
585 |
|
586 |
|
587 |
|
588 | UnauthorizedInterceptor.prototype.intercept = |
589 |
|
590 |
|
591 |
|
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 |
|
618 | UnauthorizedInterceptor.ctorParameters = function () { return [
|
619 | { type: Router },
|
620 | { type: Store }
|
621 | ]; };
|
622 | return UnauthorizedInterceptor;
|
623 | }());
|
624 |
|
625 |
|
626 |
|
627 |
|
628 |
|
629 |
|
630 | var initialState = {
|
631 | loggedIn: false,
|
632 | user: new UserModel({ Id: 1 })
|
633 | };
|
634 |
|
635 |
|
636 |
|
637 |
|
638 |
|
639 | function 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 |
|
654 |
|
655 | var getLoggedIn = function (state) { return state.loggedIn; };
|
656 |
|
657 | var getUser = function (state) { return state.user; };
|
658 |
|
659 |
|
660 |
|
661 |
|
662 |
|
663 |
|
664 | var AuthenticationReducers = {
|
665 | userStatus: UserReducer
|
666 |
|
667 | };
|
668 |
|
669 |
|
670 | var selectAuthenticationState = createFeatureSelector("authentication");
|
671 |
|
672 | var selectAuthState = createSelector(selectAuthenticationState, function (state) { return state.userStatus; });
|
673 |
|
674 | var getLoggedIn$1 = createSelector(selectAuthState, getLoggedIn);
|
675 |
|
676 | var getUser$1 = createSelector(selectAuthState, getUser);
|
677 |
|
678 |
|
679 |
|
680 |
|
681 |
|
682 |
|
683 |
|
684 |
|
685 |
|
686 |
|
687 | var SigninEffects = (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 |
|
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 |
|
732 | debugger;
|
733 | return of(err);
|
734 | }));
|
735 | }));
|
736 |
|
737 |
|
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 |
|
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 |
|
797 |
|
798 |
|
799 | var AuthenticationEffects = (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 |
|
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 |
|
825 |
|
826 |
|
827 | var SignupComponent = (function () {
|
828 | function SignupComponent() {
|
829 | this.signedup = new EventEmitter();
|
830 | }
|
831 | |
832 |
|
833 |
|
834 |
|
835 | SignupComponent.prototype.signup = |
836 |
|
837 |
|
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 |
|
852 | SignupComponent.ctorParameters = function () { return []; };
|
853 | SignupComponent.propDecorators = {
|
854 | signedup: [{ type: Output }],
|
855 | formId: [{ type: Input }]
|
856 | };
|
857 | return SignupComponent;
|
858 | }());
|
859 |
|
860 |
|
861 |
|
862 |
|
863 |
|
864 | var SigninGuard = (function () {
|
865 | function SigninGuard(store) {
|
866 | this.store = store;
|
867 | }
|
868 | |
869 |
|
870 |
|
871 |
|
872 |
|
873 | SigninGuard.prototype.canActivate = |
874 |
|
875 |
|
876 |
|
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 |
|
885 | SigninGuard.ctorParameters = function () { return [
|
886 | { type: Store }
|
887 | ]; };
|
888 | return SigninGuard;
|
889 | }());
|
890 |
|
891 |
|
892 |
|
893 |
|
894 |
|
895 | var NgsAuthenticationModule = (function () {
|
896 | function NgsAuthenticationModule() {
|
897 | }
|
898 | |
899 |
|
900 |
|
901 |
|
902 | NgsAuthenticationModule.forRoot = |
903 |
|
904 |
|
905 |
|
906 | function (config) {
|
907 | if (config === void 0) { config = ( ({})); }
|
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 | }());
|
969 | var RootNgsAuthenticationModule = (function () {
|
970 | function RootNgsAuthenticationModule() {
|
971 | (( (window))).___starter = (( (window))).___starter || {};
|
972 | (( (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 |
|
985 | RootNgsAuthenticationModule.ctorParameters = function () { return []; };
|
986 | return RootNgsAuthenticationModule;
|
987 | }());
|
988 |
|
989 |
|
990 |
|
991 |
|
992 |
|
993 |
|
994 |
|
995 |
|
996 |
|
997 |
|
998 |
|
999 | export { 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 |
|
\ | No newline at end of file |