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 {
|
import {
|
||||||
Actions,
|
Actions,
|
||||||
ActionType,
|
ActionType,
|
||||||
} from './modify.action';
|
} from '../../entity/member/member.action';
|
||||||
|
|
||||||
import {
|
import {
|
||||||
State,
|
State,
|
||||||
initialState,
|
initialState,
|
||||||
} from './modify.state';
|
} from './member-modify-password.state';
|
||||||
|
|
||||||
export function reducer(state = initialState, action: Actions): State {
|
export function reducer(state = initialState, action: Actions): State {
|
||||||
switch (action.type) {
|
switch (action.type) {
|
||||||
case ActionType.Modify: {
|
case ActionType.ModifyPassword: {
|
||||||
return {
|
return {
|
||||||
...state,
|
|
||||||
error: null,
|
|
||||||
pending: true,
|
pending: true,
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
case ActionType.ModifySuccess: {
|
|
||||||
return {
|
|
||||||
...state,
|
|
||||||
error: null,
|
error: null,
|
||||||
pending: false,
|
|
||||||
member: action.payload,
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
case ActionType.ModifyFailure: {
|
case ActionType.ModifyPasswordSuccess: {
|
||||||
return {
|
return {
|
||||||
...state,
|
|
||||||
error: action.payload,
|
|
||||||
pending: false,
|
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 './member-modify.reducer';
|
||||||
export * from './modify.effect';
|
export * from './member-modify.state';
|
||||||
export * from './modify.reducer';
|
|
||||||
export * from './modify.state';
|
|
||||||
|
|
||||||
|
|
|
@ -6,25 +6,28 @@ import {
|
||||||
import {
|
import {
|
||||||
State,
|
State,
|
||||||
initialState,
|
initialState,
|
||||||
} from './modify.state';
|
} from './member-modify.state';
|
||||||
|
|
||||||
export function reducer(state = initialState, action: Actions): State {
|
export function reducer(state = initialState, action: Actions): State {
|
||||||
switch (action.type) {
|
switch (action.type) {
|
||||||
case ActionType.Modify: {
|
case ActionType.Modify: {
|
||||||
return {
|
return {
|
||||||
pending: true,
|
pending: true,
|
||||||
|
error: null,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
case ActionType.ModifySuccess: {
|
case ActionType.ModifySuccess: {
|
||||||
return {
|
return {
|
||||||
pending: false,
|
pending: false,
|
||||||
|
error: null,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
case ActionType.ModifyFailure: {
|
case ActionType.ModifyFailure: {
|
||||||
return {
|
return {
|
||||||
pending: false,
|
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 './member-reset-password.reducer';
|
||||||
export * from './reset-password.effect';
|
export * from './member-reset-password.state';
|
||||||
export * from './reset-password.reducer';
|
|
||||||
export * from './reset-password.state';
|
|
||||||
|
|
||||||
|
|
|
@ -6,25 +6,28 @@ import {
|
||||||
import {
|
import {
|
||||||
State,
|
State,
|
||||||
initialState,
|
initialState,
|
||||||
} from './signout.state';
|
} from './member-reset-password.state';
|
||||||
|
|
||||||
export function reducer(state = initialState, action: Actions): State {
|
export function reducer(state = initialState, action: Actions): State {
|
||||||
switch (action.type) {
|
switch (action.type) {
|
||||||
case ActionType.Signout: {
|
case ActionType.ResetPassword: {
|
||||||
return {
|
return {
|
||||||
pending: true,
|
pending: true,
|
||||||
|
error: null,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
case ActionType.SignoutSuccess: {
|
case ActionType.ResetPasswordSuccess: {
|
||||||
return {
|
return {
|
||||||
pending: false,
|
pending: false,
|
||||||
|
error: null,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
case ActionType.SignoutFailure: {
|
case ActionType.ResetPasswordFailure: {
|
||||||
return {
|
return {
|
||||||
pending: false,
|
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 './member-signin.reducer';
|
||||||
export * from './signin.state';
|
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 './member-signout.reducer';
|
||||||
export * from './signout.state';
|
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 './member-signup.reducer';
|
||||||
export * from './signup.effect';
|
export * from './member-signup.state';
|
||||||
export * from './signup.reducer';
|
|
||||||
export * from './signup.state';
|
|
||||||
|
|
||||||
|
|
|
@ -6,25 +6,28 @@ import {
|
||||||
import {
|
import {
|
||||||
State,
|
State,
|
||||||
initialState,
|
initialState,
|
||||||
} from './signup.state';
|
} from './member-signup.state';
|
||||||
|
|
||||||
export function reducer(state = initialState, action: Actions): State {
|
export function reducer(state = initialState, action: Actions): State {
|
||||||
switch (action.type) {
|
switch (action.type) {
|
||||||
case ActionType.Signup: {
|
case ActionType.Signup: {
|
||||||
return {
|
return {
|
||||||
pending: true,
|
pending: true,
|
||||||
|
error: null,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
case ActionType.SignupSuccess: {
|
case ActionType.SignupSuccess: {
|
||||||
return {
|
return {
|
||||||
pending: false,
|
pending: false,
|
||||||
|
error: null,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
case ActionType.SignupFailure: {
|
case ActionType.SignupFailure: {
|
||||||
return {
|
return {
|
||||||
pending: false,
|
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';
|
import { Member } from '@overflow/commons-typescript/model/member';
|
||||||
|
|
||||||
export enum ActionType {
|
export enum ActionType {
|
||||||
CreateTotp = '[member.totp] CreateTotp',
|
CreateTotp = '[member.member-totp] CreateTotp',
|
||||||
CreateTotpSuccess = '[member.totp] CreateTotpSuccess',
|
CreateTotpSuccess = '[member.member-totp] CreateTotpSuccess',
|
||||||
CreateTotpFailure = '[member.totp] CreateTotpFailure',
|
CreateTotpFailure = '[member.member-totp] CreateTotpFailure',
|
||||||
|
|
||||||
Regist = '[member.totp] Regist',
|
Regist = '[member.member-totp] Regist',
|
||||||
RegistSuccess = '[member.totp] RegistSuccess',
|
RegistSuccess = '[member.member-totp] RegistSuccess',
|
||||||
RegistFailure = '[member.totp] RegistFailure',
|
RegistFailure = '[member.member-totp] RegistFailure',
|
||||||
|
|
||||||
CheckCodeForMember = '[member.totp] CheckCodeForMember',
|
CheckCodeForMember = '[member.member-totp] CheckCodeForMember',
|
||||||
CheckCodeForMemberSuccess = '[member.totp] CheckCodeForMemberSuccess',
|
CheckCodeForMemberSuccess = '[member.member-totp] CheckCodeForMemberSuccess',
|
||||||
CheckCodeForMemberFailure = '[member.totp] CheckCodeForMemberFailure',
|
CheckCodeForMemberFailure = '[member.member-totp] CheckCodeForMemberFailure',
|
||||||
}
|
}
|
||||||
|
|
||||||
export class CreateTotp implements Action {
|
export class CreateTotp implements Action {
|
|
@ -1,8 +1,8 @@
|
||||||
import { TestBed, inject } from '@angular/core/testing';
|
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(() => {
|
beforeEach(() => {
|
||||||
TestBed.configureTestingModule({
|
TestBed.configureTestingModule({
|
||||||
providers: [Effects]
|
providers: [Effects]
|
|
@ -15,7 +15,7 @@ import 'rxjs/add/operator/map';
|
||||||
import 'rxjs/add/operator/take';
|
import 'rxjs/add/operator/take';
|
||||||
|
|
||||||
import { RESTClientError } from '@loafer/ng-rest';
|
import { RESTClientError } from '@loafer/ng-rest';
|
||||||
import { MemberTotpService } from '../../service/member-totp.service';
|
import { MemberTotpService } from '../../../service/member-totp.service';
|
||||||
|
|
||||||
import {
|
import {
|
||||||
CreateTotp,
|
CreateTotp,
|
||||||
|
@ -31,11 +31,10 @@ import {
|
||||||
CheckCodeForMemberFailure,
|
CheckCodeForMemberFailure,
|
||||||
|
|
||||||
ActionType,
|
ActionType,
|
||||||
} from './totp.action';
|
} from './member-totp.action';
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class Effects {
|
export class Effects {
|
||||||
private _returnURL: any;
|
|
||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
private actions$: Actions,
|
private actions$: Actions,
|
||||||
|
@ -54,7 +53,7 @@ export class Effects {
|
||||||
.map((result: any) => {
|
.map((result: any) => {
|
||||||
const key = result['key'];
|
const key = result['key'];
|
||||||
const uri = result['uri'];
|
const uri = result['uri'];
|
||||||
return new CreateTotpSuccess({key: key, uri: uri});
|
return new CreateTotpSuccess({ key: key, uri: uri });
|
||||||
})
|
})
|
||||||
.catch((error: RESTClientError) => {
|
.catch((error: RESTClientError) => {
|
||||||
return of(new CreateTotpFailure(error));
|
return of(new CreateTotpFailure(error));
|
||||||
|
@ -81,7 +80,6 @@ export class Effects {
|
||||||
.ofType(ActionType.CheckCodeForMember)
|
.ofType(ActionType.CheckCodeForMember)
|
||||||
.map((action: Regist) => action.payload)
|
.map((action: Regist) => action.payload)
|
||||||
.switchMap((payload) => {
|
.switchMap((payload) => {
|
||||||
// this._returnURL = payload.returnURL;
|
|
||||||
return this.memberTotpService.checkCodeForMember(payload.member, payload.code);
|
return this.memberTotpService.checkCodeForMember(payload.member, payload.code);
|
||||||
})
|
})
|
||||||
.map((result: any) => {
|
.map((result: any) => {
|
|
@ -7,90 +7,44 @@ import { DomainMember } from '@overflow/commons-typescript/model/domain';
|
||||||
|
|
||||||
export enum ActionType {
|
export enum ActionType {
|
||||||
Signin = '[member.member] Signin',
|
Signin = '[member.member] Signin',
|
||||||
SigninSuccess = '[member.member] SigninSuccess',
|
|
||||||
SigninFailure = '[member.member] SigninFailure',
|
|
||||||
SigninRedirect = '[member.member] SigninRedirect',
|
|
||||||
|
|
||||||
SigninCookie = '[member.auth] SigninCookie',
|
SigninCookie = '[member.member] SigninCookie',
|
||||||
SigninCookieSuccess = '[member.auth] SigninCookieSuccess',
|
|
||||||
SigninCookieFailure = '[member.auth] SigninCookieFailure',
|
|
||||||
|
|
||||||
Signout = '[member.auth] Signout',
|
Signout = '[member.member] Signout',
|
||||||
SignoutSuccess = '[member.auth] SignoutSuccess',
|
|
||||||
SignoutFailure = '[member.auth] SignoutFailure',
|
|
||||||
|
|
||||||
Signup = '[member.signup] Signup',
|
Signup = '[member.member] Signup',
|
||||||
SignupSuccess = '[member.signup] SignupSuccess',
|
SignupSuccess = '[member.member] SignupSuccess',
|
||||||
SignupFailure = '[member.signup] SignupFailure',
|
SignupFailure = '[member.member] SignupFailure',
|
||||||
|
|
||||||
Modify = '[member.modify] Modify',
|
Modify = '[member.member] Modify',
|
||||||
ModifySuccess = '[member.modify] ModifySuccess',
|
ModifySuccess = '[member.member] ModifySuccess',
|
||||||
ModifyFailure = '[member.modify] ModifyFailure',
|
ModifyFailure = '[member.member] ModifyFailure',
|
||||||
|
|
||||||
ResetPassword = '[member.resetPassword] ResetPassword',
|
ResetPassword = '[member.member] ResetPassword',
|
||||||
ResetPasswordSuccess = '[member.resetPassword] ResetPasswordSuccess',
|
ResetPasswordSuccess = '[member.member] ResetPasswordSuccess',
|
||||||
ResetPasswordFailure = '[member.resetPassword] ResetPasswordFailure',
|
ResetPasswordFailure = '[member.member] ResetPasswordFailure',
|
||||||
|
|
||||||
ModifyPassword = '[member.modifyPassword] ModifyPassword',
|
ModifyPassword = '[member.member] ModifyPassword',
|
||||||
ModifyPasswordSuccess = '[member.modifyPassword] ModifyPasswordSuccess',
|
ModifyPasswordSuccess = '[member.member] ModifyPasswordSuccess',
|
||||||
ModifyPasswordFailure = '[member.modifyPassword] ModifyPasswordFailure',
|
ModifyPasswordFailure = '[member.member] ModifyPasswordFailure',
|
||||||
}
|
}
|
||||||
|
|
||||||
export class Signin implements Action {
|
export class Signin implements Action {
|
||||||
readonly type = ActionType.Signin;
|
readonly type = ActionType.Signin;
|
||||||
|
|
||||||
constructor(public payload: { email: string, password: string, returnURL: string }) { }
|
constructor(public payload: { email: string, password: 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 {
|
export class SigninCookie implements Action {
|
||||||
readonly type = ActionType.SigninCookie;
|
readonly type = ActionType.SigninCookie;
|
||||||
|
|
||||||
constructor(public payload: { authToken: string, returnURL: string }) { }
|
constructor(public payload: { authToken: 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 {
|
export class Signout implements Action {
|
||||||
readonly type = ActionType.Signout;
|
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 {
|
export class Signup implements Action {
|
||||||
readonly type = ActionType.Signup;
|
readonly type = ActionType.Signup;
|
||||||
|
|
||||||
|
@ -148,7 +102,7 @@ export class ResetPasswordFailure implements Action {
|
||||||
export class ModifyPassword implements Action {
|
export class ModifyPassword implements Action {
|
||||||
readonly type = ActionType.ModifyPassword;
|
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 {
|
export class ModifyPasswordSuccess implements Action {
|
||||||
|
@ -163,18 +117,10 @@ export class ModifyPasswordFailure implements Action {
|
||||||
constructor(public payload: RESTClientError) {}
|
constructor(public payload: RESTClientError) {}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
export type Actions =
|
export type Actions =
|
||||||
| Signin
|
| Signin
|
||||||
| SigninSuccess
|
|
||||||
| SigninFailure
|
|
||||||
| SigninRedirect
|
|
||||||
| SigninCookie
|
| SigninCookie
|
||||||
| SigninCookieSuccess
|
|
||||||
| SigninCookieFailure
|
|
||||||
| Signout
|
| Signout
|
||||||
| SignoutSuccess
|
|
||||||
| SignoutFailure
|
|
||||||
| Signup
|
| Signup
|
||||||
| SignupSuccess
|
| SignupSuccess
|
||||||
| SignupFailure
|
| SignupFailure
|
||||||
|
|
|
@ -14,14 +14,35 @@ import 'rxjs/add/operator/map';
|
||||||
import 'rxjs/add/operator/take';
|
import 'rxjs/add/operator/take';
|
||||||
|
|
||||||
import { Member } from '@overflow/commons-typescript/model/member';
|
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 {
|
import {
|
||||||
|
Signin,
|
||||||
|
SigninCookie,
|
||||||
Signup,
|
Signup,
|
||||||
SignupSuccess,
|
SignupSuccess,
|
||||||
SignupFailure,
|
SignupFailure,
|
||||||
|
Modify,
|
||||||
|
ModifySuccess,
|
||||||
|
ModifyFailure,
|
||||||
|
ResetPassword,
|
||||||
|
ResetPasswordSuccess,
|
||||||
|
ResetPasswordFailure,
|
||||||
|
ModifyPassword,
|
||||||
|
ModifyPasswordSuccess,
|
||||||
|
ModifyPasswordFailure,
|
||||||
ActionType,
|
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()
|
@Injectable()
|
||||||
export class Effects {
|
export class Effects {
|
||||||
|
@ -31,21 +52,73 @@ export class Effects {
|
||||||
private memberService: MemberService,
|
private memberService: MemberService,
|
||||||
private router: Router
|
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()
|
@Effect()
|
||||||
signup$: Observable<Action> = this.actions$
|
signup$: Observable<Action> = this.actions$
|
||||||
.ofType(ActionType.Signup)
|
.ofType(ActionType.Signup)
|
||||||
.map((action: Signup) => action.payload)
|
.map((action: Signup) => action.payload)
|
||||||
.exhaustMap(payload =>
|
.exhaustMap(payload =>
|
||||||
this.memberService
|
this.memberService.signup(payload.member, payload.password)
|
||||||
.signup(payload.member, payload.password)
|
.map(member => new SignupSuccess(member))
|
||||||
.map(_member => new SignupSuccess(_member))
|
|
||||||
.catch(error => of(new SignupFailure(error)))
|
.catch(error => of(new SignupFailure(error)))
|
||||||
);
|
);
|
||||||
|
|
||||||
@Effect({ dispatch: false })
|
@Effect()
|
||||||
signupSuccess$ = this.actions$
|
modify$: Observable<Action> = this.actions$
|
||||||
.ofType(ActionType.SignupSuccess)
|
.ofType(ActionType.Modify)
|
||||||
.do(() => this.router.navigate(['/']));
|
.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,
|
createFeatureSelector,
|
||||||
} from '@ngrx/store';
|
} from '@ngrx/store';
|
||||||
|
|
||||||
import { StateSelector } from '@overflow/core/ngrx/store';
|
|
||||||
|
|
||||||
import { MODULE } from '../member.constant';
|
import { MODULE } from '../member.constant';
|
||||||
|
|
||||||
import * as AuthStore from './auth';
|
import * as MemberEntityStore from './entity/member';
|
||||||
import * as SignupStore from './signup';
|
import * as MemberTOTPEntityStore from './entity/member-totp';
|
||||||
import * as TotpStore from './totp';
|
|
||||||
import * as ModifyStore from './modify';
|
import * as MemberSignupContainerStore from './container/signup';
|
||||||
import * as ResetPasswordStore from './reset-password';
|
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 {
|
export interface State {
|
||||||
auth: AuthStore.State;
|
member_signup_container: MemberSignupContainerStore.State;
|
||||||
signup: SignupStore.State;
|
member_signin_container: MemberSigninContainerStore.State;
|
||||||
totp: TotpStore.State;
|
member_modify_password_container: MemberModifyPasswordContainerStore.State;
|
||||||
modify: ModifyStore.State;
|
member_reset_password_container: MemberResetPasswordContainerStore.State;
|
||||||
resetPassword: ResetPasswordStore.State;
|
member_modify_container: MemberModifyContainerStore.State;
|
||||||
|
member_signout_container: MemberSignoutContainerStore.State;
|
||||||
}
|
}
|
||||||
|
|
||||||
export const REDUCERS = {
|
export const REDUCERS = {
|
||||||
auth: AuthStore.reducer,
|
member_signup_container: MemberSignupContainerStore.reducer,
|
||||||
signup: SignupStore.reducer,
|
member_signin_container: MemberSigninContainerStore.reducer,
|
||||||
totp: TotpStore.reducer,
|
member_modify_password_container: MemberModifyPasswordContainerStore.reducer,
|
||||||
modify: ModifyStore.reducer,
|
member_reset_password_container: MemberResetPasswordContainerStore.reducer,
|
||||||
resetPassword: ResetPasswordStore.reducer,
|
member_modify_container: MemberModifyContainerStore.reducer,
|
||||||
|
member_signout_container: MemberSignoutContainerStore.reducer,
|
||||||
};
|
};
|
||||||
|
|
||||||
export const EFFECTS = [
|
export const EFFECTS = [
|
||||||
AuthStore.Effects,
|
MemberEntityStore.Effects,
|
||||||
SignupStore.Effects,
|
MemberTOTPEntityStore.Effects,
|
||||||
TotpStore.Effects,
|
|
||||||
ModifyStore.Effects,
|
|
||||||
ResetPasswordStore.Effects,
|
|
||||||
];
|
];
|
||||||
|
|
||||||
export const selectMemberState = createFeatureSelector<State>(MODULE.name);
|
export const selectState = createFeatureSelector<State>(MODULE.name);
|
||||||
|
|
||||||
export const AuthSelector = new StateSelector<AuthStore.State>(createSelector(
|
export const MemberSignupContainerSelector = MemberSignupContainerStore.getSelectors(createSelector(
|
||||||
selectMemberState,
|
selectState,
|
||||||
(state: State) => state.auth
|
(state: State) => state.member_signup_container
|
||||||
));
|
));
|
||||||
|
|
||||||
export const SignupSelector = new StateSelector<SignupStore.State>(createSelector(
|
export const MemberSigninContainerSelector = MemberSigninContainerStore.getSelectors(createSelector(
|
||||||
selectMemberState,
|
selectState,
|
||||||
(state: State) => state.signup
|
(state: State) => state.member_signin_container
|
||||||
));
|
));
|
||||||
|
|
||||||
export const TotpSelector = new StateSelector<TotpStore.State>(createSelector(
|
export const MemberModifyPasswordContainerSelector = MemberModifyPasswordContainerStore.getSelectors(createSelector(
|
||||||
selectMemberState,
|
selectState,
|
||||||
(state: State) => state.totp
|
(state: State) => state.member_modify_password_container
|
||||||
));
|
));
|
||||||
|
|
||||||
export const ModifySelector = new StateSelector<ModifyStore.State>(createSelector(
|
export const MemberResetPasswordContainerSelector = MemberResetPasswordContainerStore.getSelectors(createSelector(
|
||||||
selectMemberState,
|
selectState,
|
||||||
(state: State) => state.modify
|
(state: State) => state.member_reset_password_container
|
||||||
));
|
));
|
||||||
|
|
||||||
export const ResetPasswordSelector = new StateSelector<ResetPasswordStore.State>(createSelector(
|
export const MemberModifyContainerSelector = MemberModifyContainerStore.getSelectors(createSelector(
|
||||||
selectMemberState,
|
selectState,
|
||||||
(state: State) => state.resetPassword
|
(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 { NgModule } from '@angular/core';
|
||||||
import { CommonModule } from '@angular/common';
|
import { CommonModule } from '@angular/common';
|
||||||
|
import { AuthStoreModule } from './auth-store.module';
|
||||||
|
|
||||||
@NgModule({
|
@NgModule({
|
||||||
imports: [
|
imports: [
|
||||||
CommonModule,
|
CommonModule,
|
||||||
|
AuthStoreModule,
|
||||||
],
|
],
|
||||||
})
|
})
|
||||||
export class AuthModule { }
|
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 { RESTClientError } from '@loafer/ng-rest';
|
||||||
|
|
||||||
import { DomainMember } from '@overflow/commons-typescript/model/domain';
|
import { DomainMember } from '@overflow/commons-typescript/model/domain';
|
||||||
import { Member } from '@overflow/commons-typescript/model/member';
|
|
||||||
|
|
||||||
export enum ActionType {
|
export enum ActionType {
|
||||||
Signin = '[member.auth] Signin',
|
SigninSuccess = '[auth.auth] SigninSuccess',
|
||||||
SigninSuccess = '[member.auth] SigninSuccess',
|
SigninFailure = '[auth.auth] SigninFailure',
|
||||||
SigninFailure = '[member.auth] SigninFailure',
|
SigninRedirect = '[auth.auth] SigninRedirect',
|
||||||
SigninRedirect = '[member.auth] SigninRedirect',
|
|
||||||
|
|
||||||
SigninCookie = '[member.auth] SigninCookie',
|
SigninCookieSuccess = '[auth.auth] SigninCookieSuccess',
|
||||||
SigninCookieSuccess = '[member.auth] SigninCookieSuccess',
|
SigninCookieFailure = '[auth.auth] SigninCookieFailure',
|
||||||
SigninCookieFailure = '[member.auth] SigninCookieFailure',
|
|
||||||
|
|
||||||
Signout = '[member.auth] Signout',
|
SignoutSuccess = '[auth.auth] SignoutSuccess',
|
||||||
SignoutSuccess = '[member.auth] SignoutSuccess',
|
SignoutFailure = '[auth.auth] SignoutFailure',
|
||||||
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 {
|
export class SigninSuccess implements Action {
|
||||||
|
@ -43,12 +33,6 @@ export class SigninRedirect implements Action {
|
||||||
constructor(public payload: string) {}
|
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 {
|
export class SigninCookieSuccess implements Action {
|
||||||
readonly type = ActionType.SigninCookieSuccess;
|
readonly type = ActionType.SigninCookieSuccess;
|
||||||
|
|
||||||
|
@ -61,10 +45,6 @@ export class SigninCookieFailure implements Action {
|
||||||
constructor(public payload: RESTClientError) {}
|
constructor(public payload: RESTClientError) {}
|
||||||
}
|
}
|
||||||
|
|
||||||
export class Signout implements Action {
|
|
||||||
readonly type = ActionType.Signout;
|
|
||||||
}
|
|
||||||
|
|
||||||
export class SignoutSuccess implements Action {
|
export class SignoutSuccess implements Action {
|
||||||
readonly type = ActionType.SignoutSuccess;
|
readonly type = ActionType.SignoutSuccess;
|
||||||
}
|
}
|
||||||
|
@ -76,14 +56,11 @@ export class SignoutFailure implements Action {
|
||||||
}
|
}
|
||||||
|
|
||||||
export type Actions =
|
export type Actions =
|
||||||
| Signin
|
|
||||||
| SigninSuccess
|
| SigninSuccess
|
||||||
| SigninFailure
|
| SigninFailure
|
||||||
| SigninRedirect
|
| SigninRedirect
|
||||||
| SigninCookie
|
|
||||||
| SigninCookieSuccess
|
| SigninCookieSuccess
|
||||||
| SigninCookieFailure
|
| SigninCookieFailure
|
||||||
| Signout
|
|
||||||
| SignoutSuccess
|
| SignoutSuccess
|
||||||
| SignoutFailure
|
| 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.action';
|
||||||
export * from './auth.effect';
|
|
||||||
export * from './auth.reducer';
|
export * from './auth.reducer';
|
||||||
export * from './auth.state';
|
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