ing
This commit is contained in:
parent
e980403faf
commit
312ea95f07
|
@ -32,13 +32,13 @@ export enum ActionType {
|
|||
export class Signin implements Action {
|
||||
readonly type = ActionType.Signin;
|
||||
|
||||
constructor(public payload: { email: string, password: string }) { }
|
||||
constructor(public payload: { email: string, password: string, returnURL: string }) { }
|
||||
}
|
||||
|
||||
export class SigninCookie implements Action {
|
||||
readonly type = ActionType.SigninCookie;
|
||||
|
||||
constructor(public payload: { authToken: string }) { }
|
||||
constructor(public payload: { authToken: string, returnURL: string }) { }
|
||||
}
|
||||
|
||||
export class Signout implements Action {
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
import { TestBed, inject } from '@angular/core/testing';
|
||||
|
||||
import { Effects } from './signup.effect';
|
||||
import { Effects } from './member.effect';
|
||||
|
||||
describe('Signup.Effects', () => {
|
||||
describe('member-entity.Effects', () => {
|
||||
beforeEach(() => {
|
||||
TestBed.configureTestingModule({
|
||||
providers: [Effects]
|
||||
|
|
|
@ -5,13 +5,8 @@ import { Effect, Actions, ofType } from '@ngrx/effects';
|
|||
import { Action } from '@ngrx/store';
|
||||
|
||||
import { Observable } from 'rxjs/Observable';
|
||||
import { of } from 'rxjs/observable/of';
|
||||
|
||||
import 'rxjs/add/operator/catch';
|
||||
import 'rxjs/add/operator/do';
|
||||
import 'rxjs/add/operator/exhaustMap';
|
||||
import 'rxjs/add/operator/map';
|
||||
import 'rxjs/add/operator/take';
|
||||
import { of } from 'rxjs';
|
||||
import { catchError, exhaustMap, map, tap } from 'rxjs/operators';
|
||||
|
||||
import { Member } from '@overflow/commons-typescript/model/member';
|
||||
import { MemberService } from '../../../service/member.service';
|
||||
|
@ -52,73 +47,100 @@ export class Effects {
|
|||
private memberService: MemberService,
|
||||
private router: Router
|
||||
) { }
|
||||
@Effect()
|
||||
signin$: Observable<Action> = this.actions$
|
||||
.ofType(ActionType.Signin)
|
||||
.map((action: Signin) => action.payload)
|
||||
.switchMap(payload => {
|
||||
return this.memberService.signin(payload.email, payload.password);
|
||||
})
|
||||
.map((result: { authToken: string, domainMember: DomainMember }) => {
|
||||
return new SigninSuccess({ authToken: result.authToken, domainMember: result.domainMember });
|
||||
})
|
||||
.catch((error: RESTClientError) => {
|
||||
return of(new SigninFailure(error));
|
||||
});
|
||||
|
||||
@Effect()
|
||||
signinCookie$: Observable<Action> = this.actions$
|
||||
.ofType(ActionType.SigninCookie)
|
||||
.map((action: SigninCookie) => action.payload)
|
||||
.switchMap((payload) => {
|
||||
return this.memberService.signin_cookie(payload.authToken);
|
||||
})
|
||||
.map((domainMember: DomainMember) => {
|
||||
return new SigninCookieSuccess(domainMember);
|
||||
})
|
||||
.catch((error: RESTClientError) => {
|
||||
return of(new SigninFailure(error));
|
||||
});
|
||||
|
||||
@Effect()
|
||||
signup$: Observable<Action> = this.actions$
|
||||
.ofType(ActionType.Signup)
|
||||
.map((action: Signup) => action.payload)
|
||||
.exhaustMap(payload =>
|
||||
this.memberService.signup(payload.member, payload.password)
|
||||
.map(member => new SignupSuccess(member))
|
||||
.catch(error => of(new SignupFailure(error)))
|
||||
);
|
||||
|
||||
@Effect()
|
||||
modify$: Observable<Action> = this.actions$
|
||||
.ofType(ActionType.Modify)
|
||||
.map((action: Modify) => action.payload)
|
||||
.exhaustMap(payload =>
|
||||
this.memberService.modify(payload)
|
||||
.map(member => new ModifySuccess(member))
|
||||
.catch(error => of(new ModifyFailure(error)))
|
||||
);
|
||||
|
||||
@Effect()
|
||||
resetPassword$: Observable<Action> = this.actions$
|
||||
.ofType(ActionType.ResetPassword)
|
||||
.map((action: ResetPassword) => action.payload)
|
||||
.exhaustMap(payload =>
|
||||
signin$ = this.actions$.pipe(
|
||||
ofType(ActionType.Signin),
|
||||
map((action: Signin) => action.payload),
|
||||
exhaustMap((signinInfo: { email: string, password: string, returnURL: string }) =>
|
||||
this.memberService
|
||||
.sendEmailResetPassword(payload)
|
||||
.map(member => new ResetPasswordSuccess(member))
|
||||
.catch(error => of(new ResetPasswordFailure(error)))
|
||||
);
|
||||
.signin(signinInfo.email, signinInfo.password)
|
||||
.pipe(
|
||||
map((result: { authToken: string, domainMember: DomainMember }) => {
|
||||
return new SigninSuccess({ authToken: result.authToken, domainMember: result.domainMember, returnURL: signinInfo.returnURL });
|
||||
}),
|
||||
catchError(error => of(new SigninFailure(error)))
|
||||
)
|
||||
)
|
||||
);
|
||||
|
||||
@Effect()
|
||||
ModifyPassword$: Observable<Action> = this.actions$
|
||||
.ofType(ActionType.ModifyPassword)
|
||||
.map((action: ModifyPassword) => action.payload)
|
||||
.exhaustMap(payload =>
|
||||
signinCookie$ = this.actions$.pipe(
|
||||
ofType(ActionType.SigninCookie),
|
||||
map((action: SigninCookie) => action.payload),
|
||||
exhaustMap((signinInfo: { authToken: string, returnURL: string }) =>
|
||||
this.memberService
|
||||
.resetPassword(payload.token, payload.password, payload.confirmPassword)
|
||||
.map(member => new ModifyPasswordSuccess(member))
|
||||
.catch(error => of(new ModifyPasswordFailure(error)))
|
||||
);
|
||||
.signin_cookie(signinInfo.authToken)
|
||||
.pipe(
|
||||
map((domainMember: DomainMember) => {
|
||||
return new SigninCookieSuccess({ domainMember: domainMember, returnURL: signinInfo.returnURL });
|
||||
}),
|
||||
catchError(error => of(new SigninCookieFailure(error)))
|
||||
)
|
||||
)
|
||||
);
|
||||
|
||||
@Effect()
|
||||
signup$ = this.actions$.pipe(
|
||||
ofType(ActionType.Signup),
|
||||
map((action: Signup) => action.payload),
|
||||
exhaustMap((signupInfo: { member: Member, password: string }) =>
|
||||
this.memberService
|
||||
.signup(signupInfo.member, signupInfo.password)
|
||||
.pipe(
|
||||
map((member: Member) => {
|
||||
return new SignupSuccess(member);
|
||||
}),
|
||||
catchError(error => of(new SignupFailure(error)))
|
||||
)
|
||||
)
|
||||
);
|
||||
|
||||
@Effect()
|
||||
modify$ = this.actions$.pipe(
|
||||
ofType(ActionType.Modify),
|
||||
map((action: Modify) => action.payload),
|
||||
exhaustMap((member: Member) =>
|
||||
this.memberService
|
||||
.modify(member)
|
||||
.pipe(
|
||||
map((newMember: Member) => {
|
||||
return new ModifySuccess(newMember);
|
||||
}),
|
||||
catchError(error => of(new ModifyFailure(error)))
|
||||
)
|
||||
)
|
||||
);
|
||||
|
||||
@Effect()
|
||||
resetPassword$ = this.actions$.pipe(
|
||||
ofType(ActionType.ResetPassword),
|
||||
map((action: ResetPassword) => action.payload),
|
||||
exhaustMap((email: string) =>
|
||||
this.memberService
|
||||
.sendEmailResetPassword(email)
|
||||
.pipe(
|
||||
map((newMember: Member) => {
|
||||
return new ResetPasswordSuccess(newMember);
|
||||
}),
|
||||
catchError(error => of(new ResetPasswordFailure(error)))
|
||||
)
|
||||
)
|
||||
);
|
||||
|
||||
@Effect()
|
||||
modifyPassword$ = this.actions$.pipe(
|
||||
ofType(ActionType.ModifyPassword),
|
||||
map((action: ModifyPassword) => action.payload),
|
||||
exhaustMap((info: { token: string, password: string, confirmPassword: string }) =>
|
||||
this.memberService
|
||||
.resetPassword(info.token, info.password, info.confirmPassword)
|
||||
.pipe(
|
||||
map((newMember: Member) => {
|
||||
return new ModifyPasswordSuccess(newMember);
|
||||
}),
|
||||
catchError(error => of(new ModifyPasswordFailure(error)))
|
||||
)
|
||||
)
|
||||
);
|
||||
}
|
||||
|
|
|
@ -18,7 +18,7 @@ export enum ActionType {
|
|||
export class SigninSuccess implements Action {
|
||||
readonly type = ActionType.SigninSuccess;
|
||||
|
||||
constructor(public payload: {authToken: string, domainMember: DomainMember}) {}
|
||||
constructor(public payload: {authToken: string, domainMember: DomainMember, returnURL: string}) {}
|
||||
}
|
||||
|
||||
export class SigninFailure implements Action {
|
||||
|
@ -30,7 +30,7 @@ export class SigninFailure implements Action {
|
|||
export class SigninCookieSuccess implements Action {
|
||||
readonly type = ActionType.SigninCookieSuccess;
|
||||
|
||||
constructor(public payload: DomainMember) {}
|
||||
constructor(public payload: {domainMember: DomainMember, returnURL: string}) {}
|
||||
}
|
||||
|
||||
export class SigninCookieFailure implements Action {
|
||||
|
|
|
@ -27,7 +27,7 @@ export function reducer(state: State = initialState, action: Actions): State {
|
|||
case ActionType.SigninCookieSuccess: {
|
||||
return {
|
||||
signined: true,
|
||||
domainMember: action.payload,
|
||||
domainMember: action.payload.domainMember,
|
||||
};
|
||||
}
|
||||
|
||||
|
|
|
@ -18,25 +18,25 @@ import { BrowserAnimationsModule } from '@angular/platform-browser/animations';
|
|||
import { MemberModule } from '@overflow/member/member.module';
|
||||
|
||||
@NgModule({
|
||||
imports: [
|
||||
BrowserModule,
|
||||
BrowserAnimationsModule,
|
||||
HttpClientModule,
|
||||
AppRoutingModule,
|
||||
AppStoreModule,
|
||||
AppL10NModule,
|
||||
AppRPCModule,
|
||||
AppRESTModule,
|
||||
AppLoggerModule,
|
||||
MemberModule,
|
||||
],
|
||||
declarations: [
|
||||
AppComponent,
|
||||
],
|
||||
providers: [
|
||||
CookieService,
|
||||
AuthGuard,
|
||||
],
|
||||
bootstrap: [AppComponent]
|
||||
imports: [
|
||||
BrowserModule,
|
||||
BrowserAnimationsModule,
|
||||
HttpClientModule,
|
||||
AppRoutingModule,
|
||||
AppStoreModule,
|
||||
AppL10NModule,
|
||||
AppRPCModule,
|
||||
AppRESTModule,
|
||||
AppLoggerModule,
|
||||
MemberModule,
|
||||
],
|
||||
declarations: [
|
||||
AppComponent,
|
||||
],
|
||||
providers: [
|
||||
CookieService,
|
||||
AuthGuard,
|
||||
],
|
||||
bootstrap: [AppComponent]
|
||||
})
|
||||
export class AppModule { }
|
||||
|
|
Loading…
Reference in New Issue
Block a user