UNPKG

16.5 kBJavaScriptView Raw
1!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports,require("@angular/core"),require("@angular/common/http"),require("rxjs"),require("@angular/material"),require("rxjs/operators"),require("@ngrx/store"),require("@soushians/shared"),require("@soushians/config"),require("@angular/material/snack-bar"),require("@angular/common"),require("@angular/router"),require("@angular/flex-layout"),require("@angular/platform-browser/animations"),require("@angular/forms"),require("@ngrx/effects"),require("@soushians/form"),require("rxjs/add/operator/do")):"function"==typeof define&&define.amd?define("@soushians/authentication",["exports","@angular/core","@angular/common/http","rxjs","@angular/material","rxjs/operators","@ngrx/store","@soushians/shared","@soushians/config","@angular/material/snack-bar","@angular/common","@angular/router","@angular/flex-layout","@angular/platform-browser/animations","@angular/forms","@ngrx/effects","@soushians/form","rxjs/add/operator/do"],e):e(((t=t||self).soushians=t.soushians||{},t.soushians.authentication={}),t.ng.core,t.ng.common.http,t.rxjs,t.ng.material,t.rxjs.operators,t.store,t.shared,t.config,t.ng.material["snack-bar"],t.ng.common,t.ng.router,t.ng["flex-layout"],t.ng.platformBrowser.animations,t.ng.forms,t.effects,t.form)}(this,(function(t,e,n,r,o,i,s,a,u,c,p,f,d,g,h,l,I){"use strict";var y=function(){return(y=Object.assign||function(t){for(var e,n=1,r=arguments.length;n<r;n++)for(var o in e=arguments[n])Object.prototype.hasOwnProperty.call(e,o)&&(t[o]=e[o]);return t}).apply(this,arguments)};function v(t,e,n,r){var o,i=arguments.length,s=i<3?e:null===r?r=Object.getOwnPropertyDescriptor(e,n):r;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)s=Reflect.decorate(t,e,n,r);else for(var a=t.length-1;a>=0;a--)(o=t[a])&&(s=(i<3?o(s):i>3?o(e,n,s):o(e,n))||s);return i>3&&s&&Object.defineProperty(e,n,s),s}function m(t,e){if("object"==typeof Reflect&&"function"==typeof Reflect.metadata)return Reflect.metadata(t,e)}var S=function(t){var e=this;this.Roles=[],t&&Object.keys(t).forEach((function(n){n in t&&(e[n]=t[n])}))};var N={WHO_AM_I:"[AUTHENTICATION] who am i",SIGNUP:"[AUTHENTICATION][SIGNUP] start",SIGNUP_SUCCEED:"[AUTHENTICATION][SIGNUP] Success",SIGNUP_FAILURE:"[AUTHENTICATION][SIGNUP] Failure",SIGNIN:"[AUTHENTICATION] Signin",DO_SIGNOUT:"[AUTHENTICATION] Do Signout",SIGNOUT:"[AUTHENTICATION] Signout",SIGNIN_SUCCEED:"[AUTHENTICATION][Signin] Success",SIGNIN_FAILURE:"[AUTHENTICATION][Signin] Failure",SIGNIN_REDIRECT:"[AUTHENTICATION][Signin] Redirect",SIGNIN_REQUIRED:"[AUTHENTICATION][Signin] Required"},E=function(){this.type=N.WHO_AM_I};var T=function(t){this.payload=t,this.type=N.SIGNUP};var w=function(t){this.payload=t,this.type=N.SIGNUP_SUCCEED};var M=function(t){this.payload=t,this.type=N.SIGNUP_FAILURE};var O=function(t){this.payload=t,this.type=N.SIGNIN};var $=function(t){this.payload=t,this.type=N.SIGNIN_SUCCEED};var C=function(t){this.payload=t,this.type=N.SIGNIN_FAILURE};var U=function(){this.type=N.DO_SIGNOUT};var b=function(){this.type=N.SIGNOUT};var A=function(){this.type=N.SIGNIN_REQUIRED};var R={mode:"cookie-base",token:{time:1036800},server:"frontend_server",endpoints:{signOut:"",signOutMethod:"get",signIn:"",signUp:"",whoAmI:""},forms:{signIn:"",signUp:""},env:{production:!1,frontend_server:"auth/module/frontend_server/did/not/set",server:"auth/module/server/did/not/set"},afterSignoutRedirectTo:"/",signupValidator:function(t){return r.of(!0)},afterSignin:function(t){},responseToUser:function(t){return t}},j=new e.InjectionToken("ModuleConfig"),_=function(){function t(t,e){var n=this;this.store=e,this.config$=new r.BehaviorSubject(this._config),this._config=Object.assign({},R,t),this.config$.next(this._config),this.store.select(u.getAuthenticationModuleConfig).subscribe((function(t){t&&(n._config=Object.assign({},n._config,t.Config),n.config$.next(n._config))}))}return Object.defineProperty(t.prototype,"config",{get:function(){return this._config},enumerable:!0,configurable:!0}),t.decorators=[{type:e.Injectable,args:[{providedIn:"root"}]}],t.ctorParameters=function(){return[{type:void 0,decorators:[{type:e.Inject,args:[j]}]},{type:s.Store}]},t.ngInjectableDef=e.ɵɵdefineInjectable({factory:function(){return new t(e.ɵɵinject(j),e.ɵɵinject(s.Store))},token:t,providedIn:"root"}),t}();var x=function(){this.type="[AUTHENTICATION] PROGRESSING_STARTED"};var P=function(){this.type="[AUTHENTICATION] PROGRESSING_FINISHED"};var G="[captcha] new captcha",k=function(){this.type=G};var D="ngs-authentication",F=function(){function t(t,e,n,r){var o=this;this.http=t,this.store=e,this.configurationService=n,this.snackBar=r,setTimeout((function(){return o.store.dispatch(new E)}),300)}return t.prototype.signup=function(t){var e=this;return this.configurationService.config$.pipe(i.filter((function(t){return""!=t.endpoints.signUp})),i.take(1),i.switchMap((function(n){return e.http.post(n.env[n.server]+n.endpoints.signUp,t)})),i.map((function(t){var e=Object.assign({},t.Result);return e.Role&&(e.Roles=[e.Role]),e})))},t.prototype.signin=function(t){var e=this;return this.configurationService.config$.pipe(i.filter((function(t){return""!=t.endpoints.signIn})),i.take(1),i.switchMap((function(n){return e.http.post(n.env[n.server]+n.endpoints.signIn,t)})),i.map(this.configurationService.config.responseToUser),i.map((function(t){return t.Role&&(t.Roles=[t.Role]),t})),i.tap((function(t){"token-base"==e.configurationService.config.mode&&a.Cookie.setCookie(D,JSON.stringify(t),e.configurationService.config.token.time)})),i.tap((function(t){return e.configurationService.config.afterSignin(t)})))},t.prototype.signout=function(){var t=this.configurationService.config,e=JSON.parse(a.Cookie.getCookie(D)),n=a.stringTemplate(t.env[t.server]+t.endpoints.signOut,e),o=t.endpoints.signOutMethod||"get";return-1===["get","put","post","patch","delete"].indexOf(o)&&r.throwError(o+" is not valid http method. [ @starter/authentication/signinservice/singout ]"),this.http[o](n).pipe(i.tap((function(){a.Cookie.deleteCookie(D)})))},t.prototype.whoAmI=function(){var t=this,e={Token:"--"};if("token-base"==this.configurationService.config.mode)try{e=JSON.parse(a.Cookie.getCookie(D))}catch(t){}return this.configurationService.config$.pipe(i.filter((function(t){return""!=t.endpoints.whoAmI})),i.take(1),i.switchMap((function(n){return t.http.get(a.stringTemplate(n.env[n.server]+n.endpoints.whoAmI,{user:e}))})))},t.decorators=[{type:e.Injectable,args:[{providedIn:"root"}]}],t.ctorParameters=function(){return[{type:n.HttpClient},{type:s.Store},{type:_},{type:o.MatSnackBar}]},t.ngInjectableDef=e.ɵɵdefineInjectable({factory:function(){return new t(e.ɵɵinject(n.HttpClient),e.ɵɵinject(s.Store),e.ɵɵinject(_),e.ɵɵinject(c.MatSnackBar))},token:t,providedIn:"root"}),t}();var H=function(){function t(t,n){this.configurationService=t,this.store=n,this.signedIn$=new e.EventEmitter,this.formId$=this.configurationService.config$.map((function(t){return t.forms.signIn}))}return t.prototype.signIn=function(t){this.store.dispatch(new O(t)),this.signedIn$.emit(!0)},t.decorators=[{type:e.Component,args:[{template:"\n <auth-signin \n [formId]='(formId$ | async)'\n (signedin)=\"signIn($event)\"\n ></auth-signin>\n "}]}],t.ctorParameters=function(){return[{type:_},{type:s.Store}]},t.propDecorators={signedIn$:[{type:e.Output}]},t}();var q=function(){function t(){}return t.decorators=[{type:e.Component,args:[{template:"\n <router-outlet></router-outlet>\n "}]}],t}(),L=function(){function t(t,n,r){this.configurationService=t,this.store=n,this.snackBar=r,this.signedUp$=new e.EventEmitter,this.formId$=this.configurationService.config$.map((function(t){return t.forms.signUp}))}return t.prototype.signup=function(t){var e=this;this.configurationService.config$.pipe(i.take(1),i.switchMap((function(e){return e.signupValidator(t)}))).subscribe((function(n){n?(e.store.dispatch(new T(t)),e.signedUp$.emit(!0)):e.snackBar.open("رمز عبور یکسان نیست",null,{duration:2222})}))},t.decorators=[{type:e.Component,args:[{template:"\n <auth-signup \n [formId]='(formId$ | async)'\n (signedup)=\"signup($event)\"\n ></auth-signup>\n "}]}],t.ctorParameters=function(){return[{type:_},{type:s.Store},{type:o.MatSnackBar}]},t.propDecorators={signedUp$:[{type:e.Output}]},t}();var B=[{path:"auth",component:q,children:[{path:"signin",component:H},{path:"signup",component:L}]}],V=f.RouterModule.forChild(B),J=function(){function t(){this.signedin=new e.EventEmitter}return t.prototype.signin=function(t){t.valid&&this.signedin.emit(t.value)},t.decorators=[{type:e.Component,args:[{selector:"auth-signin",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\x3c!-- <div>\r\n <a fxFlex="nogrow" routerLink="/user/password/reset" mat-raised-button fxFlexFill>کلمه عبور خود را فراموش کرده اید؟</a>\r\n</div> --\x3e',styles:[""]}]}],t.ctorParameters=function(){return[]},t.propDecorators={signedin:[{type:e.Output}],formId:[{type:e.Input}]},t}();var Q=function(){function t(t){this.configurationService=t}return t.prototype.intercept=function(t,e){return t.withCredentials=!0,e.handle(t)},t.decorators=[{type:e.Injectable}],t.ctorParameters=function(){return[{type:_}]},t}();var W=function(){function t(t,e){this.router=t,this.store=e}return t.prototype.intercept=function(t,e){var o=this;return e.handle(t).map((function(t){if(t instanceof n.HttpResponse)return t})).catch((function(t){return t instanceof n.HttpErrorResponse?401!=t.status?r.throwError(t):t.url.includes("logout")?r.throwError(t):t.url.includes("user/account/profile")?r.throwError(t):(o.store.dispatch(new b),r.throwError("Unauthorized")):r.throwError(t)}))},t.decorators=[{type:e.Injectable}],t.ctorParameters=function(){return[{type:f.Router},{type:s.Store}]},t}();var z={loggedIn:!1,user:new S({Id:1})};function K(t,e){switch(void 0===t&&(t=z),e.type){case N.SIGNIN_SUCCEED:return y({},t,{loggedIn:!0,user:e.payload});case N.SIGNOUT:return y({},t,{loggedIn:!1,user:new S});default:return t}}var X=function(t){return t.user};var Y={userStatus:K},Z=s.createFeatureSelector("authentication"),tt=s.createSelector(Z,(function(t){return t.userStatus})),et=s.createSelector(tt,(function(t){return t.loggedIn})),nt=s.createSelector(tt,X),rt=function(){function t(t,e,n,o,s){var a=this;this.actions$=t,this.router=e,this.signinService=n,this.configurationService=o,this.bottomSheet=s,this.whoAmI$=this.actions$.pipe(l.ofType(N.WHO_AM_I),i.switchMap((function(){return a.signinService.whoAmI().pipe(i.map((function(t){return new $(t)})),i.catchError((function(t){return r.of(new C(t))})))}))),this.Signin$=this.actions$.pipe(l.ofType(N.SIGNIN),i.pluck("payload"),i.switchMap((function(t){return a.signinService.signin(t).pipe(i.map((function(t){return new $(t)})),i.catchError((function(t){return r.of(new C(t))})))}))),this.signup$=this.actions$.pipe(l.ofType(N.SIGNUP),i.pluck("payload"),i.switchMap((function(t){return a.signinService.signup(t).pipe(i.map((function(t){return new w(t)})),i.catchError((function(t){return r.of(new M(t))})))}))),this.signupSucceed$=this.actions$.pipe(l.ofType(N.SIGNUP_SUCCEED),i.tap((function(){a.router.navigate(["auth/signin"])}))),this.SignInRequired$=this.actions$.pipe(l.ofType(N.SIGNIN_REQUIRED),i.tap((function(t){var e=a.bottomSheet.open(H,{panelClass:"clear-mat-card-box"});return e.instance.signedIn$.subscribe((function(){e.dismiss()})),e}))),this.SigninSucceed$=this.actions$.pipe(l.ofType(N.SIGNIN_SUCCEED),i.tap((function(t){location.pathname.indexOf("signin")>-1&&a.router.navigate(["/"])}))),this.AfterSigninFiled$=this.actions$.pipe(l.ofType(N.SIGNIN_FAILURE),i.map((function(){return new k}))),this.DoSignout$=this.actions$.pipe(l.ofType(N.DO_SIGNOUT),i.switchMap((function(t){return a.signinService.signout().pipe(i.map((function(){return new b})),i.catchError((function(t){return r.of(t)})))}))),this.redirectToLoginPage$=this.actions$.pipe(l.ofType(N.SIGNIN_REDIRECT),i.tap((function(t){return a.router.navigate(["auth/signin"])}))),this.redirectAfterSignout$=this.actions$.pipe(l.ofType(N.SIGNOUT),i.tap((function(t){return a.router.navigate([a.configurationService.config$.getValue().afterSignoutRedirectTo])})))}return t.decorators=[{type:e.Injectable}],t.ctorParameters=function(){return[{type:l.Actions},{type:f.Router},{type:F},{type:_},{type:o.MatBottomSheet}]},v([l.Effect(),m("design:type",Object)],t.prototype,"whoAmI$",void 0),v([l.Effect(),m("design:type",Object)],t.prototype,"Signin$",void 0),v([l.Effect(),m("design:type",Object)],t.prototype,"signup$",void 0),v([l.Effect({dispatch:!1}),m("design:type",Object)],t.prototype,"signupSucceed$",void 0),v([l.Effect({dispatch:!1}),m("design:type",Object)],t.prototype,"SignInRequired$",void 0),v([l.Effect({dispatch:!1}),m("design:type",Object)],t.prototype,"SigninSucceed$",void 0),v([l.Effect(),m("design:type",Object)],t.prototype,"AfterSigninFiled$",void 0),v([l.Effect(),m("design:type",Object)],t.prototype,"DoSignout$",void 0),v([l.Effect({dispatch:!1}),m("design:type",Object)],t.prototype,"redirectToLoginPage$",void 0),v([l.Effect({dispatch:!1}),m("design:type",Object)],t.prototype,"redirectAfterSignout$",void 0),t}();var ot=function(){function t(t){this.actions$=t,this.dispachProgressingStarted$=this.actions$.pipe(l.ofType(N.SIGNIN),i.map((function(){return new x}))),this.dispachProgressingFinished$=this.actions$.pipe(l.ofType(N.SIGNIN_FAILURE,N.SIGNIN_SUCCEED),i.map((function(){return new P})))}return t.decorators=[{type:e.Injectable}],t.ctorParameters=function(){return[{type:l.Actions}]},v([l.Effect(),m("design:type",Object)],t.prototype,"dispachProgressingStarted$",void 0),v([l.Effect(),m("design:type",Object)],t.prototype,"dispachProgressingFinished$",void 0),t}();var it=function(){function t(){this.signedup=new e.EventEmitter}return t.prototype.signup=function(t){t.valid&&this.signedup.emit(t.value)},t.decorators=[{type:e.Component,args:[{selector:"auth-signup",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\x3c!-- <div>\r\n <a fxFlex="nogrow" routerLink="/user/password/reset" mat-raised-button fxFlexFill>کلمه عبور خود را فراموش کرده اید؟</a>\r\n</div> --\x3e',styles:[""]}]}],t.ctorParameters=function(){return[]},t.propDecorators={signedup:[{type:e.Output}],formId:[{type:e.Input}]},t}();var st=function(){function t(t){this.store=t}return t.prototype.canActivate=function(t,e){return this.store.select(et).take(1).map((function(t){return!t}))},t.decorators=[{type:e.Injectable}],t.ctorParameters=function(){return[{type:s.Store}]},t}();var at=function(){function t(){}return t.forRoot=function(t){return void 0===t&&(t={}),{ngModule:ut,providers:[{provide:j,useValue:t},{provide:n.HTTP_INTERCEPTORS,useClass:W,multi:!0},{provide:n.HTTP_INTERCEPTORS,useClass:Q,multi:!0},F]}},t.decorators=[{type:e.NgModule,args:[{imports:[p.CommonModule,f.RouterModule,h.FormsModule,n.HttpClientModule,d.FlexLayoutModule,o.MatIconModule,o.MatButtonModule,o.MatCardModule,o.MatSnackBarModule,o.MatSidenavModule,o.MatExpansionModule,o.MatSelectModule,o.MatBottomSheetModule,o.MatFormFieldModule,o.MatListModule,o.MatMenuModule,o.MatRadioModule,o.MatInputModule,o.MatToolbarModule,o.MatDatepickerModule,o.MatProgressBarModule,g.BrowserAnimationsModule,h.ReactiveFormsModule,h.FormsModule,I.NgsFormModule],declarations:[H,J,q,L,it],entryComponents:[H],providers:[st],exports:[]}]}],t}(),ut=function(){function t(){window.___starter=window.___starter||{},window.___starter.authentication="8.0.10"}return t.decorators=[{type:e.NgModule,args:[{imports:[s.StoreModule.forFeature("authentication",Y),l.EffectsModule.forFeature([rt,ot]),V,at]}]}],t.ctorParameters=function(){return[]},t}();t.DoSignoutAction=U,t.NgsAuthenticationModule=at,t.SignInActionTypes=N,t.SigninContainerComponent=H,t.SigninRequiredAction=A,t.SigninService=F,t.UserModel=S,t.getUser=nt,t.ɵa=j,t.ɵb=ut,t.ɵc=Y,t.ɵd=Z,t.ɵe=tt,t.ɵh=_,t.ɵi=J,t.ɵj=q,t.ɵk=L,t.ɵl=it,t.ɵm=st,t.ɵn=K,t.ɵo=X,t.ɵp=rt,t.ɵq=ot,t.ɵr=V,t.ɵs=W,t.ɵt=Q,Object.defineProperty(t,"__esModule",{value:!0})}));
2//# sourceMappingURL=soushians-authentication.umd.min.js.map
\No newline at end of file