ing
This commit is contained in:
parent
d3372d8db0
commit
1d0ac6b572
|
@ -1,15 +0,0 @@
|
|||
import { TestBed, inject } from '@angular/core/testing';
|
||||
|
||||
import { Effects } from './auth.effect';
|
||||
|
||||
describe('Auth.Effects', () => {
|
||||
beforeEach(() => {
|
||||
TestBed.configureTestingModule({
|
||||
providers: [Effects]
|
||||
});
|
||||
});
|
||||
|
||||
it('should be created', inject([Effects], (effects: Effects) => {
|
||||
expect(effects).toBeTruthy();
|
||||
}));
|
||||
});
|
|
@ -1,107 +0,0 @@
|
|||
import { Injectable } from '@angular/core';
|
||||
import { Router } from '@angular/router';
|
||||
|
||||
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/switchMap';
|
||||
import 'rxjs/add/operator/map';
|
||||
import 'rxjs/add/operator/take';
|
||||
|
||||
import { RESTClientError } from '@loafer/ng-rest';
|
||||
|
||||
import { DomainMember } from '@overflow/commons-typescript/model/domain';
|
||||
|
||||
import { Member } from '@overflow/commons-typescript/model/member';
|
||||
import { MemberService } from '../../service/member.service';
|
||||
|
||||
import {
|
||||
Signin,
|
||||
SigninSuccess,
|
||||
SigninFailure,
|
||||
SigninRedirect,
|
||||
SigninCookie,
|
||||
SigninCookieSuccess,
|
||||
SigninCookieFailure,
|
||||
|
||||
ActionType,
|
||||
} from './auth.action';
|
||||
|
||||
@Injectable()
|
||||
export class Effects {
|
||||
private _returnURL: any;
|
||||
|
||||
constructor(
|
||||
private actions$: Actions,
|
||||
private memberService: MemberService,
|
||||
private router: Router
|
||||
) { }
|
||||
|
||||
@Effect()
|
||||
signin$: Observable<Action> = this.actions$
|
||||
.ofType(ActionType.Signin)
|
||||
.map((action: Signin) => action.payload)
|
||||
.switchMap(payload => {
|
||||
this._returnURL = payload.returnURL;
|
||||
return this.memberService.signin(payload.email, payload.password);
|
||||
})
|
||||
.map((result: any) => {
|
||||
const authToken = result['authToken'];
|
||||
const domainMember = result['domainMember'];
|
||||
return new SigninSuccess({authToken: authToken, domainMember: domainMember});
|
||||
})
|
||||
.catch((error: RESTClientError) => {
|
||||
return of(new SigninFailure(error));
|
||||
});
|
||||
|
||||
@Effect({ dispatch: false })
|
||||
signinSuccess$ = this.actions$
|
||||
.ofType(ActionType.SigninSuccess)
|
||||
.do(() => {
|
||||
this.router.navigateByUrl(this._returnURL);
|
||||
});
|
||||
|
||||
@Effect({ dispatch: false })
|
||||
signinRedirect$ = this.actions$
|
||||
.ofType(ActionType.SigninRedirect, ActionType.Signout)
|
||||
.map((action: SigninRedirect) => action.payload)
|
||||
.do(returnURL => {
|
||||
this.router.navigate(['/auth/signin'], {queryParams: {returnURL: returnURL}});
|
||||
});
|
||||
|
||||
|
||||
@Effect()
|
||||
signinCookie$: Observable<Action> = this.actions$
|
||||
.ofType(ActionType.SigninCookie)
|
||||
.map((action: SigninCookie) => action.payload)
|
||||
.switchMap((payload) => {
|
||||
this._returnURL = payload.returnURL;
|
||||
return this.memberService.signin_cookie(payload.authToken);
|
||||
})
|
||||
.map((domainMember: DomainMember) => {
|
||||
return new SigninCookieSuccess(domainMember);
|
||||
})
|
||||
.catch((error: RESTClientError) => {
|
||||
return of(new SigninFailure(error));
|
||||
});
|
||||
|
||||
@Effect({ dispatch: false })
|
||||
signinCookieSuccess$ = this.actions$
|
||||
.ofType(ActionType.SigninCookieSuccess)
|
||||
.do(() => {
|
||||
this.router.navigateByUrl(this._returnURL);
|
||||
});
|
||||
|
||||
@Effect({ dispatch: false })
|
||||
signinCookieFailure$ = this.actions$
|
||||
.ofType(ActionType.SigninCookieFailure)
|
||||
.map(() => {
|
||||
return new SigninRedirect(this._returnURL);
|
||||
});
|
||||
}
|
|
@ -1,102 +0,0 @@
|
|||
import {
|
||||
Actions,
|
||||
ActionType,
|
||||
Signin,
|
||||
} from './auth.action';
|
||||
|
||||
import {
|
||||
State,
|
||||
initialState,
|
||||
} from './auth.state';
|
||||
|
||||
import { Member } from '@overflow/commons-typescript/model/member';
|
||||
import { DomainMember } from '@overflow/commons-typescript/model/domain';
|
||||
|
||||
export function reducer(state = initialState, action: Actions): State {
|
||||
switch (action.type) {
|
||||
case ActionType.Signin: {
|
||||
return {
|
||||
...state,
|
||||
error: null,
|
||||
pending: true,
|
||||
};
|
||||
}
|
||||
|
||||
case ActionType.SigninSuccess: {
|
||||
const domainMember = action.payload.domainMember;
|
||||
return {
|
||||
...state,
|
||||
signined: true,
|
||||
error: null,
|
||||
pending: false,
|
||||
member: domainMember.member,
|
||||
domain: domainMember.domain,
|
||||
};
|
||||
}
|
||||
|
||||
case ActionType.SigninFailure: {
|
||||
return {
|
||||
...state,
|
||||
signined: false,
|
||||
error: action.payload,
|
||||
pending: false,
|
||||
member: null,
|
||||
domain: null,
|
||||
};
|
||||
}
|
||||
|
||||
case ActionType.SigninCookieSuccess: {
|
||||
return {
|
||||
...state,
|
||||
signined: true,
|
||||
error: null,
|
||||
pending: false,
|
||||
member: action.payload.member,
|
||||
domain: action.payload.domain,
|
||||
};
|
||||
}
|
||||
|
||||
case ActionType.SigninCookieFailure: {
|
||||
return {
|
||||
...state,
|
||||
signined: false,
|
||||
error: action.payload,
|
||||
pending: false,
|
||||
member: null,
|
||||
domain: null,
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
case ActionType.Signout: {
|
||||
return {
|
||||
...state,
|
||||
error: null,
|
||||
pending: true,
|
||||
};
|
||||
}
|
||||
|
||||
case ActionType.SignoutSuccess: {
|
||||
return {
|
||||
...state,
|
||||
signined: false,
|
||||
error: null,
|
||||
pending: false,
|
||||
member: null,
|
||||
domain: null,
|
||||
};
|
||||
}
|
||||
|
||||
case ActionType.SignoutFailure: {
|
||||
return {
|
||||
...state,
|
||||
error: action.payload,
|
||||
pending: false,
|
||||
};
|
||||
}
|
||||
|
||||
default: {
|
||||
return state;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,19 +0,0 @@
|
|||
import { RESTClientError } from '@loafer/ng-rest';
|
||||
import { Domain } from '@overflow/commons-typescript/model/domain';
|
||||
import { Member } from '@overflow/commons-typescript/model/member';
|
||||
|
||||
export interface State {
|
||||
signined: boolean;
|
||||
error: RESTClientError | null;
|
||||
pending: boolean;
|
||||
member: Member | null;
|
||||
domain: Domain | null;
|
||||
}
|
||||
|
||||
export const initialState: State = {
|
||||
signined: false,
|
||||
error: null,
|
||||
pending: false,
|
||||
member: null,
|
||||
domain: null,
|
||||
};
|
|
@ -0,0 +1,3 @@
|
|||
export * from './member-modify-password.state';
|
||||
export * from './member-modify-password.reducer';
|
||||
|
|
@ -1,38 +1,33 @@
|
|||
import {
|
||||
Actions,
|
||||
ActionType,
|
||||
} from './modify.action';
|
||||
} from '../../entity/member/member.action';
|
||||
|
||||
import {
|
||||
State,
|
||||
initialState,
|
||||
} from './modify.state';
|
||||
} from './member-modify-password.state';
|
||||
|
||||
export function reducer(state = initialState, action: Actions): State {
|
||||
switch (action.type) {
|
||||
case ActionType.Modify: {
|
||||
case ActionType.ModifyPassword: {
|
||||
return {
|
||||
...state,
|
||||
error: null,
|
||||
pending: true,
|
||||
};
|
||||
}
|
||||
|
||||
case ActionType.ModifySuccess: {
|
||||
return {
|
||||
...state,
|
||||
error: null,
|
||||
pending: false,
|
||||
member: action.payload,
|
||||
};
|
||||
}
|
||||
|
||||
case ActionType.ModifyFailure: {
|
||||
case ActionType.ModifyPasswordSuccess: {
|
||||
return {
|
||||
...state,
|
||||
error: action.payload,
|
||||
pending: false,
|
||||
member: null,
|
||||
error: null,
|
||||
};
|
||||
}
|
||||
|
||||
case ActionType.ModifyPasswordFailure: {
|
||||
return {
|
||||
pending: false,
|
||||
error: action.payload,
|
||||
};
|
||||
}
|
||||
|
||||
|
@ -41,3 +36,4 @@ export function reducer(state = initialState, action: Actions): State {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,23 @@
|
|||
import { Selector, createSelector } from '@ngrx/store';
|
||||
|
||||
import { RESTClientError } from '@loafer/ng-rest';
|
||||
|
||||
import { Member } from '@overflow/commons-typescript/model/member';
|
||||
|
||||
export interface State {
|
||||
pending: boolean;
|
||||
error: RESTClientError;
|
||||
}
|
||||
|
||||
export const initialState: State = {
|
||||
pending: false,
|
||||
error: null,
|
||||
};
|
||||
|
||||
|
||||
export function getSelectors(selector: Selector<any, State>) {
|
||||
return {
|
||||
selectPending: createSelector(selector, (state: State) => state.pending),
|
||||
selectError: createSelector(selector, (state: State) => state.error),
|
||||
};
|
||||
}
|
|
@ -1,5 +1,3 @@
|
|||
export * from './modify.action';
|
||||
export * from './modify.effect';
|
||||
export * from './modify.reducer';
|
||||
export * from './modify.state';
|
||||
export * from './member-modify.reducer';
|
||||
export * from './member-modify.state';
|
||||
|
||||
|
|
|
@ -6,25 +6,28 @@ import {
|
|||
import {
|
||||
State,
|
||||
initialState,
|
||||
} from './modify.state';
|
||||
} from './member-modify.state';
|
||||
|
||||
export function reducer(state = initialState, action: Actions): State {
|
||||
switch (action.type) {
|
||||
case ActionType.Modify: {
|
||||
return {
|
||||
pending: true,
|
||||
error: null,
|
||||
};
|
||||
}
|
||||
|
||||
case ActionType.ModifySuccess: {
|
||||
return {
|
||||
pending: false,
|
||||
error: null,
|
||||
};
|
||||
}
|
||||
|
||||
case ActionType.ModifyFailure: {
|
||||
return {
|
||||
pending: false,
|
||||
error: action.payload,
|
||||
};
|
||||
}
|
||||
|
|
@ -0,0 +1,23 @@
|
|||
import { Selector, createSelector } from '@ngrx/store';
|
||||
|
||||
import { RESTClientError } from '@loafer/ng-rest';
|
||||
|
||||
import { Member } from '@overflow/commons-typescript/model/member';
|
||||
|
||||
export interface State {
|
||||
pending: boolean;
|
||||
error: RESTClientError;
|
||||
}
|
||||
|
||||
export const initialState: State = {
|
||||
pending: false,
|
||||
error: null,
|
||||
};
|
||||
|
||||
|
||||
export function getSelectors(selector: Selector<any, State>) {
|
||||
return {
|
||||
selectPending: createSelector(selector, (state: State) => state.pending),
|
||||
selectError: createSelector(selector, (state: State) => state.error),
|
||||
};
|
||||
}
|
|
@ -1,11 +0,0 @@
|
|||
import { RESTClientError } from '@loafer/ng-rest';
|
||||
|
||||
import { Member } from '@overflow/commons-typescript/model/member';
|
||||
|
||||
export interface State {
|
||||
pending: boolean;
|
||||
}
|
||||
|
||||
export const initialState: State = {
|
||||
pending: false,
|
||||
};
|
|
@ -1,5 +1,2 @@
|
|||
export * from './reset-password.action';
|
||||
export * from './reset-password.effect';
|
||||
export * from './reset-password.reducer';
|
||||
export * from './reset-password.state';
|
||||
|
||||
export * from './member-reset-password.reducer';
|
||||
export * from './member-reset-password.state';
|
||||
|
|
|
@ -6,25 +6,28 @@ import {
|
|||
import {
|
||||
State,
|
||||
initialState,
|
||||
} from './signout.state';
|
||||
} from './member-reset-password.state';
|
||||
|
||||
export function reducer(state = initialState, action: Actions): State {
|
||||
switch (action.type) {
|
||||
case ActionType.Signout: {
|
||||
case ActionType.ResetPassword: {
|
||||
return {
|
||||
pending: true,
|
||||
error: null,
|
||||
};
|
||||
}
|
||||
|
||||
case ActionType.SignoutSuccess: {
|
||||
case ActionType.ResetPasswordSuccess: {
|
||||
return {
|
||||
pending: false,
|
||||
error: null,
|
||||
};
|
||||
}
|
||||
|
||||
case ActionType.SignoutFailure: {
|
||||
case ActionType.ResetPasswordFailure: {
|
||||
return {
|
||||
pending: false,
|
||||
error: action.payload,
|
||||
};
|
||||
}
|
||||
|
||||
|
@ -33,3 +36,4 @@ export function reducer(state = initialState, action: Actions): State {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,23 @@
|
|||
import { Selector, createSelector } from '@ngrx/store';
|
||||
|
||||
import { RESTClientError } from '@loafer/ng-rest';
|
||||
|
||||
import { Member } from '@overflow/commons-typescript/model/member';
|
||||
|
||||
export interface State {
|
||||
pending: boolean;
|
||||
error: RESTClientError;
|
||||
}
|
||||
|
||||
export const initialState: State = {
|
||||
pending: false,
|
||||
error: null,
|
||||
};
|
||||
|
||||
|
||||
export function getSelectors(selector: Selector<any, State>) {
|
||||
return {
|
||||
selectPending: createSelector(selector, (state: State) => state.pending),
|
||||
selectError: createSelector(selector, (state: State) => state.error),
|
||||
};
|
||||
}
|
|
@ -1,54 +0,0 @@
|
|||
import {
|
||||
Actions,
|
||||
ActionType,
|
||||
} from '../../entity/member/member.action';
|
||||
|
||||
import {
|
||||
State,
|
||||
initialState,
|
||||
} from './reset-password.state';
|
||||
|
||||
export function reducer(state = initialState, action: Actions): State {
|
||||
switch (action.type) {
|
||||
case ActionType.ResetPassword: {
|
||||
return {
|
||||
pending: true,
|
||||
};
|
||||
}
|
||||
|
||||
case ActionType.ResetPasswordSuccess: {
|
||||
return {
|
||||
pending: false,
|
||||
};
|
||||
}
|
||||
|
||||
case ActionType.ResetPasswordFailure: {
|
||||
return {
|
||||
pending: false,
|
||||
};
|
||||
}
|
||||
|
||||
case ActionType.ModifyPassword: {
|
||||
return {
|
||||
pending: true,
|
||||
};
|
||||
}
|
||||
|
||||
case ActionType.ModifyPasswordSuccess: {
|
||||
return {
|
||||
pending: false,
|
||||
};
|
||||
}
|
||||
|
||||
case ActionType.ModifyPasswordFailure: {
|
||||
return {
|
||||
pending: false,
|
||||
};
|
||||
}
|
||||
|
||||
default: {
|
||||
return state;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1,11 +0,0 @@
|
|||
import { RESTClientError } from '@loafer/ng-rest';
|
||||
|
||||
import { Member } from '@overflow/commons-typescript/model/member';
|
||||
|
||||
export interface State {
|
||||
pending: boolean;
|
||||
}
|
||||
|
||||
export const initialState: State = {
|
||||
pending: false,
|
||||
};
|
|
@ -1,2 +1,2 @@
|
|||
export * from './signin.reducer';
|
||||
export * from './signin.state';
|
||||
export * from './member-signin.reducer';
|
||||
export * from './member-signin.state';
|
||||
|
|
|
@ -0,0 +1,44 @@
|
|||
import {
|
||||
Actions as MemberActions,
|
||||
ActionType as MemberActionType,
|
||||
} from '../../entity/member/member.action';
|
||||
|
||||
import {
|
||||
State,
|
||||
initialState,
|
||||
} from './member-signin.state';
|
||||
|
||||
|
||||
import {
|
||||
Actions as AuthActions,
|
||||
ActionType as AuthActionType,
|
||||
} from '@overflow/shared/auth/store/container/auth';
|
||||
|
||||
export function reducer(state = initialState, action: MemberActions | AuthActions): State {
|
||||
switch (action.type) {
|
||||
case MemberActionType.Signin: {
|
||||
return {
|
||||
pending: true,
|
||||
error: null,
|
||||
};
|
||||
}
|
||||
|
||||
case AuthActionType.SigninSuccess: {
|
||||
return {
|
||||
pending: false,
|
||||
error: null,
|
||||
};
|
||||
}
|
||||
|
||||
case AuthActionType.SigninFailure: {
|
||||
return {
|
||||
pending: false,
|
||||
error: action.payload,
|
||||
};
|
||||
}
|
||||
|
||||
default: {
|
||||
return state;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,20 @@
|
|||
import { Selector, createSelector } from '@ngrx/store';
|
||||
|
||||
import { RESTClientError } from '@loafer/ng-rest';
|
||||
|
||||
export interface State {
|
||||
pending: boolean;
|
||||
error: RESTClientError;
|
||||
}
|
||||
|
||||
export const initialState: State = {
|
||||
pending: false,
|
||||
error: null,
|
||||
};
|
||||
|
||||
export function getSelectors(selector: Selector<any, State>) {
|
||||
return {
|
||||
selectPending: createSelector(selector, (state: State) => state.pending),
|
||||
selectError: createSelector(selector, (state: State) => state.error),
|
||||
};
|
||||
}
|
|
@ -1,48 +0,0 @@
|
|||
import {
|
||||
Actions,
|
||||
ActionType,
|
||||
} from '../../entity/member/member.action';
|
||||
|
||||
import {
|
||||
State,
|
||||
initialState,
|
||||
} from './signin.state';
|
||||
|
||||
export function reducer(state = initialState, action: Actions): State {
|
||||
switch (action.type) {
|
||||
case ActionType.Signin: {
|
||||
return {
|
||||
pending: true,
|
||||
};
|
||||
}
|
||||
|
||||
case ActionType.SigninSuccess: {
|
||||
const domainMember = action.payload.domainMember;
|
||||
return {
|
||||
pending: false,
|
||||
};
|
||||
}
|
||||
|
||||
case ActionType.SigninFailure: {
|
||||
return {
|
||||
pending: false,
|
||||
};
|
||||
}
|
||||
|
||||
case ActionType.SigninCookieSuccess: {
|
||||
return {
|
||||
pending: false,
|
||||
};
|
||||
}
|
||||
|
||||
case ActionType.SigninCookieFailure: {
|
||||
return {
|
||||
pending: false,
|
||||
};
|
||||
}
|
||||
|
||||
default: {
|
||||
return state;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,11 +0,0 @@
|
|||
import { RESTClientError } from '@loafer/ng-rest';
|
||||
import { Domain } from '@overflow/commons-typescript/model/domain';
|
||||
import { Member } from '@overflow/commons-typescript/model/member';
|
||||
|
||||
export interface State {
|
||||
pending: boolean;
|
||||
}
|
||||
|
||||
export const initialState: State = {
|
||||
pending: false,
|
||||
};
|
|
@ -1,2 +1,2 @@
|
|||
export * from './signout.reducer';
|
||||
export * from './signout.state';
|
||||
export * from './member-signout.reducer';
|
||||
export * from './member-signout.state';
|
||||
|
|
|
@ -0,0 +1,44 @@
|
|||
import {
|
||||
Actions as MemberActions,
|
||||
ActionType as MemberActionType,
|
||||
} from '../../entity/member/member.action';
|
||||
|
||||
import {
|
||||
State,
|
||||
initialState,
|
||||
} from './member-signout.state';
|
||||
|
||||
import {
|
||||
Actions as AuthActions,
|
||||
ActionType as AuthActionType,
|
||||
} from '@overflow/shared/auth/store/container/auth';
|
||||
|
||||
|
||||
export function reducer(state = initialState, action: MemberActions | AuthActions): State {
|
||||
switch (action.type) {
|
||||
case MemberActionType.Signout: {
|
||||
return {
|
||||
pending: true,
|
||||
error: null,
|
||||
};
|
||||
}
|
||||
|
||||
case AuthActionType.SignoutSuccess: {
|
||||
return {
|
||||
pending: false,
|
||||
error: null,
|
||||
};
|
||||
}
|
||||
|
||||
case AuthActionType.SignoutFailure: {
|
||||
return {
|
||||
pending: false,
|
||||
error: null,
|
||||
};
|
||||
}
|
||||
|
||||
default: {
|
||||
return state;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,20 @@
|
|||
import { Selector, createSelector } from '@ngrx/store';
|
||||
|
||||
import { RESTClientError } from '@loafer/ng-rest';
|
||||
|
||||
export interface State {
|
||||
pending: boolean;
|
||||
error: RESTClientError;
|
||||
}
|
||||
|
||||
export const initialState: State = {
|
||||
pending: false,
|
||||
error: null,
|
||||
};
|
||||
|
||||
export function getSelectors(selector: Selector<any, State>) {
|
||||
return {
|
||||
selectPending: createSelector(selector, (state: State) => state.pending),
|
||||
selectError: createSelector(selector, (state: State) => state.error),
|
||||
};
|
||||
}
|
|
@ -1,11 +0,0 @@
|
|||
import { RESTClientError } from '@loafer/ng-rest';
|
||||
import { Domain } from '@overflow/commons-typescript/model/domain';
|
||||
import { Member } from '@overflow/commons-typescript/model/member';
|
||||
|
||||
export interface State {
|
||||
pending: boolean;
|
||||
}
|
||||
|
||||
export const initialState: State = {
|
||||
pending: false,
|
||||
};
|
|
@ -1,5 +1,3 @@
|
|||
export * from './signup.action';
|
||||
export * from './signup.effect';
|
||||
export * from './signup.reducer';
|
||||
export * from './signup.state';
|
||||
export * from './member-signup.reducer';
|
||||
export * from './member-signup.state';
|
||||
|
||||
|
|
|
@ -6,25 +6,28 @@ import {
|
|||
import {
|
||||
State,
|
||||
initialState,
|
||||
} from './signup.state';
|
||||
} from './member-signup.state';
|
||||
|
||||
export function reducer(state = initialState, action: Actions): State {
|
||||
switch (action.type) {
|
||||
case ActionType.Signup: {
|
||||
return {
|
||||
pending: true,
|
||||
error: null,
|
||||
};
|
||||
}
|
||||
|
||||
case ActionType.SignupSuccess: {
|
||||
return {
|
||||
pending: false,
|
||||
error: null,
|
||||
};
|
||||
}
|
||||
|
||||
case ActionType.SignupFailure: {
|
||||
return {
|
||||
pending: false,
|
||||
error: action.payload,
|
||||
};
|
||||
}
|
||||
|
|
@ -0,0 +1,20 @@
|
|||
import { Selector, createSelector } from '@ngrx/store';
|
||||
|
||||
import { RESTClientError } from '@loafer/ng-rest';
|
||||
|
||||
export interface State {
|
||||
pending: boolean;
|
||||
error: RESTClientError;
|
||||
}
|
||||
|
||||
export const initialState: State = {
|
||||
pending: false,
|
||||
error: null,
|
||||
};
|
||||
|
||||
export function getSelectors(selector: Selector<any, State>) {
|
||||
return {
|
||||
selectPending: createSelector(selector, (state: State) => state.pending),
|
||||
selectError: createSelector(selector, (state: State) => state.error),
|
||||
};
|
||||
}
|
|
@ -1,11 +0,0 @@
|
|||
import { RESTClientError } from '@loafer/ng-rest';
|
||||
|
||||
import { Member } from '@overflow/commons-typescript/model/member';
|
||||
|
||||
export interface State {
|
||||
pending: boolean;
|
||||
}
|
||||
|
||||
export const initialState: State = {
|
||||
pending: false,
|
||||
};
|
2
@overflow/member/store/entity/member-totp/index.ts
Normal file
2
@overflow/member/store/entity/member-totp/index.ts
Normal file
|
@ -0,0 +1,2 @@
|
|||
export * from './member-totp.action';
|
||||
export * from './member-totp.effect';
|
|
@ -5,17 +5,17 @@ import { RESTClientError } from '@loafer/ng-rest';
|
|||
import { Member } from '@overflow/commons-typescript/model/member';
|
||||
|
||||
export enum ActionType {
|
||||
CreateTotp = '[member.totp] CreateTotp',
|
||||
CreateTotpSuccess = '[member.totp] CreateTotpSuccess',
|
||||
CreateTotpFailure = '[member.totp] CreateTotpFailure',
|
||||
CreateTotp = '[member.member-totp] CreateTotp',
|
||||
CreateTotpSuccess = '[member.member-totp] CreateTotpSuccess',
|
||||
CreateTotpFailure = '[member.member-totp] CreateTotpFailure',
|
||||
|
||||
Regist = '[member.totp] Regist',
|
||||
RegistSuccess = '[member.totp] RegistSuccess',
|
||||
RegistFailure = '[member.totp] RegistFailure',
|
||||
Regist = '[member.member-totp] Regist',
|
||||
RegistSuccess = '[member.member-totp] RegistSuccess',
|
||||
RegistFailure = '[member.member-totp] RegistFailure',
|
||||
|
||||
CheckCodeForMember = '[member.totp] CheckCodeForMember',
|
||||
CheckCodeForMemberSuccess = '[member.totp] CheckCodeForMemberSuccess',
|
||||
CheckCodeForMemberFailure = '[member.totp] CheckCodeForMemberFailure',
|
||||
CheckCodeForMember = '[member.member-totp] CheckCodeForMember',
|
||||
CheckCodeForMemberSuccess = '[member.member-totp] CheckCodeForMemberSuccess',
|
||||
CheckCodeForMemberFailure = '[member.member-totp] CheckCodeForMemberFailure',
|
||||
}
|
||||
|
||||
export class CreateTotp implements Action {
|
|
@ -1,8 +1,8 @@
|
|||
import { TestBed, inject } from '@angular/core/testing';
|
||||
|
||||
import { Effects } from './modify.effect';
|
||||
import { Effects } from './member-totp.effect';
|
||||
|
||||
describe('Modify.Effects', () => {
|
||||
describe('member-totp.Effects', () => {
|
||||
beforeEach(() => {
|
||||
TestBed.configureTestingModule({
|
||||
providers: [Effects]
|
|
@ -15,7 +15,7 @@ import 'rxjs/add/operator/map';
|
|||
import 'rxjs/add/operator/take';
|
||||
|
||||
import { RESTClientError } from '@loafer/ng-rest';
|
||||
import { MemberTotpService } from '../../service/member-totp.service';
|
||||
import { MemberTotpService } from '../../../service/member-totp.service';
|
||||
|
||||
import {
|
||||
CreateTotp,
|
||||
|
@ -31,11 +31,10 @@ import {
|
|||
CheckCodeForMemberFailure,
|
||||
|
||||
ActionType,
|
||||
} from './totp.action';
|
||||
} from './member-totp.action';
|
||||
|
||||
@Injectable()
|
||||
export class Effects {
|
||||
private _returnURL: any;
|
||||
|
||||
constructor(
|
||||
private actions$: Actions,
|
||||
|
@ -54,7 +53,7 @@ export class Effects {
|
|||
.map((result: any) => {
|
||||
const key = result['key'];
|
||||
const uri = result['uri'];
|
||||
return new CreateTotpSuccess({key: key, uri: uri});
|
||||
return new CreateTotpSuccess({ key: key, uri: uri });
|
||||
})
|
||||
.catch((error: RESTClientError) => {
|
||||
return of(new CreateTotpFailure(error));
|
||||
|
@ -81,7 +80,6 @@ export class Effects {
|
|||
.ofType(ActionType.CheckCodeForMember)
|
||||
.map((action: Regist) => action.payload)
|
||||
.switchMap((payload) => {
|
||||
// this._returnURL = payload.returnURL;
|
||||
return this.memberTotpService.checkCodeForMember(payload.member, payload.code);
|
||||
})
|
||||
.map((result: any) => {
|
|
@ -7,90 +7,44 @@ import { DomainMember } from '@overflow/commons-typescript/model/domain';
|
|||
|
||||
export enum ActionType {
|
||||
Signin = '[member.member] Signin',
|
||||
SigninSuccess = '[member.member] SigninSuccess',
|
||||
SigninFailure = '[member.member] SigninFailure',
|
||||
SigninRedirect = '[member.member] SigninRedirect',
|
||||
|
||||
SigninCookie = '[member.auth] SigninCookie',
|
||||
SigninCookieSuccess = '[member.auth] SigninCookieSuccess',
|
||||
SigninCookieFailure = '[member.auth] SigninCookieFailure',
|
||||
SigninCookie = '[member.member] SigninCookie',
|
||||
|
||||
Signout = '[member.auth] Signout',
|
||||
SignoutSuccess = '[member.auth] SignoutSuccess',
|
||||
SignoutFailure = '[member.auth] SignoutFailure',
|
||||
Signout = '[member.member] Signout',
|
||||
|
||||
Signup = '[member.signup] Signup',
|
||||
SignupSuccess = '[member.signup] SignupSuccess',
|
||||
SignupFailure = '[member.signup] SignupFailure',
|
||||
Signup = '[member.member] Signup',
|
||||
SignupSuccess = '[member.member] SignupSuccess',
|
||||
SignupFailure = '[member.member] SignupFailure',
|
||||
|
||||
Modify = '[member.modify] Modify',
|
||||
ModifySuccess = '[member.modify] ModifySuccess',
|
||||
ModifyFailure = '[member.modify] ModifyFailure',
|
||||
Modify = '[member.member] Modify',
|
||||
ModifySuccess = '[member.member] ModifySuccess',
|
||||
ModifyFailure = '[member.member] ModifyFailure',
|
||||
|
||||
ResetPassword = '[member.resetPassword] ResetPassword',
|
||||
ResetPasswordSuccess = '[member.resetPassword] ResetPasswordSuccess',
|
||||
ResetPasswordFailure = '[member.resetPassword] ResetPasswordFailure',
|
||||
ResetPassword = '[member.member] ResetPassword',
|
||||
ResetPasswordSuccess = '[member.member] ResetPasswordSuccess',
|
||||
ResetPasswordFailure = '[member.member] ResetPasswordFailure',
|
||||
|
||||
ModifyPassword = '[member.modifyPassword] ModifyPassword',
|
||||
ModifyPasswordSuccess = '[member.modifyPassword] ModifyPasswordSuccess',
|
||||
ModifyPasswordFailure = '[member.modifyPassword] ModifyPasswordFailure',
|
||||
ModifyPassword = '[member.member] ModifyPassword',
|
||||
ModifyPasswordSuccess = '[member.member] ModifyPasswordSuccess',
|
||||
ModifyPasswordFailure = '[member.member] ModifyPasswordFailure',
|
||||
}
|
||||
|
||||
export class Signin implements Action {
|
||||
readonly type = ActionType.Signin;
|
||||
|
||||
constructor(public payload: { email: string, password: string, returnURL: string }) { }
|
||||
}
|
||||
|
||||
export class SigninSuccess implements Action {
|
||||
readonly type = ActionType.SigninSuccess;
|
||||
|
||||
constructor(public payload: { authToken: string, domainMember: DomainMember }) { }
|
||||
}
|
||||
|
||||
export class SigninFailure implements Action {
|
||||
readonly type = ActionType.SigninFailure;
|
||||
|
||||
constructor(public payload: RESTClientError) { }
|
||||
}
|
||||
|
||||
export class SigninRedirect implements Action {
|
||||
readonly type = ActionType.SigninRedirect;
|
||||
constructor(public payload: string) { }
|
||||
constructor(public payload: { email: string, password: string }) { }
|
||||
}
|
||||
|
||||
export class SigninCookie implements Action {
|
||||
readonly type = ActionType.SigninCookie;
|
||||
|
||||
constructor(public payload: { authToken: string, returnURL: string }) { }
|
||||
}
|
||||
|
||||
export class SigninCookieSuccess implements Action {
|
||||
readonly type = ActionType.SigninCookieSuccess;
|
||||
|
||||
constructor(public payload: DomainMember) { }
|
||||
}
|
||||
|
||||
export class SigninCookieFailure implements Action {
|
||||
readonly type = ActionType.SigninCookieFailure;
|
||||
|
||||
constructor(public payload: RESTClientError) { }
|
||||
constructor(public payload: { authToken: string }) { }
|
||||
}
|
||||
|
||||
export class Signout implements Action {
|
||||
readonly type = ActionType.Signout;
|
||||
}
|
||||
|
||||
export class SignoutSuccess implements Action {
|
||||
readonly type = ActionType.SignoutSuccess;
|
||||
}
|
||||
|
||||
export class SignoutFailure implements Action {
|
||||
readonly type = ActionType.SignoutFailure;
|
||||
|
||||
constructor(public payload: RESTClientError) { }
|
||||
}
|
||||
|
||||
export class Signup implements Action {
|
||||
readonly type = ActionType.Signup;
|
||||
|
||||
|
@ -148,7 +102,7 @@ export class ResetPasswordFailure implements Action {
|
|||
export class ModifyPassword implements Action {
|
||||
readonly type = ActionType.ModifyPassword;
|
||||
|
||||
constructor(public payload: { token: string, pw: string, confirmPw: string } ) {}
|
||||
constructor(public payload: { token: string, password: string, confirmPassword: string } ) {}
|
||||
}
|
||||
|
||||
export class ModifyPasswordSuccess implements Action {
|
||||
|
@ -163,18 +117,10 @@ export class ModifyPasswordFailure implements Action {
|
|||
constructor(public payload: RESTClientError) {}
|
||||
}
|
||||
|
||||
|
||||
export type Actions =
|
||||
| Signin
|
||||
| SigninSuccess
|
||||
| SigninFailure
|
||||
| SigninRedirect
|
||||
| SigninCookie
|
||||
| SigninCookieSuccess
|
||||
| SigninCookieFailure
|
||||
| Signout
|
||||
| SignoutSuccess
|
||||
| SignoutFailure
|
||||
| Signup
|
||||
| SignupSuccess
|
||||
| SignupFailure
|
||||
|
|
|
@ -14,14 +14,35 @@ import 'rxjs/add/operator/map';
|
|||
import 'rxjs/add/operator/take';
|
||||
|
||||
import { Member } from '@overflow/commons-typescript/model/member';
|
||||
import { MemberService } from '../../service/member.service';
|
||||
import { MemberService } from '../../../service/member.service';
|
||||
import { RESTClientError } from '@loafer/ng-rest';
|
||||
|
||||
import {
|
||||
Signin,
|
||||
SigninCookie,
|
||||
Signup,
|
||||
SignupSuccess,
|
||||
SignupFailure,
|
||||
Modify,
|
||||
ModifySuccess,
|
||||
ModifyFailure,
|
||||
ResetPassword,
|
||||
ResetPasswordSuccess,
|
||||
ResetPasswordFailure,
|
||||
ModifyPassword,
|
||||
ModifyPasswordSuccess,
|
||||
ModifyPasswordFailure,
|
||||
ActionType,
|
||||
} from './signup.action';
|
||||
} from './member.action';
|
||||
|
||||
import {
|
||||
SigninSuccess,
|
||||
SigninFailure,
|
||||
SigninCookieSuccess,
|
||||
SigninCookieFailure,
|
||||
} from '@overflow/shared/auth/store/container/auth';
|
||||
import { DomainMember } from '@overflow/commons-typescript/model/domain';
|
||||
|
||||
|
||||
@Injectable()
|
||||
export class Effects {
|
||||
|
@ -31,21 +52,73 @@ 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))
|
||||
this.memberService.signup(payload.member, payload.password)
|
||||
.map(member => new SignupSuccess(member))
|
||||
.catch(error => of(new SignupFailure(error)))
|
||||
);
|
||||
|
||||
@Effect({ dispatch: false })
|
||||
signupSuccess$ = this.actions$
|
||||
.ofType(ActionType.SignupSuccess)
|
||||
.do(() => this.router.navigate(['/']));
|
||||
@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 =>
|
||||
this.memberService
|
||||
.sendEmailResetPassword(payload)
|
||||
.map(member => new ResetPasswordSuccess(member))
|
||||
.catch(error => of(new ResetPasswordFailure(error)))
|
||||
);
|
||||
|
||||
@Effect()
|
||||
ModifyPassword$: Observable<Action> = this.actions$
|
||||
.ofType(ActionType.ModifyPassword)
|
||||
.map((action: ModifyPassword) => action.payload)
|
||||
.exhaustMap(payload =>
|
||||
this.memberService
|
||||
.resetPassword(payload.token, payload.password, payload.confirmPassword)
|
||||
.map(member => new ModifyPasswordSuccess(member))
|
||||
.catch(error => of(new ModifyPasswordFailure(error)))
|
||||
);
|
||||
}
|
||||
|
|
|
@ -1,45 +0,0 @@
|
|||
import {
|
||||
Actions,
|
||||
ActionType,
|
||||
} from './signup.action';
|
||||
|
||||
import {
|
||||
State,
|
||||
initialState,
|
||||
} from './signup.state';
|
||||
|
||||
import { Member } from '@overflow/commons-typescript/model/member';
|
||||
|
||||
export function reducer(state = initialState, action: Actions): State {
|
||||
switch (action.type) {
|
||||
case ActionType.Signup: {
|
||||
return {
|
||||
...state,
|
||||
error: null,
|
||||
pending: true,
|
||||
};
|
||||
}
|
||||
|
||||
case ActionType.SignupSuccess: {
|
||||
return {
|
||||
...state,
|
||||
error: null,
|
||||
pending: false,
|
||||
member: action.payload,
|
||||
};
|
||||
}
|
||||
|
||||
case ActionType.SignupFailure: {
|
||||
return {
|
||||
...state,
|
||||
error: action.payload,
|
||||
pending: false,
|
||||
member: null,
|
||||
};
|
||||
}
|
||||
|
||||
default: {
|
||||
return state;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,15 +0,0 @@
|
|||
import { RESTClientError } from '@loafer/ng-rest';
|
||||
|
||||
import { Member } from '@overflow/commons-typescript/model/member';
|
||||
|
||||
export interface State {
|
||||
error: RESTClientError | null;
|
||||
pending: boolean;
|
||||
member: Member | null;
|
||||
}
|
||||
|
||||
export const initialState: State = {
|
||||
error: null,
|
||||
pending: false,
|
||||
member: null,
|
||||
};
|
|
@ -3,64 +3,70 @@ import {
|
|||
createFeatureSelector,
|
||||
} from '@ngrx/store';
|
||||
|
||||
import { StateSelector } from '@overflow/core/ngrx/store';
|
||||
|
||||
import { MODULE } from '../member.constant';
|
||||
|
||||
import * as AuthStore from './auth';
|
||||
import * as SignupStore from './signup';
|
||||
import * as TotpStore from './totp';
|
||||
import * as ModifyStore from './modify';
|
||||
import * as ResetPasswordStore from './reset-password';
|
||||
import * as MemberEntityStore from './entity/member';
|
||||
import * as MemberTOTPEntityStore from './entity/member-totp';
|
||||
|
||||
import * as MemberSignupContainerStore from './container/signup';
|
||||
import * as MemberSigninContainerStore from './container/signin';
|
||||
import * as MemberModifyPasswordContainerStore from './container/modify-password';
|
||||
import * as MemberResetPasswordContainerStore from './container/reset-password';
|
||||
import * as MemberModifyContainerStore from './container/modify';
|
||||
import * as MemberSignoutContainerStore from './container/signout';
|
||||
|
||||
|
||||
export interface State {
|
||||
auth: AuthStore.State;
|
||||
signup: SignupStore.State;
|
||||
totp: TotpStore.State;
|
||||
modify: ModifyStore.State;
|
||||
resetPassword: ResetPasswordStore.State;
|
||||
member_signup_container: MemberSignupContainerStore.State;
|
||||
member_signin_container: MemberSigninContainerStore.State;
|
||||
member_modify_password_container: MemberModifyPasswordContainerStore.State;
|
||||
member_reset_password_container: MemberResetPasswordContainerStore.State;
|
||||
member_modify_container: MemberModifyContainerStore.State;
|
||||
member_signout_container: MemberSignoutContainerStore.State;
|
||||
}
|
||||
|
||||
export const REDUCERS = {
|
||||
auth: AuthStore.reducer,
|
||||
signup: SignupStore.reducer,
|
||||
totp: TotpStore.reducer,
|
||||
modify: ModifyStore.reducer,
|
||||
resetPassword: ResetPasswordStore.reducer,
|
||||
member_signup_container: MemberSignupContainerStore.reducer,
|
||||
member_signin_container: MemberSigninContainerStore.reducer,
|
||||
member_modify_password_container: MemberModifyPasswordContainerStore.reducer,
|
||||
member_reset_password_container: MemberResetPasswordContainerStore.reducer,
|
||||
member_modify_container: MemberModifyContainerStore.reducer,
|
||||
member_signout_container: MemberSignoutContainerStore.reducer,
|
||||
};
|
||||
|
||||
export const EFFECTS = [
|
||||
AuthStore.Effects,
|
||||
SignupStore.Effects,
|
||||
TotpStore.Effects,
|
||||
ModifyStore.Effects,
|
||||
ResetPasswordStore.Effects,
|
||||
MemberEntityStore.Effects,
|
||||
MemberTOTPEntityStore.Effects,
|
||||
];
|
||||
|
||||
export const selectMemberState = createFeatureSelector<State>(MODULE.name);
|
||||
export const selectState = createFeatureSelector<State>(MODULE.name);
|
||||
|
||||
export const AuthSelector = new StateSelector<AuthStore.State>(createSelector(
|
||||
selectMemberState,
|
||||
(state: State) => state.auth
|
||||
export const MemberSignupContainerSelector = MemberSignupContainerStore.getSelectors(createSelector(
|
||||
selectState,
|
||||
(state: State) => state.member_signup_container
|
||||
));
|
||||
|
||||
export const SignupSelector = new StateSelector<SignupStore.State>(createSelector(
|
||||
selectMemberState,
|
||||
(state: State) => state.signup
|
||||
export const MemberSigninContainerSelector = MemberSigninContainerStore.getSelectors(createSelector(
|
||||
selectState,
|
||||
(state: State) => state.member_signin_container
|
||||
));
|
||||
|
||||
export const TotpSelector = new StateSelector<TotpStore.State>(createSelector(
|
||||
selectMemberState,
|
||||
(state: State) => state.totp
|
||||
export const MemberModifyPasswordContainerSelector = MemberModifyPasswordContainerStore.getSelectors(createSelector(
|
||||
selectState,
|
||||
(state: State) => state.member_modify_password_container
|
||||
));
|
||||
|
||||
export const ModifySelector = new StateSelector<ModifyStore.State>(createSelector(
|
||||
selectMemberState,
|
||||
(state: State) => state.modify
|
||||
export const MemberResetPasswordContainerSelector = MemberResetPasswordContainerStore.getSelectors(createSelector(
|
||||
selectState,
|
||||
(state: State) => state.member_reset_password_container
|
||||
));
|
||||
|
||||
export const ResetPasswordSelector = new StateSelector<ResetPasswordStore.State>(createSelector(
|
||||
selectMemberState,
|
||||
(state: State) => state.resetPassword
|
||||
export const MemberModifyContainerSelector = MemberModifyContainerStore.getSelectors(createSelector(
|
||||
selectState,
|
||||
(state: State) => state.member_modify_container
|
||||
));
|
||||
|
||||
export const MemberSignoutContainerSelector = MemberSignoutContainerStore.getSelectors(createSelector(
|
||||
selectState,
|
||||
(state: State) => state.member_signout_container
|
||||
));
|
||||
|
|
|
@ -1,5 +0,0 @@
|
|||
export * from './modify.action';
|
||||
export * from './modify.effect';
|
||||
export * from './modify.reducer';
|
||||
export * from './modify.state';
|
||||
|
|
@ -1,35 +0,0 @@
|
|||
import { Action } from '@ngrx/store';
|
||||
|
||||
import { RESTClientError } from '@loafer/ng-rest';
|
||||
|
||||
import { Member } from '@overflow/commons-typescript/model/member';
|
||||
|
||||
export enum ActionType {
|
||||
Modify = '[member.modify] Modify',
|
||||
ModifySuccess = '[member.modify] ModifySuccess',
|
||||
ModifyFailure = '[member.modify] ModifyFailure',
|
||||
}
|
||||
|
||||
export class Modify implements Action {
|
||||
readonly type = ActionType.Modify;
|
||||
|
||||
constructor(public payload: Member ) {}
|
||||
}
|
||||
|
||||
export class ModifySuccess implements Action {
|
||||
readonly type = ActionType.ModifySuccess;
|
||||
|
||||
constructor(public payload: Member) {}
|
||||
}
|
||||
|
||||
export class ModifyFailure implements Action {
|
||||
readonly type = ActionType.ModifyFailure;
|
||||
|
||||
constructor(public payload: RESTClientError) {}
|
||||
}
|
||||
|
||||
export type Actions =
|
||||
| Modify
|
||||
| ModifySuccess
|
||||
| ModifyFailure
|
||||
;
|
|
@ -1,50 +0,0 @@
|
|||
import { Injectable } from '@angular/core';
|
||||
import { Router } from '@angular/router';
|
||||
|
||||
import { Effect, Actions } 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 { MemberService } from '../../service/member.service';
|
||||
|
||||
import {
|
||||
Modify,
|
||||
ModifySuccess,
|
||||
ModifyFailure,
|
||||
ActionType
|
||||
} from './modify.action';
|
||||
|
||||
@Injectable()
|
||||
export class Effects {
|
||||
|
||||
constructor(
|
||||
private actions$: Actions,
|
||||
private memberService: MemberService,
|
||||
private router: Router
|
||||
) { }
|
||||
|
||||
@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({ dispatch: false })
|
||||
// modifySuccess$ = this.actions$
|
||||
// .ofType(ActionType.ModifySuccess)
|
||||
// .do(() => this.router.navigate(['/']));
|
||||
|
||||
}
|
|
@ -1,15 +0,0 @@
|
|||
import { RESTClientError } from '@loafer/ng-rest';
|
||||
|
||||
import { Member } from '@overflow/commons-typescript/model/member';
|
||||
|
||||
export interface State {
|
||||
error: RESTClientError | null;
|
||||
pending: boolean;
|
||||
member: Member | null;
|
||||
}
|
||||
|
||||
export const initialState: State = {
|
||||
error: null,
|
||||
pending: false,
|
||||
member: null,
|
||||
};
|
|
@ -1,5 +0,0 @@
|
|||
export * from './reset-password.action';
|
||||
export * from './reset-password.effect';
|
||||
export * from './reset-password.reducer';
|
||||
export * from './reset-password.state';
|
||||
|
|
@ -1,63 +0,0 @@
|
|||
import { Action } from '@ngrx/store';
|
||||
|
||||
import { RESTClientError } from '@loafer/ng-rest';
|
||||
|
||||
import { Member } from '@overflow/commons-typescript/model/member';
|
||||
|
||||
export enum ActionType {
|
||||
ResetPassword = '[member.resetPassword] ResetPassword',
|
||||
ResetPasswordSuccess = '[member.resetPassword] ResetPasswordSuccess',
|
||||
ResetPasswordFailure = '[member.resetPassword] ResetPasswordFailure',
|
||||
}
|
||||
|
||||
export class ResetPassword implements Action {
|
||||
readonly type = ActionType.ResetPassword;
|
||||
|
||||
constructor(public payload: string ) {}
|
||||
}
|
||||
|
||||
export class ResetPasswordSuccess implements Action {
|
||||
readonly type = ActionType.ResetPasswordSuccess;
|
||||
|
||||
constructor(public payload: Member) {}
|
||||
}
|
||||
|
||||
export class ResetPasswordFailure implements Action {
|
||||
readonly type = ActionType.ResetPasswordFailure;
|
||||
|
||||
constructor(public payload: RESTClientError) {}
|
||||
}
|
||||
|
||||
export type Actions =
|
||||
| ResetPassword
|
||||
| ResetPasswordSuccess
|
||||
| ResetPasswordFailure
|
||||
| ModifyPassword
|
||||
| ModifyPasswordSuccess
|
||||
| ModifyPasswordFailure
|
||||
;
|
||||
|
||||
|
||||
export enum ActionType {
|
||||
ModifyPassword = '[member.modifyPassword] ModifyPassword',
|
||||
ModifyPasswordSuccess = '[member.modifyPassword] ModifyPasswordSuccess',
|
||||
ModifyPasswordFailure = '[member.modifyPassword] ModifyPasswordFailure',
|
||||
}
|
||||
|
||||
export class ModifyPassword implements Action {
|
||||
readonly type = ActionType.ModifyPassword;
|
||||
|
||||
constructor(public payload: { token: string, pw: string, confirmPw: string } ) {}
|
||||
}
|
||||
|
||||
export class ModifyPasswordSuccess implements Action {
|
||||
readonly type = ActionType.ModifyPasswordSuccess;
|
||||
|
||||
constructor(public payload: Member) {}
|
||||
}
|
||||
|
||||
export class ModifyPasswordFailure implements Action {
|
||||
readonly type = ActionType.ModifyPasswordFailure;
|
||||
|
||||
constructor(public payload: RESTClientError) {}
|
||||
}
|
|
@ -1,15 +0,0 @@
|
|||
import { TestBed, inject } from '@angular/core/testing';
|
||||
|
||||
import { Effects } from './reset-password.effect';
|
||||
|
||||
describe('ResetPassword.Effects', () => {
|
||||
beforeEach(() => {
|
||||
TestBed.configureTestingModule({
|
||||
providers: [Effects]
|
||||
});
|
||||
});
|
||||
|
||||
it('should be created', inject([Effects], (effects: Effects) => {
|
||||
expect(effects).toBeTruthy();
|
||||
}));
|
||||
});
|
|
@ -1,64 +0,0 @@
|
|||
import { Injectable } from '@angular/core';
|
||||
import { Router } from '@angular/router';
|
||||
|
||||
import { Effect, Actions } 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 { MemberService } from '../../service/member.service';
|
||||
|
||||
import {
|
||||
ResetPassword,
|
||||
ResetPasswordSuccess,
|
||||
ResetPasswordFailure,
|
||||
ModifyPassword,
|
||||
ModifyPasswordSuccess,
|
||||
ModifyPasswordFailure,
|
||||
ActionType
|
||||
} from './reset-password.action';
|
||||
|
||||
@Injectable()
|
||||
export class Effects {
|
||||
|
||||
constructor(
|
||||
private actions$: Actions,
|
||||
private memberService: MemberService,
|
||||
private router: Router
|
||||
) { }
|
||||
|
||||
@Effect()
|
||||
ResetPassword$: Observable<Action> = this.actions$
|
||||
.ofType(ActionType.ResetPassword)
|
||||
.map((action: ResetPassword) => action.payload)
|
||||
.exhaustMap(payload =>
|
||||
this.memberService
|
||||
.sendEmailResetPassword(payload)
|
||||
.map(_member => new ResetPasswordSuccess(_member))
|
||||
.catch(error => of(new ResetPasswordFailure(error)))
|
||||
);
|
||||
|
||||
@Effect()
|
||||
ModifyPassword$: Observable<Action> = this.actions$
|
||||
.ofType(ActionType.ModifyPassword)
|
||||
.map((action: ModifyPassword) => action.payload)
|
||||
.exhaustMap(payload =>
|
||||
this.memberService
|
||||
.resetPassword(payload.token, payload.pw, payload.confirmPw)
|
||||
.map(_member => new ModifyPasswordSuccess(_member))
|
||||
.catch(error => of(new ModifyPasswordFailure(error)))
|
||||
);
|
||||
//
|
||||
// @Effect({ dispatch: false })
|
||||
// ResetPasswordSuccess$ = this.actions$
|
||||
// .ofType(ActionType.ResetPasswordSuccess)
|
||||
// .do(() => this.router.navigate(['/']));
|
||||
|
||||
}
|
|
@ -1,70 +0,0 @@
|
|||
import {
|
||||
Actions,
|
||||
ActionType,
|
||||
} from './reset-password.action';
|
||||
|
||||
import {
|
||||
State,
|
||||
initialState,
|
||||
} from './reset-password.state';
|
||||
|
||||
export function reducer(state = initialState, action: Actions): State {
|
||||
switch (action.type) {
|
||||
case ActionType.ResetPassword: {
|
||||
return {
|
||||
...state,
|
||||
error: null,
|
||||
pending: true,
|
||||
};
|
||||
}
|
||||
|
||||
case ActionType.ResetPasswordSuccess: {
|
||||
return {
|
||||
...state,
|
||||
error: null,
|
||||
pending: false,
|
||||
member: action.payload,
|
||||
};
|
||||
}
|
||||
|
||||
case ActionType.ResetPasswordFailure: {
|
||||
return {
|
||||
...state,
|
||||
error: action.payload,
|
||||
pending: false,
|
||||
member: null,
|
||||
};
|
||||
}
|
||||
|
||||
case ActionType.ModifyPassword: {
|
||||
return {
|
||||
...state,
|
||||
error: null,
|
||||
pending: true,
|
||||
};
|
||||
}
|
||||
|
||||
case ActionType.ModifyPasswordSuccess: {
|
||||
return {
|
||||
...state,
|
||||
error: null,
|
||||
pending: false,
|
||||
member: action.payload,
|
||||
};
|
||||
}
|
||||
|
||||
case ActionType.ModifyPasswordFailure: {
|
||||
return {
|
||||
...state,
|
||||
error: action.payload,
|
||||
pending: false,
|
||||
member: null,
|
||||
};
|
||||
}
|
||||
|
||||
default: {
|
||||
return state;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1,15 +0,0 @@
|
|||
import { RESTClientError } from '@loafer/ng-rest';
|
||||
|
||||
import { Member } from '@overflow/commons-typescript/model/member';
|
||||
|
||||
export interface State {
|
||||
error: RESTClientError | null;
|
||||
pending: boolean;
|
||||
member: Member | null;
|
||||
}
|
||||
|
||||
export const initialState: State = {
|
||||
error: null,
|
||||
pending: false,
|
||||
member: null,
|
||||
};
|
|
@ -1,5 +0,0 @@
|
|||
export * from './signup.action';
|
||||
export * from './signup.effect';
|
||||
export * from './signup.reducer';
|
||||
export * from './signup.state';
|
||||
|
|
@ -1,35 +0,0 @@
|
|||
import { Action } from '@ngrx/store';
|
||||
|
||||
import { RESTClientError } from '@loafer/ng-rest';
|
||||
|
||||
import { Member } from '@overflow/commons-typescript/model/member';
|
||||
|
||||
export enum ActionType {
|
||||
Signup = '[member.signup] Signup',
|
||||
SignupSuccess = '[member.signup] SignupSuccess',
|
||||
SignupFailure = '[member.signup] SignupFailure',
|
||||
}
|
||||
|
||||
export class Signup implements Action {
|
||||
readonly type = ActionType.Signup;
|
||||
|
||||
constructor(public payload: {member: Member, password: string}) {}
|
||||
}
|
||||
|
||||
export class SignupSuccess implements Action {
|
||||
readonly type = ActionType.SignupSuccess;
|
||||
|
||||
constructor(public payload: Member) {}
|
||||
}
|
||||
|
||||
export class SignupFailure implements Action {
|
||||
readonly type = ActionType.SignupFailure;
|
||||
|
||||
constructor(public payload: RESTClientError) {}
|
||||
}
|
||||
|
||||
export type Actions =
|
||||
| Signup
|
||||
| SignupSuccess
|
||||
| SignupFailure
|
||||
;
|
|
@ -1,15 +0,0 @@
|
|||
import { TestBed, inject } from '@angular/core/testing';
|
||||
|
||||
import { Effects } from './signup.effect';
|
||||
|
||||
describe('Signup.Effects', () => {
|
||||
beforeEach(() => {
|
||||
TestBed.configureTestingModule({
|
||||
providers: [Effects]
|
||||
});
|
||||
});
|
||||
|
||||
it('should be created', inject([Effects], (effects: Effects) => {
|
||||
expect(effects).toBeTruthy();
|
||||
}));
|
||||
});
|
|
@ -1,51 +0,0 @@
|
|||
import { Injectable } from '@angular/core';
|
||||
import { Router } from '@angular/router';
|
||||
|
||||
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 { Member } from '@overflow/commons-typescript/model/member';
|
||||
import { MemberService } from '../../service/member.service';
|
||||
|
||||
import {
|
||||
Signup,
|
||||
SignupSuccess,
|
||||
SignupFailure,
|
||||
ActionType,
|
||||
} from './signup.action';
|
||||
|
||||
@Injectable()
|
||||
export class Effects {
|
||||
|
||||
constructor(
|
||||
private actions$: Actions,
|
||||
private memberService: MemberService,
|
||||
private router: Router
|
||||
) { }
|
||||
|
||||
@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({ dispatch: false })
|
||||
signupSuccess$ = this.actions$
|
||||
.ofType(ActionType.SignupSuccess)
|
||||
.do(() => this.router.navigate(['/']));
|
||||
|
||||
}
|
|
@ -1,45 +0,0 @@
|
|||
import {
|
||||
Actions,
|
||||
ActionType,
|
||||
} from './signup.action';
|
||||
|
||||
import {
|
||||
State,
|
||||
initialState,
|
||||
} from './signup.state';
|
||||
|
||||
import { Member } from '@overflow/commons-typescript/model/member';
|
||||
|
||||
export function reducer(state = initialState, action: Actions): State {
|
||||
switch (action.type) {
|
||||
case ActionType.Signup: {
|
||||
return {
|
||||
...state,
|
||||
error: null,
|
||||
pending: true,
|
||||
};
|
||||
}
|
||||
|
||||
case ActionType.SignupSuccess: {
|
||||
return {
|
||||
...state,
|
||||
error: null,
|
||||
pending: false,
|
||||
member: action.payload,
|
||||
};
|
||||
}
|
||||
|
||||
case ActionType.SignupFailure: {
|
||||
return {
|
||||
...state,
|
||||
error: action.payload,
|
||||
pending: false,
|
||||
member: null,
|
||||
};
|
||||
}
|
||||
|
||||
default: {
|
||||
return state;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,15 +0,0 @@
|
|||
import { RESTClientError } from '@loafer/ng-rest';
|
||||
|
||||
import { Member } from '@overflow/commons-typescript/model/member';
|
||||
|
||||
export interface State {
|
||||
error: RESTClientError | null;
|
||||
pending: boolean;
|
||||
member: Member | null;
|
||||
}
|
||||
|
||||
export const initialState: State = {
|
||||
error: null,
|
||||
pending: false,
|
||||
member: null,
|
||||
};
|
|
@ -1,4 +0,0 @@
|
|||
export * from './totp.action';
|
||||
export * from './totp.effect';
|
||||
export * from './totp.reducer';
|
||||
export * from './totp.state';
|
|
@ -1,15 +0,0 @@
|
|||
import { TestBed, inject } from '@angular/core/testing';
|
||||
|
||||
import { Effects } from './totp.effect';
|
||||
|
||||
describe('ProbeList.Effects', () => {
|
||||
beforeEach(() => {
|
||||
TestBed.configureTestingModule({
|
||||
providers: [Effects]
|
||||
});
|
||||
});
|
||||
|
||||
it('should be created', inject([Effects], (effects: Effects) => {
|
||||
expect(effects).toBeTruthy();
|
||||
}));
|
||||
});
|
|
@ -1,72 +0,0 @@
|
|||
import {
|
||||
Actions,
|
||||
ActionType,
|
||||
} from './totp.action';
|
||||
|
||||
import {
|
||||
State,
|
||||
initialState,
|
||||
} from './totp.state';
|
||||
|
||||
export function reducer(state = initialState, action: Actions): State {
|
||||
switch (action.type) {
|
||||
case ActionType.CreateTotp: {
|
||||
return {
|
||||
...state,
|
||||
error: null,
|
||||
pending: true,
|
||||
};
|
||||
}
|
||||
|
||||
case ActionType.CreateTotpSuccess: {
|
||||
const secretKey = action.payload.key;
|
||||
const keyURI = action.payload.uri;
|
||||
return {
|
||||
...state,
|
||||
totp: {key: secretKey, uri: keyURI},
|
||||
error: null,
|
||||
pending: false,
|
||||
secretKey: secretKey,
|
||||
keyURI: keyURI,
|
||||
};
|
||||
}
|
||||
|
||||
case ActionType.CreateTotpFailure: {
|
||||
return {
|
||||
...state,
|
||||
error: action.payload,
|
||||
pending: false,
|
||||
secretKey: null,
|
||||
keyURI: null,
|
||||
};
|
||||
}
|
||||
|
||||
case ActionType.Regist: {
|
||||
return {
|
||||
...state,
|
||||
error: null,
|
||||
pending: true,
|
||||
};
|
||||
}
|
||||
|
||||
case ActionType.RegistSuccess: {
|
||||
return {
|
||||
...state,
|
||||
error: null,
|
||||
pending: false,
|
||||
};
|
||||
}
|
||||
|
||||
case ActionType.RegistFailure: {
|
||||
return {
|
||||
...state,
|
||||
error: action.payload,
|
||||
pending: false,
|
||||
};
|
||||
}
|
||||
|
||||
default: {
|
||||
return state;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,17 +0,0 @@
|
|||
import { RESTClientError } from '@loafer/ng-rest';
|
||||
|
||||
export interface State {
|
||||
totp: any;
|
||||
secretKey: string;
|
||||
keyURI: string;
|
||||
error: RESTClientError | null;
|
||||
pending: boolean;
|
||||
}
|
||||
|
||||
export const initialState: State = {
|
||||
totp: null,
|
||||
secretKey: null,
|
||||
keyURI: null,
|
||||
error: null,
|
||||
pending: false,
|
||||
};
|
18
@overflow/shared/auth/auth-store.module.ts
Normal file
18
@overflow/shared/auth/auth-store.module.ts
Normal file
|
@ -0,0 +1,18 @@
|
|||
import { NgModule } from '@angular/core';
|
||||
import { StoreModule } from '@ngrx/store';
|
||||
import { EffectsModule } from '@ngrx/effects';
|
||||
|
||||
import {
|
||||
REDUCERS,
|
||||
EFFECTS,
|
||||
} from './store';
|
||||
|
||||
import { MODULE } from './auth.constant';
|
||||
|
||||
@NgModule({
|
||||
imports: [
|
||||
StoreModule.forFeature(MODULE.name, REDUCERS),
|
||||
EffectsModule.forFeature(EFFECTS),
|
||||
],
|
||||
})
|
||||
export class AuthStoreModule { }
|
|
@ -1,9 +1,11 @@
|
|||
import { NgModule } from '@angular/core';
|
||||
import { CommonModule } from '@angular/common';
|
||||
import { AuthStoreModule } from './auth-store.module';
|
||||
|
||||
@NgModule({
|
||||
imports: [
|
||||
CommonModule,
|
||||
AuthStoreModule,
|
||||
],
|
||||
})
|
||||
export class AuthModule { }
|
||||
|
|
|
@ -1,89 +0,0 @@
|
|||
import { Action } from '@ngrx/store';
|
||||
|
||||
import { RESTClientError } from '@loafer/ng-rest';
|
||||
|
||||
import { DomainMember } from '@overflow/commons-typescript/model/domain';
|
||||
import { Member } from '@overflow/commons-typescript/model/member';
|
||||
|
||||
export enum ActionType {
|
||||
Signin = '[member.auth] Signin',
|
||||
SigninSuccess = '[member.auth] SigninSuccess',
|
||||
SigninFailure = '[member.auth] SigninFailure',
|
||||
SigninRedirect = '[member.auth] SigninRedirect',
|
||||
|
||||
SigninCookie = '[member.auth] SigninCookie',
|
||||
SigninCookieSuccess = '[member.auth] SigninCookieSuccess',
|
||||
SigninCookieFailure = '[member.auth] SigninCookieFailure',
|
||||
|
||||
Signout = '[member.auth] Signout',
|
||||
SignoutSuccess = '[member.auth] SignoutSuccess',
|
||||
SignoutFailure = '[member.auth] SignoutFailure',
|
||||
}
|
||||
|
||||
export class Signin implements Action {
|
||||
readonly type = ActionType.Signin;
|
||||
|
||||
constructor(public payload: {email: string, password: string, returnURL: string}) {}
|
||||
}
|
||||
|
||||
export class SigninSuccess implements Action {
|
||||
readonly type = ActionType.SigninSuccess;
|
||||
|
||||
constructor(public payload: {authToken: string, domainMember: DomainMember}) {}
|
||||
}
|
||||
|
||||
export class SigninFailure implements Action {
|
||||
readonly type = ActionType.SigninFailure;
|
||||
|
||||
constructor(public payload: RESTClientError) {}
|
||||
}
|
||||
|
||||
export class SigninRedirect implements Action {
|
||||
readonly type = ActionType.SigninRedirect;
|
||||
constructor(public payload: string) {}
|
||||
}
|
||||
|
||||
export class SigninCookie implements Action {
|
||||
readonly type = ActionType.SigninCookie;
|
||||
|
||||
constructor(public payload: {authToken: string, returnURL: string}) {}
|
||||
}
|
||||
|
||||
export class SigninCookieSuccess implements Action {
|
||||
readonly type = ActionType.SigninCookieSuccess;
|
||||
|
||||
constructor(public payload: DomainMember) {}
|
||||
}
|
||||
|
||||
export class SigninCookieFailure implements Action {
|
||||
readonly type = ActionType.SigninCookieFailure;
|
||||
|
||||
constructor(public payload: RESTClientError) {}
|
||||
}
|
||||
|
||||
export class Signout implements Action {
|
||||
readonly type = ActionType.Signout;
|
||||
}
|
||||
|
||||
export class SignoutSuccess implements Action {
|
||||
readonly type = ActionType.SignoutSuccess;
|
||||
}
|
||||
|
||||
export class SignoutFailure implements Action {
|
||||
readonly type = ActionType.SignoutFailure;
|
||||
|
||||
constructor(public payload: RESTClientError) {}
|
||||
}
|
||||
|
||||
export type Actions =
|
||||
| Signin
|
||||
| SigninSuccess
|
||||
| SigninFailure
|
||||
| SigninRedirect
|
||||
| SigninCookie
|
||||
| SigninCookieSuccess
|
||||
| SigninCookieFailure
|
||||
| Signout
|
||||
| SignoutSuccess
|
||||
| SignoutFailure
|
||||
;
|
|
@ -1,15 +0,0 @@
|
|||
import { TestBed, inject } from '@angular/core/testing';
|
||||
|
||||
import { Effects } from './auth.effect';
|
||||
|
||||
describe('Auth.Effects', () => {
|
||||
beforeEach(() => {
|
||||
TestBed.configureTestingModule({
|
||||
providers: [Effects]
|
||||
});
|
||||
});
|
||||
|
||||
it('should be created', inject([Effects], (effects: Effects) => {
|
||||
expect(effects).toBeTruthy();
|
||||
}));
|
||||
});
|
|
@ -1,107 +0,0 @@
|
|||
import { Injectable } from '@angular/core';
|
||||
import { Router } from '@angular/router';
|
||||
|
||||
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/switchMap';
|
||||
import 'rxjs/add/operator/map';
|
||||
import 'rxjs/add/operator/take';
|
||||
|
||||
import { RESTClientError } from '@loafer/ng-rest';
|
||||
|
||||
import { DomainMember } from '@overflow/commons-typescript/model/domain';
|
||||
|
||||
import { Member } from '@overflow/commons-typescript/model/member';
|
||||
import { MemberService } from '../../service/member.service';
|
||||
|
||||
import {
|
||||
Signin,
|
||||
SigninSuccess,
|
||||
SigninFailure,
|
||||
SigninRedirect,
|
||||
SigninCookie,
|
||||
SigninCookieSuccess,
|
||||
SigninCookieFailure,
|
||||
|
||||
ActionType,
|
||||
} from './auth.action';
|
||||
|
||||
@Injectable()
|
||||
export class Effects {
|
||||
private _returnURL: any;
|
||||
|
||||
constructor(
|
||||
private actions$: Actions,
|
||||
private memberService: MemberService,
|
||||
private router: Router
|
||||
) { }
|
||||
|
||||
@Effect()
|
||||
signin$: Observable<Action> = this.actions$
|
||||
.ofType(ActionType.Signin)
|
||||
.map((action: Signin) => action.payload)
|
||||
.switchMap(payload => {
|
||||
this._returnURL = payload.returnURL;
|
||||
return this.memberService.signin(payload.email, payload.password);
|
||||
})
|
||||
.map((result: any) => {
|
||||
const authToken = result['authToken'];
|
||||
const domainMember = result['domainMember'];
|
||||
return new SigninSuccess({authToken: authToken, domainMember: domainMember});
|
||||
})
|
||||
.catch((error: RESTClientError) => {
|
||||
return of(new SigninFailure(error));
|
||||
});
|
||||
|
||||
@Effect({ dispatch: false })
|
||||
signinSuccess$ = this.actions$
|
||||
.ofType(ActionType.SigninSuccess)
|
||||
.do(() => {
|
||||
this.router.navigateByUrl(this._returnURL);
|
||||
});
|
||||
|
||||
@Effect({ dispatch: false })
|
||||
signinRedirect$ = this.actions$
|
||||
.ofType(ActionType.SigninRedirect, ActionType.Signout)
|
||||
.map((action: SigninRedirect) => action.payload)
|
||||
.do(returnURL => {
|
||||
this.router.navigate(['/auth/signin'], {queryParams: {returnURL: returnURL}});
|
||||
});
|
||||
|
||||
|
||||
@Effect()
|
||||
signinCookie$: Observable<Action> = this.actions$
|
||||
.ofType(ActionType.SigninCookie)
|
||||
.map((action: SigninCookie) => action.payload)
|
||||
.switchMap((payload) => {
|
||||
this._returnURL = payload.returnURL;
|
||||
return this.memberService.signin_cookie(payload.authToken);
|
||||
})
|
||||
.map((domainMember: DomainMember) => {
|
||||
return new SigninCookieSuccess(domainMember);
|
||||
})
|
||||
.catch((error: RESTClientError) => {
|
||||
return of(new SigninFailure(error));
|
||||
});
|
||||
|
||||
@Effect({ dispatch: false })
|
||||
signinCookieSuccess$ = this.actions$
|
||||
.ofType(ActionType.SigninCookieSuccess)
|
||||
.do(() => {
|
||||
this.router.navigateByUrl(this._returnURL);
|
||||
});
|
||||
|
||||
@Effect({ dispatch: false })
|
||||
signinCookieFailure$ = this.actions$
|
||||
.ofType(ActionType.SigninCookieFailure)
|
||||
.map(() => {
|
||||
return new SigninRedirect(this._returnURL);
|
||||
});
|
||||
}
|
|
@ -1,102 +0,0 @@
|
|||
import {
|
||||
Actions,
|
||||
ActionType,
|
||||
Signin,
|
||||
} from './auth.action';
|
||||
|
||||
import {
|
||||
State,
|
||||
initialState,
|
||||
} from './auth.state';
|
||||
|
||||
import { Member } from '@overflow/commons-typescript/model/member';
|
||||
import { DomainMember } from '@overflow/commons-typescript/model/domain';
|
||||
|
||||
export function reducer(state = initialState, action: Actions): State {
|
||||
switch (action.type) {
|
||||
case ActionType.Signin: {
|
||||
return {
|
||||
...state,
|
||||
error: null,
|
||||
pending: true,
|
||||
};
|
||||
}
|
||||
|
||||
case ActionType.SigninSuccess: {
|
||||
const domainMember = action.payload.domainMember;
|
||||
return {
|
||||
...state,
|
||||
signined: true,
|
||||
error: null,
|
||||
pending: false,
|
||||
member: domainMember.member,
|
||||
domain: domainMember.domain,
|
||||
};
|
||||
}
|
||||
|
||||
case ActionType.SigninFailure: {
|
||||
return {
|
||||
...state,
|
||||
signined: false,
|
||||
error: action.payload,
|
||||
pending: false,
|
||||
member: null,
|
||||
domain: null,
|
||||
};
|
||||
}
|
||||
|
||||
case ActionType.SigninCookieSuccess: {
|
||||
return {
|
||||
...state,
|
||||
signined: true,
|
||||
error: null,
|
||||
pending: false,
|
||||
member: action.payload.member,
|
||||
domain: action.payload.domain,
|
||||
};
|
||||
}
|
||||
|
||||
case ActionType.SigninCookieFailure: {
|
||||
return {
|
||||
...state,
|
||||
signined: false,
|
||||
error: action.payload,
|
||||
pending: false,
|
||||
member: null,
|
||||
domain: null,
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
case ActionType.Signout: {
|
||||
return {
|
||||
...state,
|
||||
error: null,
|
||||
pending: true,
|
||||
};
|
||||
}
|
||||
|
||||
case ActionType.SignoutSuccess: {
|
||||
return {
|
||||
...state,
|
||||
signined: false,
|
||||
error: null,
|
||||
pending: false,
|
||||
member: null,
|
||||
domain: null,
|
||||
};
|
||||
}
|
||||
|
||||
case ActionType.SignoutFailure: {
|
||||
return {
|
||||
...state,
|
||||
error: action.payload,
|
||||
pending: false,
|
||||
};
|
||||
}
|
||||
|
||||
default: {
|
||||
return state;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,19 +0,0 @@
|
|||
import { RESTClientError } from '@loafer/ng-rest';
|
||||
import { Domain } from '@overflow/commons-typescript/model/domain';
|
||||
import { Member } from '@overflow/commons-typescript/model/member';
|
||||
|
||||
export interface State {
|
||||
signined: boolean;
|
||||
error: RESTClientError | null;
|
||||
pending: boolean;
|
||||
member: Member | null;
|
||||
domain: Domain | null;
|
||||
}
|
||||
|
||||
export const initialState: State = {
|
||||
signined: false,
|
||||
error: null,
|
||||
pending: false,
|
||||
member: null,
|
||||
domain: null,
|
||||
};
|
|
@ -1,4 +0,0 @@
|
|||
export * from './auth.action';
|
||||
export * from './auth.effect';
|
||||
export * from './auth.reducer';
|
||||
export * from './auth.state';
|
|
@ -3,27 +3,17 @@ import { Action } from '@ngrx/store';
|
|||
import { RESTClientError } from '@loafer/ng-rest';
|
||||
|
||||
import { DomainMember } from '@overflow/commons-typescript/model/domain';
|
||||
import { Member } from '@overflow/commons-typescript/model/member';
|
||||
|
||||
export enum ActionType {
|
||||
Signin = '[member.auth] Signin',
|
||||
SigninSuccess = '[member.auth] SigninSuccess',
|
||||
SigninFailure = '[member.auth] SigninFailure',
|
||||
SigninRedirect = '[member.auth] SigninRedirect',
|
||||
SigninSuccess = '[auth.auth] SigninSuccess',
|
||||
SigninFailure = '[auth.auth] SigninFailure',
|
||||
SigninRedirect = '[auth.auth] SigninRedirect',
|
||||
|
||||
SigninCookie = '[member.auth] SigninCookie',
|
||||
SigninCookieSuccess = '[member.auth] SigninCookieSuccess',
|
||||
SigninCookieFailure = '[member.auth] SigninCookieFailure',
|
||||
SigninCookieSuccess = '[auth.auth] SigninCookieSuccess',
|
||||
SigninCookieFailure = '[auth.auth] SigninCookieFailure',
|
||||
|
||||
Signout = '[member.auth] Signout',
|
||||
SignoutSuccess = '[member.auth] SignoutSuccess',
|
||||
SignoutFailure = '[member.auth] SignoutFailure',
|
||||
}
|
||||
|
||||
export class Signin implements Action {
|
||||
readonly type = ActionType.Signin;
|
||||
|
||||
constructor(public payload: {email: string, password: string, returnURL: string}) {}
|
||||
SignoutSuccess = '[auth.auth] SignoutSuccess',
|
||||
SignoutFailure = '[auth.auth] SignoutFailure',
|
||||
}
|
||||
|
||||
export class SigninSuccess implements Action {
|
||||
|
@ -43,12 +33,6 @@ export class SigninRedirect implements Action {
|
|||
constructor(public payload: string) {}
|
||||
}
|
||||
|
||||
export class SigninCookie implements Action {
|
||||
readonly type = ActionType.SigninCookie;
|
||||
|
||||
constructor(public payload: {authToken: string, returnURL: string}) {}
|
||||
}
|
||||
|
||||
export class SigninCookieSuccess implements Action {
|
||||
readonly type = ActionType.SigninCookieSuccess;
|
||||
|
||||
|
@ -61,10 +45,6 @@ export class SigninCookieFailure implements Action {
|
|||
constructor(public payload: RESTClientError) {}
|
||||
}
|
||||
|
||||
export class Signout implements Action {
|
||||
readonly type = ActionType.Signout;
|
||||
}
|
||||
|
||||
export class SignoutSuccess implements Action {
|
||||
readonly type = ActionType.SignoutSuccess;
|
||||
}
|
||||
|
@ -76,14 +56,11 @@ export class SignoutFailure implements Action {
|
|||
}
|
||||
|
||||
export type Actions =
|
||||
| Signin
|
||||
| SigninSuccess
|
||||
| SigninFailure
|
||||
| SigninRedirect
|
||||
| SigninCookie
|
||||
| SigninCookieSuccess
|
||||
| SigninCookieFailure
|
||||
| Signout
|
||||
| SignoutSuccess
|
||||
| SignoutFailure
|
||||
;
|
58
@overflow/shared/auth/store/container/auth/auth.reducer.ts
Normal file
58
@overflow/shared/auth/store/container/auth/auth.reducer.ts
Normal file
|
@ -0,0 +1,58 @@
|
|||
import {
|
||||
Actions,
|
||||
ActionType,
|
||||
} from './auth.action';
|
||||
|
||||
import {
|
||||
State,
|
||||
initialState,
|
||||
} from './auth.state';
|
||||
|
||||
export function reducer(state: State = initialState, action: Actions): State {
|
||||
switch (action.type) {
|
||||
case ActionType.SigninSuccess: {
|
||||
return {
|
||||
signined: true,
|
||||
domainMember: action.payload.domainMember,
|
||||
};
|
||||
}
|
||||
|
||||
case ActionType.SigninFailure: {
|
||||
return {
|
||||
signined: false,
|
||||
domainMember: null,
|
||||
};
|
||||
}
|
||||
|
||||
case ActionType.SigninCookieSuccess: {
|
||||
return {
|
||||
signined: true,
|
||||
domainMember: action.payload,
|
||||
};
|
||||
}
|
||||
|
||||
case ActionType.SigninCookieFailure: {
|
||||
return {
|
||||
signined: false,
|
||||
domainMember: null,
|
||||
};
|
||||
}
|
||||
|
||||
case ActionType.SignoutSuccess: {
|
||||
return {
|
||||
signined: false,
|
||||
domainMember: null,
|
||||
};
|
||||
}
|
||||
|
||||
case ActionType.SignoutFailure: {
|
||||
return {
|
||||
...state,
|
||||
};
|
||||
}
|
||||
|
||||
default: {
|
||||
return state;
|
||||
}
|
||||
}
|
||||
}
|
19
@overflow/shared/auth/store/container/auth/auth.state.ts
Normal file
19
@overflow/shared/auth/store/container/auth/auth.state.ts
Normal file
|
@ -0,0 +1,19 @@
|
|||
import { Selector, createSelector } from '@ngrx/store';
|
||||
import { DomainMember } from '@overflow/commons-typescript/model/domain';
|
||||
|
||||
export interface State {
|
||||
signined: boolean;
|
||||
domainMember: DomainMember | null;
|
||||
}
|
||||
|
||||
export const initialState: State = {
|
||||
signined: false,
|
||||
domainMember: null,
|
||||
};
|
||||
|
||||
export function getSelectors<S>(selector: Selector<any, State>) {
|
||||
return {
|
||||
selectSignined: createSelector(selector, (state: State) => state.signined),
|
||||
selectDomainMember: createSelector(selector, (state: State) => state.domainMember),
|
||||
};
|
||||
}
|
|
@ -1,4 +1,3 @@
|
|||
export * from './auth.action';
|
||||
export * from './auth.effect';
|
||||
export * from './auth.reducer';
|
||||
export * from './auth.state';
|
26
@overflow/shared/auth/store/index.ts
Normal file
26
@overflow/shared/auth/store/index.ts
Normal file
|
@ -0,0 +1,26 @@
|
|||
import {
|
||||
createSelector,
|
||||
createFeatureSelector,
|
||||
} from '@ngrx/store';
|
||||
|
||||
import { MODULE } from '../auth.constant';
|
||||
|
||||
import * as AuthContainerStore from './container/auth';
|
||||
|
||||
export interface State {
|
||||
auth_container: AuthContainerStore.State;
|
||||
}
|
||||
|
||||
export const REDUCERS = {
|
||||
auth_container: AuthContainerStore.reducer,
|
||||
};
|
||||
|
||||
export const EFFECTS = [
|
||||
];
|
||||
|
||||
export const selectState = createFeatureSelector<State>(MODULE.name);
|
||||
|
||||
export const AuthContainerSelector = AuthContainerStore.getSelectors(createSelector(
|
||||
selectState,
|
||||
(state: State) => state.auth_container
|
||||
));
|
|
@ -1,3 +0,0 @@
|
|||
export const MODULE = {
|
||||
name: 'Target'
|
||||
};
|
|
@ -1,9 +0,0 @@
|
|||
import { NgModule } from '@angular/core';
|
||||
import { CommonModule } from '@angular/common';
|
||||
|
||||
@NgModule({
|
||||
imports: [
|
||||
CommonModule,
|
||||
],
|
||||
})
|
||||
export class SharedModule { }
|
Loading…
Reference in New Issue
Block a user