UNPKG

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