UNPKG

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