diff --git a/@overflow/member/store/auth/auth.effect.spec.ts b/@overflow/member/store/auth/auth.effect.spec.ts deleted file mode 100644 index da764e2..0000000 --- a/@overflow/member/store/auth/auth.effect.spec.ts +++ /dev/null @@ -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(); - })); -}); diff --git a/@overflow/member/store/auth/auth.effect.ts b/@overflow/member/store/auth/auth.effect.ts deleted file mode 100644 index 9ddea7a..0000000 --- a/@overflow/member/store/auth/auth.effect.ts +++ /dev/null @@ -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 = 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 = 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); - }); -} diff --git a/@overflow/member/store/auth/auth.reducer.ts b/@overflow/member/store/auth/auth.reducer.ts deleted file mode 100644 index c74e735..0000000 --- a/@overflow/member/store/auth/auth.reducer.ts +++ /dev/null @@ -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; - } - } -} diff --git a/@overflow/member/store/auth/auth.state.ts b/@overflow/member/store/auth/auth.state.ts deleted file mode 100644 index 1d8aee3..0000000 --- a/@overflow/member/store/auth/auth.state.ts +++ /dev/null @@ -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, -}; diff --git a/@overflow/member/store/container/modify-password/index.ts b/@overflow/member/store/container/modify-password/index.ts new file mode 100644 index 0000000..53b16ea --- /dev/null +++ b/@overflow/member/store/container/modify-password/index.ts @@ -0,0 +1,3 @@ +export * from './member-modify-password.state'; +export * from './member-modify-password.reducer'; + diff --git a/@overflow/member/store/modify/modify.reducer.ts b/@overflow/member/store/container/modify-password/member-modify-password.reducer.ts similarity index 63% rename from @overflow/member/store/modify/modify.reducer.ts rename to @overflow/member/store/container/modify-password/member-modify-password.reducer.ts index 7e7fcfc..bce2a8a 100644 --- a/@overflow/member/store/modify/modify.reducer.ts +++ b/@overflow/member/store/container/modify-password/member-modify-password.reducer.ts @@ -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 { } } } + diff --git a/@overflow/member/store/container/modify-password/member-modify-password.state.ts b/@overflow/member/store/container/modify-password/member-modify-password.state.ts new file mode 100644 index 0000000..7f8f259 --- /dev/null +++ b/@overflow/member/store/container/modify-password/member-modify-password.state.ts @@ -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) { + return { + selectPending: createSelector(selector, (state: State) => state.pending), + selectError: createSelector(selector, (state: State) => state.error), + }; +} diff --git a/@overflow/member/store/container/modify/index.ts b/@overflow/member/store/container/modify/index.ts index c5c34eb..89ba010 100644 --- a/@overflow/member/store/container/modify/index.ts +++ b/@overflow/member/store/container/modify/index.ts @@ -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'; diff --git a/@overflow/member/store/container/modify/modify.reducer.ts b/@overflow/member/store/container/modify/member-modify.reducer.ts similarity index 83% rename from @overflow/member/store/container/modify/modify.reducer.ts rename to @overflow/member/store/container/modify/member-modify.reducer.ts index c2ba0be..5127632 100644 --- a/@overflow/member/store/container/modify/modify.reducer.ts +++ b/@overflow/member/store/container/modify/member-modify.reducer.ts @@ -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, }; } diff --git a/@overflow/member/store/container/modify/member-modify.state.ts b/@overflow/member/store/container/modify/member-modify.state.ts new file mode 100644 index 0000000..7f8f259 --- /dev/null +++ b/@overflow/member/store/container/modify/member-modify.state.ts @@ -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) { + return { + selectPending: createSelector(selector, (state: State) => state.pending), + selectError: createSelector(selector, (state: State) => state.error), + }; +} diff --git a/@overflow/member/store/container/modify/modify.state.ts b/@overflow/member/store/container/modify/modify.state.ts deleted file mode 100644 index 432b5f2..0000000 --- a/@overflow/member/store/container/modify/modify.state.ts +++ /dev/null @@ -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, -}; diff --git a/@overflow/member/store/container/reset-password/index.ts b/@overflow/member/store/container/reset-password/index.ts index ee04fbb..6f66364 100644 --- a/@overflow/member/store/container/reset-password/index.ts +++ b/@overflow/member/store/container/reset-password/index.ts @@ -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'; diff --git a/@overflow/member/store/container/signout/signout.reducer.ts b/@overflow/member/store/container/reset-password/member-reset-password.reducer.ts similarity index 63% rename from @overflow/member/store/container/signout/signout.reducer.ts rename to @overflow/member/store/container/reset-password/member-reset-password.reducer.ts index 2c089a9..f949fcc 100644 --- a/@overflow/member/store/container/signout/signout.reducer.ts +++ b/@overflow/member/store/container/reset-password/member-reset-password.reducer.ts @@ -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 { } } } + diff --git a/@overflow/member/store/container/reset-password/member-reset-password.state.ts b/@overflow/member/store/container/reset-password/member-reset-password.state.ts new file mode 100644 index 0000000..7f8f259 --- /dev/null +++ b/@overflow/member/store/container/reset-password/member-reset-password.state.ts @@ -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) { + return { + selectPending: createSelector(selector, (state: State) => state.pending), + selectError: createSelector(selector, (state: State) => state.error), + }; +} diff --git a/@overflow/member/store/container/reset-password/reset-password.reducer.ts b/@overflow/member/store/container/reset-password/reset-password.reducer.ts deleted file mode 100644 index 204c3d9..0000000 --- a/@overflow/member/store/container/reset-password/reset-password.reducer.ts +++ /dev/null @@ -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; - } - } -} - diff --git a/@overflow/member/store/container/reset-password/reset-password.state.ts b/@overflow/member/store/container/reset-password/reset-password.state.ts deleted file mode 100644 index 432b5f2..0000000 --- a/@overflow/member/store/container/reset-password/reset-password.state.ts +++ /dev/null @@ -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, -}; diff --git a/@overflow/member/store/container/signin/index.ts b/@overflow/member/store/container/signin/index.ts index 3319e69..8f0b4e6 100644 --- a/@overflow/member/store/container/signin/index.ts +++ b/@overflow/member/store/container/signin/index.ts @@ -1,2 +1,2 @@ -export * from './signin.reducer'; -export * from './signin.state'; +export * from './member-signin.reducer'; +export * from './member-signin.state'; diff --git a/@overflow/member/store/container/signin/member-signin.reducer.ts b/@overflow/member/store/container/signin/member-signin.reducer.ts new file mode 100644 index 0000000..3a8698a --- /dev/null +++ b/@overflow/member/store/container/signin/member-signin.reducer.ts @@ -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; + } + } +} diff --git a/@overflow/member/store/container/signin/member-signin.state.ts b/@overflow/member/store/container/signin/member-signin.state.ts new file mode 100644 index 0000000..39f65af --- /dev/null +++ b/@overflow/member/store/container/signin/member-signin.state.ts @@ -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) { + return { + selectPending: createSelector(selector, (state: State) => state.pending), + selectError: createSelector(selector, (state: State) => state.error), + }; +} diff --git a/@overflow/member/store/container/signin/signin.reducer.ts b/@overflow/member/store/container/signin/signin.reducer.ts deleted file mode 100644 index b3a844f..0000000 --- a/@overflow/member/store/container/signin/signin.reducer.ts +++ /dev/null @@ -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; - } - } -} diff --git a/@overflow/member/store/container/signin/signin.state.ts b/@overflow/member/store/container/signin/signin.state.ts deleted file mode 100644 index ef3e155..0000000 --- a/@overflow/member/store/container/signin/signin.state.ts +++ /dev/null @@ -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, -}; diff --git a/@overflow/member/store/container/signout/index.ts b/@overflow/member/store/container/signout/index.ts index 1f877b7..855a01f 100644 --- a/@overflow/member/store/container/signout/index.ts +++ b/@overflow/member/store/container/signout/index.ts @@ -1,2 +1,2 @@ -export * from './signout.reducer'; -export * from './signout.state'; +export * from './member-signout.reducer'; +export * from './member-signout.state'; diff --git a/@overflow/member/store/container/signout/member-signout.reducer.ts b/@overflow/member/store/container/signout/member-signout.reducer.ts new file mode 100644 index 0000000..df5cdb3 --- /dev/null +++ b/@overflow/member/store/container/signout/member-signout.reducer.ts @@ -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; + } + } +} diff --git a/@overflow/member/store/container/signout/member-signout.state.ts b/@overflow/member/store/container/signout/member-signout.state.ts new file mode 100644 index 0000000..39f65af --- /dev/null +++ b/@overflow/member/store/container/signout/member-signout.state.ts @@ -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) { + return { + selectPending: createSelector(selector, (state: State) => state.pending), + selectError: createSelector(selector, (state: State) => state.error), + }; +} diff --git a/@overflow/member/store/container/signout/signout.state.ts b/@overflow/member/store/container/signout/signout.state.ts deleted file mode 100644 index ef3e155..0000000 --- a/@overflow/member/store/container/signout/signout.state.ts +++ /dev/null @@ -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, -}; diff --git a/@overflow/member/store/container/signup/index.ts b/@overflow/member/store/container/signup/index.ts index d5700f1..da28980 100644 --- a/@overflow/member/store/container/signup/index.ts +++ b/@overflow/member/store/container/signup/index.ts @@ -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'; diff --git a/@overflow/member/store/container/signup/signup.reducer.ts b/@overflow/member/store/container/signup/member-signup.reducer.ts similarity index 83% rename from @overflow/member/store/container/signup/signup.reducer.ts rename to @overflow/member/store/container/signup/member-signup.reducer.ts index fce36a4..c7f3f8c 100644 --- a/@overflow/member/store/container/signup/signup.reducer.ts +++ b/@overflow/member/store/container/signup/member-signup.reducer.ts @@ -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, }; } diff --git a/@overflow/member/store/container/signup/member-signup.state.ts b/@overflow/member/store/container/signup/member-signup.state.ts new file mode 100644 index 0000000..39f65af --- /dev/null +++ b/@overflow/member/store/container/signup/member-signup.state.ts @@ -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) { + return { + selectPending: createSelector(selector, (state: State) => state.pending), + selectError: createSelector(selector, (state: State) => state.error), + }; +} diff --git a/@overflow/member/store/container/signup/signup.state.ts b/@overflow/member/store/container/signup/signup.state.ts deleted file mode 100644 index 432b5f2..0000000 --- a/@overflow/member/store/container/signup/signup.state.ts +++ /dev/null @@ -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, -}; diff --git a/@overflow/member/store/entity/member-totp/index.ts b/@overflow/member/store/entity/member-totp/index.ts new file mode 100644 index 0000000..b027745 --- /dev/null +++ b/@overflow/member/store/entity/member-totp/index.ts @@ -0,0 +1,2 @@ +export * from './member-totp.action'; +export * from './member-totp.effect'; diff --git a/@overflow/member/store/totp/totp.action.ts b/@overflow/member/store/entity/member-totp/member-totp.action.ts similarity index 75% rename from @overflow/member/store/totp/totp.action.ts rename to @overflow/member/store/entity/member-totp/member-totp.action.ts index e3a11d4..eba1e17 100644 --- a/@overflow/member/store/totp/totp.action.ts +++ b/@overflow/member/store/entity/member-totp/member-totp.action.ts @@ -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 { diff --git a/@overflow/member/store/modify/modify.effect.spec.ts b/@overflow/member/store/entity/member-totp/member-totp.effect.spec.ts similarity index 75% rename from @overflow/member/store/modify/modify.effect.spec.ts rename to @overflow/member/store/entity/member-totp/member-totp.effect.spec.ts index 213f4c8..a38e97f 100644 --- a/@overflow/member/store/modify/modify.effect.spec.ts +++ b/@overflow/member/store/entity/member-totp/member-totp.effect.spec.ts @@ -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] diff --git a/@overflow/member/store/totp/totp.effect.ts b/@overflow/member/store/entity/member-totp/member-totp.effect.ts similarity index 91% rename from @overflow/member/store/totp/totp.effect.ts rename to @overflow/member/store/entity/member-totp/member-totp.effect.ts index 6a64df1..57e0049 100644 --- a/@overflow/member/store/totp/totp.effect.ts +++ b/@overflow/member/store/entity/member-totp/member-totp.effect.ts @@ -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) => { diff --git a/@overflow/member/store/entity/member/member.action.ts b/@overflow/member/store/entity/member/member.action.ts index e4a5e68..0fac2e2 100644 --- a/@overflow/member/store/entity/member/member.action.ts +++ b/@overflow/member/store/entity/member/member.action.ts @@ -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 diff --git a/@overflow/member/store/entity/member/member.effect.ts b/@overflow/member/store/entity/member/member.effect.ts index a838bfe..4d1eaf8 100644 --- a/@overflow/member/store/entity/member/member.effect.ts +++ b/@overflow/member/store/entity/member/member.effect.ts @@ -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 = 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 = 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 = 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 = 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 = 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 = 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))) + ); } diff --git a/@overflow/member/store/entity/member/member.reducer.ts b/@overflow/member/store/entity/member/member.reducer.ts deleted file mode 100644 index f6c5ed4..0000000 --- a/@overflow/member/store/entity/member/member.reducer.ts +++ /dev/null @@ -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; - } - } -} diff --git a/@overflow/member/store/entity/member/member.state.ts b/@overflow/member/store/entity/member/member.state.ts deleted file mode 100644 index 429816e..0000000 --- a/@overflow/member/store/entity/member/member.state.ts +++ /dev/null @@ -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, -}; diff --git a/@overflow/member/store/index.ts b/@overflow/member/store/index.ts index 18814d1..5dcc5d6 100644 --- a/@overflow/member/store/index.ts +++ b/@overflow/member/store/index.ts @@ -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(MODULE.name); +export const selectState = createFeatureSelector(MODULE.name); -export const AuthSelector = new StateSelector(createSelector( - selectMemberState, - (state: State) => state.auth +export const MemberSignupContainerSelector = MemberSignupContainerStore.getSelectors(createSelector( + selectState, + (state: State) => state.member_signup_container )); -export const SignupSelector = new StateSelector(createSelector( - selectMemberState, - (state: State) => state.signup +export const MemberSigninContainerSelector = MemberSigninContainerStore.getSelectors(createSelector( + selectState, + (state: State) => state.member_signin_container )); -export const TotpSelector = new StateSelector(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(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(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 +)); diff --git a/@overflow/member/store/modify/index.ts b/@overflow/member/store/modify/index.ts deleted file mode 100644 index c5c34eb..0000000 --- a/@overflow/member/store/modify/index.ts +++ /dev/null @@ -1,5 +0,0 @@ -export * from './modify.action'; -export * from './modify.effect'; -export * from './modify.reducer'; -export * from './modify.state'; - diff --git a/@overflow/member/store/modify/modify.action.ts b/@overflow/member/store/modify/modify.action.ts deleted file mode 100644 index a4874ec..0000000 --- a/@overflow/member/store/modify/modify.action.ts +++ /dev/null @@ -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 -; diff --git a/@overflow/member/store/modify/modify.effect.ts b/@overflow/member/store/modify/modify.effect.ts deleted file mode 100644 index f4e8bce..0000000 --- a/@overflow/member/store/modify/modify.effect.ts +++ /dev/null @@ -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 = 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(['/'])); - -} diff --git a/@overflow/member/store/modify/modify.state.ts b/@overflow/member/store/modify/modify.state.ts deleted file mode 100644 index 429816e..0000000 --- a/@overflow/member/store/modify/modify.state.ts +++ /dev/null @@ -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, -}; diff --git a/@overflow/member/store/reset-password/index.ts b/@overflow/member/store/reset-password/index.ts deleted file mode 100644 index ee04fbb..0000000 --- a/@overflow/member/store/reset-password/index.ts +++ /dev/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'; - diff --git a/@overflow/member/store/reset-password/reset-password.action.ts b/@overflow/member/store/reset-password/reset-password.action.ts deleted file mode 100644 index 95bbdc3..0000000 --- a/@overflow/member/store/reset-password/reset-password.action.ts +++ /dev/null @@ -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) {} -} diff --git a/@overflow/member/store/reset-password/reset-password.effect.spec.ts b/@overflow/member/store/reset-password/reset-password.effect.spec.ts deleted file mode 100644 index 59f5118..0000000 --- a/@overflow/member/store/reset-password/reset-password.effect.spec.ts +++ /dev/null @@ -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(); - })); -}); diff --git a/@overflow/member/store/reset-password/reset-password.effect.ts b/@overflow/member/store/reset-password/reset-password.effect.ts deleted file mode 100644 index 376b933..0000000 --- a/@overflow/member/store/reset-password/reset-password.effect.ts +++ /dev/null @@ -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 = 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 = 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(['/'])); - -} diff --git a/@overflow/member/store/reset-password/reset-password.reducer.ts b/@overflow/member/store/reset-password/reset-password.reducer.ts deleted file mode 100644 index 7a13c7b..0000000 --- a/@overflow/member/store/reset-password/reset-password.reducer.ts +++ /dev/null @@ -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; - } - } -} - diff --git a/@overflow/member/store/reset-password/reset-password.state.ts b/@overflow/member/store/reset-password/reset-password.state.ts deleted file mode 100644 index 429816e..0000000 --- a/@overflow/member/store/reset-password/reset-password.state.ts +++ /dev/null @@ -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, -}; diff --git a/@overflow/member/store/signup/index.ts b/@overflow/member/store/signup/index.ts deleted file mode 100644 index d5700f1..0000000 --- a/@overflow/member/store/signup/index.ts +++ /dev/null @@ -1,5 +0,0 @@ -export * from './signup.action'; -export * from './signup.effect'; -export * from './signup.reducer'; -export * from './signup.state'; - diff --git a/@overflow/member/store/signup/signup.action.ts b/@overflow/member/store/signup/signup.action.ts deleted file mode 100644 index 81e0b8b..0000000 --- a/@overflow/member/store/signup/signup.action.ts +++ /dev/null @@ -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 -; diff --git a/@overflow/member/store/signup/signup.effect.spec.ts b/@overflow/member/store/signup/signup.effect.spec.ts deleted file mode 100644 index 2325646..0000000 --- a/@overflow/member/store/signup/signup.effect.spec.ts +++ /dev/null @@ -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(); - })); -}); diff --git a/@overflow/member/store/signup/signup.effect.ts b/@overflow/member/store/signup/signup.effect.ts deleted file mode 100644 index a838bfe..0000000 --- a/@overflow/member/store/signup/signup.effect.ts +++ /dev/null @@ -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 = 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(['/'])); - -} diff --git a/@overflow/member/store/signup/signup.reducer.ts b/@overflow/member/store/signup/signup.reducer.ts deleted file mode 100644 index f6c5ed4..0000000 --- a/@overflow/member/store/signup/signup.reducer.ts +++ /dev/null @@ -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; - } - } -} diff --git a/@overflow/member/store/signup/signup.state.ts b/@overflow/member/store/signup/signup.state.ts deleted file mode 100644 index 429816e..0000000 --- a/@overflow/member/store/signup/signup.state.ts +++ /dev/null @@ -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, -}; diff --git a/@overflow/member/store/totp/index.ts b/@overflow/member/store/totp/index.ts deleted file mode 100644 index d32dabd..0000000 --- a/@overflow/member/store/totp/index.ts +++ /dev/null @@ -1,4 +0,0 @@ -export * from './totp.action'; -export * from './totp.effect'; -export * from './totp.reducer'; -export * from './totp.state'; diff --git a/@overflow/member/store/totp/totp.effect.spec.ts b/@overflow/member/store/totp/totp.effect.spec.ts deleted file mode 100644 index 30746b8..0000000 --- a/@overflow/member/store/totp/totp.effect.spec.ts +++ /dev/null @@ -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(); - })); -}); diff --git a/@overflow/member/store/totp/totp.reducer.ts b/@overflow/member/store/totp/totp.reducer.ts deleted file mode 100644 index 612e05b..0000000 --- a/@overflow/member/store/totp/totp.reducer.ts +++ /dev/null @@ -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; - } - } -} diff --git a/@overflow/member/store/totp/totp.state.ts b/@overflow/member/store/totp/totp.state.ts deleted file mode 100644 index d11235b..0000000 --- a/@overflow/member/store/totp/totp.state.ts +++ /dev/null @@ -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, -}; diff --git a/@overflow/shared/auth/auth-store.module.ts b/@overflow/shared/auth/auth-store.module.ts new file mode 100644 index 0000000..ce513ab --- /dev/null +++ b/@overflow/shared/auth/auth-store.module.ts @@ -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 { } diff --git a/@overflow/shared/auth/auth.module.ts b/@overflow/shared/auth/auth.module.ts index 9cfa1c7..d9eb49d 100644 --- a/@overflow/shared/auth/auth.module.ts +++ b/@overflow/shared/auth/auth.module.ts @@ -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 { } diff --git a/@overflow/shared/auth/store/auth/auth.action.ts b/@overflow/shared/auth/store/auth/auth.action.ts deleted file mode 100644 index 872c954..0000000 --- a/@overflow/shared/auth/store/auth/auth.action.ts +++ /dev/null @@ -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 -; diff --git a/@overflow/shared/auth/store/auth/auth.effect.spec.ts b/@overflow/shared/auth/store/auth/auth.effect.spec.ts deleted file mode 100644 index da764e2..0000000 --- a/@overflow/shared/auth/store/auth/auth.effect.spec.ts +++ /dev/null @@ -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(); - })); -}); diff --git a/@overflow/shared/auth/store/auth/auth.effect.ts b/@overflow/shared/auth/store/auth/auth.effect.ts deleted file mode 100644 index 9ddea7a..0000000 --- a/@overflow/shared/auth/store/auth/auth.effect.ts +++ /dev/null @@ -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 = 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 = 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); - }); -} diff --git a/@overflow/shared/auth/store/auth/auth.reducer.ts b/@overflow/shared/auth/store/auth/auth.reducer.ts deleted file mode 100644 index c74e735..0000000 --- a/@overflow/shared/auth/store/auth/auth.reducer.ts +++ /dev/null @@ -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; - } - } -} diff --git a/@overflow/shared/auth/store/auth/auth.state.ts b/@overflow/shared/auth/store/auth/auth.state.ts deleted file mode 100644 index 1d8aee3..0000000 --- a/@overflow/shared/auth/store/auth/auth.state.ts +++ /dev/null @@ -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, -}; diff --git a/@overflow/shared/auth/store/auth/index.ts b/@overflow/shared/auth/store/auth/index.ts deleted file mode 100644 index aa2085e..0000000 --- a/@overflow/shared/auth/store/auth/index.ts +++ /dev/null @@ -1,4 +0,0 @@ -export * from './auth.action'; -export * from './auth.effect'; -export * from './auth.reducer'; -export * from './auth.state'; diff --git a/@overflow/member/store/auth/auth.action.ts b/@overflow/shared/auth/store/container/auth/auth.action.ts similarity index 57% rename from @overflow/member/store/auth/auth.action.ts rename to @overflow/shared/auth/store/container/auth/auth.action.ts index 872c954..e8f4eba 100644 --- a/@overflow/member/store/auth/auth.action.ts +++ b/@overflow/shared/auth/store/container/auth/auth.action.ts @@ -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 ; diff --git a/@overflow/shared/auth/store/container/auth/auth.reducer.ts b/@overflow/shared/auth/store/container/auth/auth.reducer.ts new file mode 100644 index 0000000..c3d077f --- /dev/null +++ b/@overflow/shared/auth/store/container/auth/auth.reducer.ts @@ -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; + } + } +} diff --git a/@overflow/shared/auth/store/container/auth/auth.state.ts b/@overflow/shared/auth/store/container/auth/auth.state.ts new file mode 100644 index 0000000..d1f9b37 --- /dev/null +++ b/@overflow/shared/auth/store/container/auth/auth.state.ts @@ -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(selector: Selector) { + return { + selectSignined: createSelector(selector, (state: State) => state.signined), + selectDomainMember: createSelector(selector, (state: State) => state.domainMember), + }; +} diff --git a/@overflow/member/store/auth/index.ts b/@overflow/shared/auth/store/container/auth/index.ts similarity index 75% rename from @overflow/member/store/auth/index.ts rename to @overflow/shared/auth/store/container/auth/index.ts index aa2085e..92047bf 100644 --- a/@overflow/member/store/auth/index.ts +++ b/@overflow/shared/auth/store/container/auth/index.ts @@ -1,4 +1,3 @@ export * from './auth.action'; -export * from './auth.effect'; export * from './auth.reducer'; export * from './auth.state'; diff --git a/@overflow/shared/auth/store/index.ts b/@overflow/shared/auth/store/index.ts new file mode 100644 index 0000000..b6a1785 --- /dev/null +++ b/@overflow/shared/auth/store/index.ts @@ -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(MODULE.name); + +export const AuthContainerSelector = AuthContainerStore.getSelectors(createSelector( + selectState, + (state: State) => state.auth_container +)); diff --git a/@overflow/shared/shared.constant.ts b/@overflow/shared/shared.constant.ts deleted file mode 100644 index bd2c1c3..0000000 --- a/@overflow/shared/shared.constant.ts +++ /dev/null @@ -1,3 +0,0 @@ -export const MODULE = { - name: 'Target' -}; diff --git a/@overflow/shared/shared.module.ts b/@overflow/shared/shared.module.ts deleted file mode 100644 index 2e5ec55..0000000 --- a/@overflow/shared/shared.module.ts +++ /dev/null @@ -1,9 +0,0 @@ -import { NgModule } from '@angular/core'; -import { CommonModule } from '@angular/common'; - -@NgModule({ - imports: [ - CommonModule, - ], -}) -export class SharedModule { }