From e1cf7d74b66bd00b96157e776557a404364e45b4 Mon Sep 17 00:00:00 2001 From: crusader Date: Tue, 27 Feb 2018 17:34:12 +0900 Subject: [PATCH] ing --- src/app/app.module.ts | 6 ++ src/app/commons/reducer/state.ts | 2 - src/app/commons/service/rest.service.ts | 42 +++++++---- src/app/commons/service/rpc.service.ts | 6 +- .../{modify => }/modify.component.html | 0 .../{modify => }/modify.component.scss | 0 .../{modify => }/modify.component.spec.ts | 0 .../{modify => }/modify.component.ts | 0 .../component/modify/modify-reducer.module.ts | 0 .../member/component/modify/modify.module.ts | 17 ----- .../reset-password.component.html | 0 .../reset-password.component.scss | 0 .../reset-password.component.spec.ts | 0 .../reset-password.component.ts | 0 .../reset-password/reset-password.module.ts | 24 ------ .../{signin => }/signin.component.html | 0 .../{signin => }/signin.component.scss | 0 .../{signin => }/signin.component.spec.ts | 0 .../{signin => }/signin.component.ts | 0 .../member/component/signin/signin.module.ts | 25 ------- .../{signup => }/signup.component.html | 0 .../{signup => }/signup.component.scss | 0 .../{signup => }/signup.component.spec.ts | 0 .../{signup => }/signup.component.ts | 0 .../member/component/signup/signup.module.ts | 23 ------ .../packages/member/member-store.module.ts | 36 +++++++++ src/app/packages/member/member.module.ts | 37 +++++++--- src/app/packages/member/model/member.ts | 2 +- .../packages/member/service/member.service.ts | 21 +++--- src/app/packages/member/store/auth.action.ts | 59 +++++++++++++++ .../packages/member/store/auth.effect.spec.ts | 15 ++++ src/app/packages/member/store/auth.effect.ts | 58 +++++++++++++++ src/app/packages/member/store/auth.reducer.ts | 73 +++++++++++++++++++ src/app/packages/member/store/auth.state.ts | 20 +++++ src/app/packages/member/store/auth.ts | 4 + .../packages/member/store/signup.action.ts | 33 +++++++++ .../member/store/signup.effect.spec.ts | 15 ++++ .../packages/member/store/signup.effect.ts | 51 +++++++++++++ .../packages/member/store/signup.reducer.ts | 45 ++++++++++++ src/app/packages/member/store/signup.state.ts | 17 +++++ src/app/packages/member/store/signup.ts | 5 ++ .../pages/auth/auth-page-routing.module.ts | 10 ++- src/app/pages/auth/auth-page.module.ts | 21 +++++- .../reset-password-page-routing.module.ts | 16 ---- .../reset-password-page.module.ts | 20 ----- .../auth/signin/signin-page-routing.module.ts | 16 ---- .../pages/auth/signin/signin-page.module.ts | 19 ----- .../auth/signup/signup-page-routing.module.ts | 16 ---- .../pages/auth/signup/signup-page.module.ts | 19 ----- yarn.lock | 10 +-- 50 files changed, 537 insertions(+), 246 deletions(-) delete mode 100644 src/app/commons/reducer/state.ts rename src/app/packages/member/component/{modify => }/modify.component.html (100%) rename src/app/packages/member/component/{modify => }/modify.component.scss (100%) rename src/app/packages/member/component/{modify => }/modify.component.spec.ts (100%) rename src/app/packages/member/component/{modify => }/modify.component.ts (100%) delete mode 100644 src/app/packages/member/component/modify/modify-reducer.module.ts delete mode 100644 src/app/packages/member/component/modify/modify.module.ts rename src/app/packages/member/component/{reset-password => }/reset-password.component.html (100%) rename src/app/packages/member/component/{reset-password => }/reset-password.component.scss (100%) rename src/app/packages/member/component/{reset-password => }/reset-password.component.spec.ts (100%) rename src/app/packages/member/component/{reset-password => }/reset-password.component.ts (100%) delete mode 100644 src/app/packages/member/component/reset-password/reset-password.module.ts rename src/app/packages/member/component/{signin => }/signin.component.html (100%) rename src/app/packages/member/component/{signin => }/signin.component.scss (100%) rename src/app/packages/member/component/{signin => }/signin.component.spec.ts (100%) rename src/app/packages/member/component/{signin => }/signin.component.ts (100%) delete mode 100644 src/app/packages/member/component/signin/signin.module.ts rename src/app/packages/member/component/{signup => }/signup.component.html (100%) rename src/app/packages/member/component/{signup => }/signup.component.scss (100%) rename src/app/packages/member/component/{signup => }/signup.component.spec.ts (100%) rename src/app/packages/member/component/{signup => }/signup.component.ts (100%) delete mode 100644 src/app/packages/member/component/signup/signup.module.ts create mode 100644 src/app/packages/member/member-store.module.ts create mode 100644 src/app/packages/member/store/auth.action.ts create mode 100644 src/app/packages/member/store/auth.effect.spec.ts create mode 100644 src/app/packages/member/store/auth.effect.ts create mode 100644 src/app/packages/member/store/auth.reducer.ts create mode 100644 src/app/packages/member/store/auth.state.ts create mode 100644 src/app/packages/member/store/auth.ts create mode 100644 src/app/packages/member/store/signup.action.ts create mode 100644 src/app/packages/member/store/signup.effect.spec.ts create mode 100644 src/app/packages/member/store/signup.effect.ts create mode 100644 src/app/packages/member/store/signup.reducer.ts create mode 100644 src/app/packages/member/store/signup.state.ts create mode 100644 src/app/packages/member/store/signup.ts delete mode 100644 src/app/pages/auth/reset-password/reset-password-page-routing.module.ts delete mode 100644 src/app/pages/auth/reset-password/reset-password-page.module.ts delete mode 100644 src/app/pages/auth/signin/signin-page-routing.module.ts delete mode 100644 src/app/pages/auth/signin/signin-page.module.ts delete mode 100644 src/app/pages/auth/signup/signup-page-routing.module.ts delete mode 100644 src/app/pages/auth/signup/signup-page.module.ts diff --git a/src/app/app.module.ts b/src/app/app.module.ts index 5429895..9267133 100644 --- a/src/app/app.module.ts +++ b/src/app/app.module.ts @@ -12,6 +12,9 @@ import { CovalentModule } from './commons/ui/covalent/covalent.module'; import { AppComponent } from './app.component'; +import { RESTService } from './commons/service/rest.service'; +import { RPCService } from './commons/service/rpc.service'; + @NgModule({ declarations: [ AppComponent, @@ -25,6 +28,9 @@ import { AppComponent } from './app.component'; CovalentModule, HttpClientModule, ], + providers: [ + RESTService, RPCService, + ], bootstrap: [AppComponent] }) export class AppModule { } diff --git a/src/app/commons/reducer/state.ts b/src/app/commons/reducer/state.ts deleted file mode 100644 index 2cc0057..0000000 --- a/src/app/commons/reducer/state.ts +++ /dev/null @@ -1,2 +0,0 @@ -export interface State { -} diff --git a/src/app/commons/service/rest.service.ts b/src/app/commons/service/rest.service.ts index 5812058..91cf2f6 100644 --- a/src/app/commons/service/rest.service.ts +++ b/src/app/commons/service/rest.service.ts @@ -4,31 +4,45 @@ import { HttpClient, HttpHeaders } from '@angular/common/http'; import { Observable } from 'rxjs/Observable'; import 'rxjs/add/operator/do'; +import 'rxjs/add/operator/timeout'; @Injectable() export class RESTService { private baseURL: string; + private readonly httpHeaders: HttpHeaders; constructor( - @Inject(HttpClient) private httpClient: HttpClient, + @Inject(HttpClient) private _httpClient: HttpClient, ) { - - } - - public get(entry: string, ...args: any[]): Observable { - const headers: HttpHeaders = new HttpHeaders(); - headers + this.httpHeaders = new HttpHeaders() .set('Accept', 'application/json') .set('Content-Type', 'application/json'); + } - this.httpClient - .get('') - .do( - (data: any) => { + public get httpClient(): HttpClient { + return this._httpClient; + } - } - ); - return undefined; + public get(entry: string, params?: {[param: string]: string | string[]}): Observable { + const headers: HttpHeaders = this.httpHeaders; + + return this._httpClient + .get('', { + headers: headers, + params: params, + responseType: 'json', + }); + } + + public post(entry: string, body: any | null, params?: {[param: string]: string | string[]}): Observable { + const headers: HttpHeaders = this.httpHeaders; + + return this._httpClient + .post('', body, { + headers: headers, + params: params, + responseType: 'json', + }); } } diff --git a/src/app/commons/service/rpc.service.ts b/src/app/commons/service/rpc.service.ts index 1bd17f6..1747200 100644 --- a/src/app/commons/service/rpc.service.ts +++ b/src/app/commons/service/rpc.service.ts @@ -33,11 +33,15 @@ export class RPCService { return undefined; } + public callTimeout(method: string, ...args: any[]): Observable { + return undefined; + } + public send(method: string, ...args: any[]): void { } - private sendData(data: Object): void { + private sendInternal(data: Object): void { this.wsSocketSubject.next(data); } diff --git a/src/app/packages/member/component/modify/modify.component.html b/src/app/packages/member/component/modify.component.html similarity index 100% rename from src/app/packages/member/component/modify/modify.component.html rename to src/app/packages/member/component/modify.component.html diff --git a/src/app/packages/member/component/modify/modify.component.scss b/src/app/packages/member/component/modify.component.scss similarity index 100% rename from src/app/packages/member/component/modify/modify.component.scss rename to src/app/packages/member/component/modify.component.scss diff --git a/src/app/packages/member/component/modify/modify.component.spec.ts b/src/app/packages/member/component/modify.component.spec.ts similarity index 100% rename from src/app/packages/member/component/modify/modify.component.spec.ts rename to src/app/packages/member/component/modify.component.spec.ts diff --git a/src/app/packages/member/component/modify/modify.component.ts b/src/app/packages/member/component/modify.component.ts similarity index 100% rename from src/app/packages/member/component/modify/modify.component.ts rename to src/app/packages/member/component/modify.component.ts diff --git a/src/app/packages/member/component/modify/modify-reducer.module.ts b/src/app/packages/member/component/modify/modify-reducer.module.ts deleted file mode 100644 index e69de29..0000000 diff --git a/src/app/packages/member/component/modify/modify.module.ts b/src/app/packages/member/component/modify/modify.module.ts deleted file mode 100644 index b999b7e..0000000 --- a/src/app/packages/member/component/modify/modify.module.ts +++ /dev/null @@ -1,17 +0,0 @@ -import { NgModule } from '@angular/core'; -import { CommonModule } from '@angular/common'; -import { ModifyComponent } from './modify.component'; - - -@NgModule({ - imports: [ - CommonModule, - ], - declarations: [ - ModifyComponent, - ], - exports: [ - ModifyComponent - ] -}) -export class ModifyModule { } diff --git a/src/app/packages/member/component/reset-password/reset-password.component.html b/src/app/packages/member/component/reset-password.component.html similarity index 100% rename from src/app/packages/member/component/reset-password/reset-password.component.html rename to src/app/packages/member/component/reset-password.component.html diff --git a/src/app/packages/member/component/reset-password/reset-password.component.scss b/src/app/packages/member/component/reset-password.component.scss similarity index 100% rename from src/app/packages/member/component/reset-password/reset-password.component.scss rename to src/app/packages/member/component/reset-password.component.scss diff --git a/src/app/packages/member/component/reset-password/reset-password.component.spec.ts b/src/app/packages/member/component/reset-password.component.spec.ts similarity index 100% rename from src/app/packages/member/component/reset-password/reset-password.component.spec.ts rename to src/app/packages/member/component/reset-password.component.spec.ts diff --git a/src/app/packages/member/component/reset-password/reset-password.component.ts b/src/app/packages/member/component/reset-password.component.ts similarity index 100% rename from src/app/packages/member/component/reset-password/reset-password.component.ts rename to src/app/packages/member/component/reset-password.component.ts diff --git a/src/app/packages/member/component/reset-password/reset-password.module.ts b/src/app/packages/member/component/reset-password/reset-password.module.ts deleted file mode 100644 index 82ca542..0000000 --- a/src/app/packages/member/component/reset-password/reset-password.module.ts +++ /dev/null @@ -1,24 +0,0 @@ -import { NgModule } from '@angular/core'; -import { CommonModule } from '@angular/common'; -import { ResetPasswordComponent } from './reset-password.component'; -import { RouterModule } from '@angular/router'; -import { FormsModule, ReactiveFormsModule } from '@angular/forms'; -import { MaterialModule } from 'app/commons/ui/material/material.module'; - - -@NgModule({ - imports: [ - CommonModule, - RouterModule, - FormsModule, - ReactiveFormsModule, - MaterialModule, - ], - declarations: [ - ResetPasswordComponent, - ], - exports: [ - ResetPasswordComponent - ] -}) -export class ResetPasswordModule { } diff --git a/src/app/packages/member/component/signin/signin.component.html b/src/app/packages/member/component/signin.component.html similarity index 100% rename from src/app/packages/member/component/signin/signin.component.html rename to src/app/packages/member/component/signin.component.html diff --git a/src/app/packages/member/component/signin/signin.component.scss b/src/app/packages/member/component/signin.component.scss similarity index 100% rename from src/app/packages/member/component/signin/signin.component.scss rename to src/app/packages/member/component/signin.component.scss diff --git a/src/app/packages/member/component/signin/signin.component.spec.ts b/src/app/packages/member/component/signin.component.spec.ts similarity index 100% rename from src/app/packages/member/component/signin/signin.component.spec.ts rename to src/app/packages/member/component/signin.component.spec.ts diff --git a/src/app/packages/member/component/signin/signin.component.ts b/src/app/packages/member/component/signin.component.ts similarity index 100% rename from src/app/packages/member/component/signin/signin.component.ts rename to src/app/packages/member/component/signin.component.ts diff --git a/src/app/packages/member/component/signin/signin.module.ts b/src/app/packages/member/component/signin/signin.module.ts deleted file mode 100644 index c7e0c21..0000000 --- a/src/app/packages/member/component/signin/signin.module.ts +++ /dev/null @@ -1,25 +0,0 @@ -import { NgModule } from '@angular/core'; -import { CommonModule } from '@angular/common'; -import { RouterModule } from '@angular/router'; -import { FormsModule, ReactiveFormsModule } from '@angular/forms'; - -import { SigninComponent } from './signin.component'; -import { MaterialModule } from 'app/commons/ui/material/material.module'; - - -@NgModule({ - imports: [ - CommonModule, - RouterModule, - FormsModule, - ReactiveFormsModule, - MaterialModule, - ], - declarations: [ - SigninComponent, - ], - exports: [ - SigninComponent, - ] -}) -export class SigninModule { } diff --git a/src/app/packages/member/component/signup/signup.component.html b/src/app/packages/member/component/signup.component.html similarity index 100% rename from src/app/packages/member/component/signup/signup.component.html rename to src/app/packages/member/component/signup.component.html diff --git a/src/app/packages/member/component/signup/signup.component.scss b/src/app/packages/member/component/signup.component.scss similarity index 100% rename from src/app/packages/member/component/signup/signup.component.scss rename to src/app/packages/member/component/signup.component.scss diff --git a/src/app/packages/member/component/signup/signup.component.spec.ts b/src/app/packages/member/component/signup.component.spec.ts similarity index 100% rename from src/app/packages/member/component/signup/signup.component.spec.ts rename to src/app/packages/member/component/signup.component.spec.ts diff --git a/src/app/packages/member/component/signup/signup.component.ts b/src/app/packages/member/component/signup.component.ts similarity index 100% rename from src/app/packages/member/component/signup/signup.component.ts rename to src/app/packages/member/component/signup.component.ts diff --git a/src/app/packages/member/component/signup/signup.module.ts b/src/app/packages/member/component/signup/signup.module.ts deleted file mode 100644 index 94e54c1..0000000 --- a/src/app/packages/member/component/signup/signup.module.ts +++ /dev/null @@ -1,23 +0,0 @@ -import { NgModule } from '@angular/core'; -import { CommonModule } from '@angular/common'; -import { SignupComponent } from './signup.component'; -import { MaterialModule } from 'app/commons/ui/material/material.module'; -import { FormsModule, ReactiveFormsModule } from '@angular/forms'; -import { RouterModule } from '@angular/router'; - -@NgModule({ - imports: [ - CommonModule, - RouterModule, - FormsModule, - ReactiveFormsModule, - MaterialModule, - ], - declarations: [ - SignupComponent, - ], - exports: [ - SignupComponent - ] -}) -export class SignupModule { } diff --git a/src/app/packages/member/member-store.module.ts b/src/app/packages/member/member-store.module.ts new file mode 100644 index 0000000..f450ac8 --- /dev/null +++ b/src/app/packages/member/member-store.module.ts @@ -0,0 +1,36 @@ +import { NgModule } from '@angular/core'; +import { StoreModule } from '@ngrx/store'; +import { StoreDevtoolsModule } from '@ngrx/store-devtools'; +import { + StoreRouterConnectingModule, + RouterStateSerializer, +} from '@ngrx/router-store'; +import { EffectsModule } from '@ngrx/effects'; +import { combineReducers, ActionReducer, ActionReducerMap, MetaReducer } from '@ngrx/store'; + +import * as AuthStore from './store/auth'; +import * as SignupStore from './store/signup'; + + +export interface State { + auth: AuthStore.State; + signup: SignupStore.Signup; +} + +export const reducers = { + auth: AuthStore.reducer, + signup: SignupStore.reducer, +}; + +export const EFFECTS = [ + AuthStore.Effects, + SignupStore.Effects, +]; + +@NgModule({ + imports: [ + StoreModule.forFeature('', reducers), + EffectsModule.forFeature(EFFECTS), + ], +}) +export class MemberStoreModule { } diff --git a/src/app/packages/member/member.module.ts b/src/app/packages/member/member.module.ts index 1873d54..4b654a8 100644 --- a/src/app/packages/member/member.module.ts +++ b/src/app/packages/member/member.module.ts @@ -1,21 +1,38 @@ import { NgModule } from '@angular/core'; import { CommonModule } from '@angular/common'; -import { ModifyModule } from 'app/packages/member/component/modify/modify.module'; -import { SigninModule } from 'app/packages/member/component/signin/signin.module'; -import { SignupModule } from 'app/packages/member/component/signup/signup.module'; -import { ResetPasswordModule } from 'app/packages/member/component/reset-password/reset-password.module'; -import { MemberService } from 'app/packages/member/service/member.service'; +import { RouterModule } from '@angular/router'; +import { FormsModule, ReactiveFormsModule } from '@angular/forms'; + +import { MaterialModule } from 'app/commons/ui/material/material.module'; + +import { ModifyComponent } from './component/modify.component'; +import { SigninComponent } from './component/signin.component'; +import { SignupComponent } from './component/signup.component'; +import { ResetPasswordComponent } from './component/reset-password.component'; +import { MemberService } from './service/member.service'; + +import { MemberStoreModule } from './member-store.module'; + +export const COMPONENTS = [ + ModifyComponent, + SigninComponent, + SignupComponent, + ResetPasswordComponent, +]; @NgModule({ imports: [ CommonModule, - ModifyModule, - SigninModule, - SignupModule, - ResetPasswordModule, + RouterModule, + FormsModule, + ReactiveFormsModule, + MaterialModule, + MemberStoreModule, ], + declarations: COMPONENTS, + exports: COMPONENTS, providers: [ MemberService, - ] + ], }) export class MemberModule { } diff --git a/src/app/packages/member/model/member.ts b/src/app/packages/member/model/member.ts index 8fca9b9..b7fb04c 100644 --- a/src/app/packages/member/model/member.ts +++ b/src/app/packages/member/model/member.ts @@ -1,4 +1,4 @@ -export class Member { +export interface Member { id: number; email: string; password: string; diff --git a/src/app/packages/member/service/member.service.ts b/src/app/packages/member/service/member.service.ts index 24abbb2..26bc9af 100644 --- a/src/app/packages/member/service/member.service.ts +++ b/src/app/packages/member/service/member.service.ts @@ -1,5 +1,9 @@ import { Injectable } from '@angular/core'; -import { RPCService } from 'app/commons/service/rpc.service'; +import { Observable } from 'rxjs/Observable'; + +import 'rxjs/add/operator/map'; + +import { RESTService } from 'app/commons/service/rest.service'; import { Member } from '../model/member'; @@ -7,19 +11,16 @@ import { Member } from '../model/member'; export class MemberService { public constructor( - private rpcService: RPCService, + private restService: RESTService, ) { } - public signin(email: string, password: string) { - this.rpcService.call('MemberService.signin', email, password).subscribe( - (member: Member) => { + public signin(email: string, password: string): Observable { + return this.restService.post('/member/signin', '').map((member: Member) => member); + } - }, - (error: any) => { - - } - ); + public signup(member: Member): Observable { + return this.restService.post('/member/signup', '').map((_member: Member) => _member); } } diff --git a/src/app/packages/member/store/auth.action.ts b/src/app/packages/member/store/auth.action.ts new file mode 100644 index 0000000..deb28de --- /dev/null +++ b/src/app/packages/member/store/auth.action.ts @@ -0,0 +1,59 @@ +import { Action } from '@ngrx/store'; + +import { Member } from '../model/member'; + +export enum ActionType { + Signin = '[member.auth] Signin', + SigninSuccess = '[member.auth] SigninSuccess', + SigninFailure = '[member.auth] SigninFailure', + SigninRedirect = '[member.auth] SigninRedirect', + 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}) {} +} + +export class SigninSuccess implements Action { + readonly type = ActionType.SigninSuccess; + + constructor(public payload: { member: Member }) {} +} + +export class SigninFailure implements Action { + readonly type = ActionType.SigninFailure; + + constructor(public payload: any) {} +} + +export class SigninRedirect implements Action { + readonly type = ActionType.SigninRedirect; +} + +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: any) {} +} + +export type Actions = + | Signin + | SigninSuccess + | SigninFailure + | SigninRedirect + | Signout + | SignoutSuccess + | SignoutFailure +; diff --git a/src/app/packages/member/store/auth.effect.spec.ts b/src/app/packages/member/store/auth.effect.spec.ts new file mode 100644 index 0000000..da764e2 --- /dev/null +++ b/src/app/packages/member/store/auth.effect.spec.ts @@ -0,0 +1,15 @@ +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/src/app/packages/member/store/auth.effect.ts b/src/app/packages/member/store/auth.effect.ts new file mode 100644 index 0000000..f5e5447 --- /dev/null +++ b/src/app/packages/member/store/auth.effect.ts @@ -0,0 +1,58 @@ +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 '../model/member'; +import { MemberService } from '../service/member.service'; + +import { + Signin, + SigninSuccess, + SigninFailure, + ActionType, +} from './auth.action'; + +@Injectable() +export class Effects { + + constructor( + private actions$: Actions, + private memberService: MemberService, + private router: Router + ) { } + + @Effect() + signin$: Observable = this.actions$ + .ofType(ActionType.Signin) + .map((action: Signin) => action.payload) + .exhaustMap(payload => + this.memberService + .signin(payload.email, payload.password) + .map(member => new SigninSuccess({ member })) + .catch(error => of(new SigninFailure(error))) + ); + + @Effect({ dispatch: false }) + signinSuccess$ = this.actions$ + .ofType(ActionType.SigninSuccess) + .do(() => this.router.navigate(['/'])); + + @Effect({ dispatch: false }) + signinRedirect$ = this.actions$ + .ofType(ActionType.SigninRedirect, ActionType.Signout) + .do(authed => { + this.router.navigate(['/login']); + }); + +} diff --git a/src/app/packages/member/store/auth.reducer.ts b/src/app/packages/member/store/auth.reducer.ts new file mode 100644 index 0000000..cb07494 --- /dev/null +++ b/src/app/packages/member/store/auth.reducer.ts @@ -0,0 +1,73 @@ +import { + Actions, + ActionType, +} from './auth.action'; + +import { + State, + initialState, +} from './auth.state'; + +import { Member } from '../model/member'; + +export function reducer(state = initialState, action: Actions): State { + switch (action.type) { + case ActionType.Signin: { + return { + ...state, + error: null, + isPending: true, + }; + } + + case ActionType.SigninSuccess: { + return { + ...state, + isSignin: true, + error: null, + isPending: false, + member: action.payload.member, + }; + } + + case ActionType.SigninFailure: { + return { + ...state, + isSignin: false, + error: action.payload, + isPending: false, + member: null, + }; + } + + case ActionType.Signout: { + return { + ...state, + error: null, + isPending: true, + }; + } + + case ActionType.SigninSuccess: { + return { + ...state, + isSignin: false, + error: null, + isPending: false, + member: null, + }; + } + + case ActionType.SigninFailure: { + return { + ...state, + error: action.payload, + isPending: false, + }; + } + + default: { + return state; + } + } +} diff --git a/src/app/packages/member/store/auth.state.ts b/src/app/packages/member/store/auth.state.ts new file mode 100644 index 0000000..4b218d4 --- /dev/null +++ b/src/app/packages/member/store/auth.state.ts @@ -0,0 +1,20 @@ +import { Member } from '../model/member'; + +export interface State { + isSignin: boolean; + error: string | null; + isPending: boolean; + member: Member | null; +} + +export const initialState: State = { + isSignin: false, + error: null, + isPending: false, + member: null, +}; + +export const isSignin = (state: State) => state.isSignin; +export const getMember = (state: State) => state.member; +export const getError = (state: State) => state.error; +export const isPending = (state: State) => state.isPending; diff --git a/src/app/packages/member/store/auth.ts b/src/app/packages/member/store/auth.ts new file mode 100644 index 0000000..aa2085e --- /dev/null +++ b/src/app/packages/member/store/auth.ts @@ -0,0 +1,4 @@ +export * from './auth.action'; +export * from './auth.effect'; +export * from './auth.reducer'; +export * from './auth.state'; diff --git a/src/app/packages/member/store/signup.action.ts b/src/app/packages/member/store/signup.action.ts new file mode 100644 index 0000000..2b42f2f --- /dev/null +++ b/src/app/packages/member/store/signup.action.ts @@ -0,0 +1,33 @@ +import { Action } from '@ngrx/store'; + +import { Member } from '../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}) {} +} + +export class SignupSuccess implements Action { + readonly type = ActionType.SignupSuccess; + + constructor(public payload: { member: Member }) {} +} + +export class SignupFailure implements Action { + readonly type = ActionType.SignupFailure; + + constructor(public payload: any) {} +} + +export type Actions = + | Signup + | SignupSuccess + | SignupFailure +; diff --git a/src/app/packages/member/store/signup.effect.spec.ts b/src/app/packages/member/store/signup.effect.spec.ts new file mode 100644 index 0000000..2325646 --- /dev/null +++ b/src/app/packages/member/store/signup.effect.spec.ts @@ -0,0 +1,15 @@ +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/src/app/packages/member/store/signup.effect.ts b/src/app/packages/member/store/signup.effect.ts new file mode 100644 index 0000000..571a47f --- /dev/null +++ b/src/app/packages/member/store/signup.effect.ts @@ -0,0 +1,51 @@ +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 '../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) + .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/src/app/packages/member/store/signup.reducer.ts b/src/app/packages/member/store/signup.reducer.ts new file mode 100644 index 0000000..d5eaa29 --- /dev/null +++ b/src/app/packages/member/store/signup.reducer.ts @@ -0,0 +1,45 @@ +import { + Actions, + ActionType, +} from './signup.action'; + +import { + State, + initialState, +} from './signup.state'; + +import { Member } from '../model/member'; + +export function reducer(state = initialState, action: Actions): State { + switch (action.type) { + case ActionType.Signup: { + return { + ...state, + error: null, + isPending: true, + }; + } + + case ActionType.SignupSuccess: { + return { + ...state, + error: null, + isPending: false, + member: action.payload.member, + }; + } + + case ActionType.SignupFailure: { + return { + ...state, + error: action.payload, + isPending: false, + member: null, + }; + } + + default: { + return state; + } + } +} diff --git a/src/app/packages/member/store/signup.state.ts b/src/app/packages/member/store/signup.state.ts new file mode 100644 index 0000000..eb61cc8 --- /dev/null +++ b/src/app/packages/member/store/signup.state.ts @@ -0,0 +1,17 @@ +import { Member } from '../model/member'; + +export interface State { + error: string | null; + isPending: boolean; + member: Member | null; +} + +export const initialState: State = { + error: null, + isPending: false, + member: null, +}; + +export const getMember = (state: State) => state.member; +export const getError = (state: State) => state.error; +export const isPending = (state: State) => state.isPending; diff --git a/src/app/packages/member/store/signup.ts b/src/app/packages/member/store/signup.ts new file mode 100644 index 0000000..d5700f1 --- /dev/null +++ b/src/app/packages/member/store/signup.ts @@ -0,0 +1,5 @@ +export * from './signup.action'; +export * from './signup.effect'; +export * from './signup.reducer'; +export * from './signup.state'; + diff --git a/src/app/pages/auth/auth-page-routing.module.ts b/src/app/pages/auth/auth-page-routing.module.ts index e47a94c..b2783e9 100644 --- a/src/app/pages/auth/auth-page-routing.module.ts +++ b/src/app/pages/auth/auth-page-routing.module.ts @@ -2,15 +2,19 @@ import { NgModule } from '@angular/core'; import { Routes, RouterModule } from '@angular/router'; import { AuthPageComponent } from './auth-page.component'; +import { SigninPageComponent } from './signin/signin-page.component'; +import { SignupPageComponent } from './signup/signup-page.component'; +import { ResetPasswordPageComponent } from './reset-password/reset-password-page.component'; + const routes: Routes = [ { path: '', component: AuthPageComponent, children: [ { path: '', redirectTo: 'signin' }, - { path: 'signin', loadChildren: './signin/signin-page.module#SigninPageModule' }, - { path: 'signup', loadChildren: './signup/signup-page.module#SignupPageModule' }, - { path: 'reset-password', loadChildren: './reset-password/reset-password-page.module#ResetPasswordPageModule' }, + { path: 'signin', component: SigninPageComponent }, + { path: 'signup', component: SignupPageComponent }, + { path: 'reset-password', component: ResetPasswordPageComponent }, ] } ]; diff --git a/src/app/pages/auth/auth-page.module.ts b/src/app/pages/auth/auth-page.module.ts index 0e9d5a8..93fa1f6 100644 --- a/src/app/pages/auth/auth-page.module.ts +++ b/src/app/pages/auth/auth-page.module.ts @@ -1,15 +1,30 @@ import { NgModule } from '@angular/core'; import { CommonModule } from '@angular/common'; + +import { FlexLayoutModule } from '@angular/flex-layout'; + +import { MemberModule } from 'app/packages/member/member.module'; + import { AuthPageComponent } from './auth-page.component'; import { AuthPageRoutingModule } from './auth-page-routing.module'; +import { SigninPageComponent } from './signin/signin-page.component'; +import { SignupPageComponent } from './signup/signup-page.component'; +import { ResetPasswordPageComponent } from './reset-password/reset-password-page.component'; + +export const COMPONENTS = [ + AuthPageComponent, + SigninPageComponent, + SignupPageComponent, + ResetPasswordPageComponent, +]; + @NgModule({ imports: [ CommonModule, AuthPageRoutingModule, + MemberModule, ], - declarations: [ - AuthPageComponent, - ] + declarations: COMPONENTS, }) export class AuthPageModule { } diff --git a/src/app/pages/auth/reset-password/reset-password-page-routing.module.ts b/src/app/pages/auth/reset-password/reset-password-page-routing.module.ts deleted file mode 100644 index a4410fa..0000000 --- a/src/app/pages/auth/reset-password/reset-password-page-routing.module.ts +++ /dev/null @@ -1,16 +0,0 @@ -import { NgModule } from '@angular/core'; -import { Routes, RouterModule } from '@angular/router'; -import { ResetPasswordPageComponent } from './reset-password-page.component'; - -const routes: Routes = [ - { - path: '', - component: ResetPasswordPageComponent, - } -]; - -@NgModule({ - imports: [RouterModule.forChild(routes)], - exports: [RouterModule] -}) -export class ResetPasswordPageRoutingModule { } diff --git a/src/app/pages/auth/reset-password/reset-password-page.module.ts b/src/app/pages/auth/reset-password/reset-password-page.module.ts deleted file mode 100644 index 9dd3230..0000000 --- a/src/app/pages/auth/reset-password/reset-password-page.module.ts +++ /dev/null @@ -1,20 +0,0 @@ -import { NgModule } from '@angular/core'; -import { CommonModule } from '@angular/common'; -import { ResetPasswordPageRoutingModule } from './reset-password-page-routing.module'; -import { ResetPasswordPageComponent } from './reset-password-page.component'; -import {ResetPasswordModule} from 'app/packages/member/component/reset-password/reset-password.module'; -import {FlexLayoutModule} from '@angular/flex-layout'; - - -@NgModule({ - imports: [ - CommonModule, - ResetPasswordPageRoutingModule, - ResetPasswordModule, - FlexLayoutModule - ], - declarations: [ - ResetPasswordPageComponent, - ] -}) -export class ResetPasswordPageModule { } diff --git a/src/app/pages/auth/signin/signin-page-routing.module.ts b/src/app/pages/auth/signin/signin-page-routing.module.ts deleted file mode 100644 index 12fe211..0000000 --- a/src/app/pages/auth/signin/signin-page-routing.module.ts +++ /dev/null @@ -1,16 +0,0 @@ -import { NgModule } from '@angular/core'; -import { Routes, RouterModule } from '@angular/router'; -import { SigninPageComponent } from './signin-page.component'; - -const routes: Routes = [ - { - path: '', - component: SigninPageComponent, - } -]; - -@NgModule({ - imports: [RouterModule.forChild(routes)], - exports: [RouterModule] -}) -export class SigninPageRoutingModule { } diff --git a/src/app/pages/auth/signin/signin-page.module.ts b/src/app/pages/auth/signin/signin-page.module.ts deleted file mode 100644 index 05f4495..0000000 --- a/src/app/pages/auth/signin/signin-page.module.ts +++ /dev/null @@ -1,19 +0,0 @@ -import { NgModule } from '@angular/core'; -import { CommonModule } from '@angular/common'; -import { SigninPageRoutingModule } from './signin-page-routing.module'; -import { SigninPageComponent } from './signin-page.component'; -import { SigninModule } from 'app/packages/member/component/signin/signin.module'; -import { FlexLayoutModule } from '@angular/flex-layout'; - -@NgModule({ - imports: [ - CommonModule, - SigninPageRoutingModule, - SigninModule, - FlexLayoutModule - ], - declarations: [ - SigninPageComponent, - ] -}) -export class SigninPageModule { } diff --git a/src/app/pages/auth/signup/signup-page-routing.module.ts b/src/app/pages/auth/signup/signup-page-routing.module.ts deleted file mode 100644 index 1f1f498..0000000 --- a/src/app/pages/auth/signup/signup-page-routing.module.ts +++ /dev/null @@ -1,16 +0,0 @@ -import { NgModule } from '@angular/core'; -import { Routes, RouterModule } from '@angular/router'; -import { SignupPageComponent } from './signup-page.component'; - -const routes: Routes = [ - { - path: '', - component: SignupPageComponent, - } -]; - -@NgModule({ - imports: [RouterModule.forChild(routes)], - exports: [RouterModule] -}) -export class SignupPageRoutingModule { } diff --git a/src/app/pages/auth/signup/signup-page.module.ts b/src/app/pages/auth/signup/signup-page.module.ts deleted file mode 100644 index 9f346e7..0000000 --- a/src/app/pages/auth/signup/signup-page.module.ts +++ /dev/null @@ -1,19 +0,0 @@ -import { NgModule } from '@angular/core'; -import { CommonModule } from '@angular/common'; -import { SignupPageRoutingModule } from './signup-page-routing.module'; -import { SignupPageComponent } from './signup-page.component'; -import { FlexLayoutModule } from '@angular/flex-layout'; -import { SignupModule } from 'app/packages/member/component/signup/signup.module'; - -@NgModule({ - imports: [ - CommonModule, - SignupPageRoutingModule, - FlexLayoutModule, - SignupModule - ], - declarations: [ - SignupPageComponent, - ] -}) -export class SignupPageModule { } diff --git a/yarn.lock b/yarn.lock index 9aec38a..cec2f7b 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1422,18 +1422,14 @@ combined-stream@^1.0.5, combined-stream@~1.0.5: dependencies: delayed-stream "~1.0.0" -commander@2: - version "2.14.1" - resolved "https://registry.yarnpkg.com/commander/-/commander-2.14.1.tgz#2235123e37af8ca3c65df45b026dbd357b01b9aa" +commander@2, commander@^2.12.1, commander@^2.9.0, commander@~2.13.0: + version "2.13.0" + resolved "https://registry.yarnpkg.com/commander/-/commander-2.13.0.tgz#6964bca67685df7c1f1430c584f07d7597885b9c" commander@2.12.x: version "2.12.2" resolved "https://registry.yarnpkg.com/commander/-/commander-2.12.2.tgz#0f5946c427ed9ec0d91a46bb9def53e54650e555" -commander@^2.12.1, commander@^2.9.0, commander@~2.13.0: - version "2.13.0" - resolved "https://registry.yarnpkg.com/commander/-/commander-2.13.0.tgz#6964bca67685df7c1f1430c584f07d7597885b9c" - common-tags@^1.3.1: version "1.7.2" resolved "https://registry.yarnpkg.com/common-tags/-/common-tags-1.7.2.tgz#24d9768c63d253a56ecff93845b44b4df1d52771"