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