ing
This commit is contained in:
parent
eb374a388b
commit
0a6b44c2d2
|
@ -28,14 +28,6 @@ export class MemberService {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public signin_cookie(authToken: string): Observable<DomainMember> {
|
|
||||||
return this.restService.request<DomainMember>('post', '/account/signin_cookie', {
|
|
||||||
body: {
|
|
||||||
authToken: authToken,
|
|
||||||
},
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
public signup(member: Member, password: string): Observable<Member> {
|
public signup(member: Member, password: string): Observable<Member> {
|
||||||
return this.restService.request<Member>('post', '/account/signup', {
|
return this.restService.request<Member>('post', '/account/signup', {
|
||||||
body: {
|
body: {
|
||||||
|
|
|
@ -4,9 +4,6 @@ import { Member } from '@overflow/commons-typescript/model/member';
|
||||||
|
|
||||||
export enum ActionType {
|
export enum ActionType {
|
||||||
Signin = '[member.member] Signin',
|
Signin = '[member.member] Signin',
|
||||||
|
|
||||||
SigninCookie = '[member.member] SigninCookie',
|
|
||||||
|
|
||||||
Signout = '[member.member] Signout',
|
Signout = '[member.member] Signout',
|
||||||
|
|
||||||
Signup = '[member.member] Signup',
|
Signup = '[member.member] Signup',
|
||||||
|
@ -32,12 +29,6 @@ export class Signin implements Action {
|
||||||
constructor(public payload: { email: string, password: string, returnURL: string }) { }
|
constructor(public payload: { email: string, password: string, returnURL: string }) { }
|
||||||
}
|
}
|
||||||
|
|
||||||
export class SigninCookie implements Action {
|
|
||||||
readonly type = ActionType.SigninCookie;
|
|
||||||
|
|
||||||
constructor(public payload: { authToken: string, returnURL: string }) { }
|
|
||||||
}
|
|
||||||
|
|
||||||
export class Signout implements Action {
|
export class Signout implements Action {
|
||||||
readonly type = ActionType.Signout;
|
readonly type = ActionType.Signout;
|
||||||
}
|
}
|
||||||
|
@ -116,7 +107,6 @@ export class ModifyPasswordFailure implements Action {
|
||||||
|
|
||||||
export type Actions =
|
export type Actions =
|
||||||
| Signin
|
| Signin
|
||||||
| SigninCookie
|
|
||||||
| Signout
|
| Signout
|
||||||
| Signup
|
| Signup
|
||||||
| SignupSuccess
|
| SignupSuccess
|
||||||
|
|
|
@ -10,7 +10,6 @@ import { MemberService } from '../../../service/member.service';
|
||||||
|
|
||||||
import {
|
import {
|
||||||
Signin,
|
Signin,
|
||||||
SigninCookie,
|
|
||||||
Signup,
|
Signup,
|
||||||
SignupSuccess,
|
SignupSuccess,
|
||||||
SignupFailure,
|
SignupFailure,
|
||||||
|
@ -60,22 +59,6 @@ export class Effects {
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
|
||||||
@Effect()
|
|
||||||
signinCookie$ = this.actions$.pipe(
|
|
||||||
ofType(ActionType.SigninCookie),
|
|
||||||
map((action: SigninCookie) => action.payload),
|
|
||||||
exhaustMap((signinInfo: { authToken: string, returnURL: string }) =>
|
|
||||||
this.memberService
|
|
||||||
.signin_cookie(signinInfo.authToken)
|
|
||||||
.pipe(
|
|
||||||
map((domainMember: DomainMember) => {
|
|
||||||
return new SigninCookieSuccess({ domainMember: domainMember, returnURL: signinInfo.returnURL });
|
|
||||||
}),
|
|
||||||
catchError(error => of(new SigninCookieFailure(error)))
|
|
||||||
)
|
|
||||||
)
|
|
||||||
);
|
|
||||||
|
|
||||||
@Effect()
|
@Effect()
|
||||||
signup$ = this.actions$.pipe(
|
signup$ = this.actions$.pipe(
|
||||||
ofType(ActionType.Signup),
|
ofType(ActionType.Signup),
|
||||||
|
|
|
@ -12,11 +12,12 @@ import { AppComponent } from './app.component';
|
||||||
|
|
||||||
import { CookieService } from 'ngx-cookie-service';
|
import { CookieService } from 'ngx-cookie-service';
|
||||||
import { AuthGuard } from './commons/guard/auth.guard';
|
import { AuthGuard } from './commons/guard/auth.guard';
|
||||||
|
import { AuthService } from './commons/service/auth.service';
|
||||||
|
|
||||||
import { BrowserModule } from '@angular/platform-browser';
|
import { BrowserModule } from '@angular/platform-browser';
|
||||||
import { BrowserAnimationsModule } from '@angular/platform-browser/animations';
|
import { BrowserAnimationsModule } from '@angular/platform-browser/animations';
|
||||||
|
|
||||||
import { AuthModule } from '@overflow/shared/auth/auth.module';
|
import { AuthModule } from '@overflow/shared/auth/auth.module';
|
||||||
import { MemberModule } from '@overflow/member/member.module';
|
|
||||||
|
|
||||||
@NgModule({
|
@NgModule({
|
||||||
imports: [
|
imports: [
|
||||||
|
@ -29,7 +30,6 @@ import { MemberModule } from '@overflow/member/member.module';
|
||||||
AppRPCModule,
|
AppRPCModule,
|
||||||
AppRESTModule,
|
AppRESTModule,
|
||||||
AppLoggerModule,
|
AppLoggerModule,
|
||||||
MemberModule,
|
|
||||||
AuthModule,
|
AuthModule,
|
||||||
],
|
],
|
||||||
declarations: [
|
declarations: [
|
||||||
|
@ -38,6 +38,7 @@ import { MemberModule } from '@overflow/member/member.module';
|
||||||
providers: [
|
providers: [
|
||||||
CookieService,
|
CookieService,
|
||||||
AuthGuard,
|
AuthGuard,
|
||||||
|
AuthService,
|
||||||
],
|
],
|
||||||
bootstrap: [AppComponent]
|
bootstrap: [AppComponent]
|
||||||
})
|
})
|
||||||
|
|
|
@ -30,7 +30,10 @@ export class AuthGuard implements CanActivate, CanActivateChild {
|
||||||
map(signined => {
|
map(signined => {
|
||||||
if (!signined) {
|
if (!signined) {
|
||||||
if (this.cookieService.check('authToken')) {
|
if (this.cookieService.check('authToken')) {
|
||||||
this.store.dispatch(new MemberEntityStore.SigninCookie({authToken: this.cookieService.get('authToken'), returnURL: state.url}));
|
this.store.dispatch(new SigninContaifnerStore.SigninCookie({
|
||||||
|
authToken: this.cookieService.get('authToken'),
|
||||||
|
returnURL: state.url
|
||||||
|
}));
|
||||||
} else {
|
} else {
|
||||||
this.store.dispatch(new SigninContaifnerStore.SigninRedirect({returnURL: state.url}));
|
this.store.dispatch(new SigninContaifnerStore.SigninRedirect({returnURL: state.url}));
|
||||||
}
|
}
|
||||||
|
@ -49,7 +52,10 @@ export class AuthGuard implements CanActivate, CanActivateChild {
|
||||||
map(signined => {
|
map(signined => {
|
||||||
if (!signined) {
|
if (!signined) {
|
||||||
if (this.cookieService.check('authToken')) {
|
if (this.cookieService.check('authToken')) {
|
||||||
this.store.dispatch(new MemberEntityStore.SigninCookie({authToken: this.cookieService.get('authToken'), returnURL: state.url}));
|
this.store.dispatch(new SigninContaifnerStore.SigninCookie({
|
||||||
|
authToken: this.cookieService.get('authToken'),
|
||||||
|
returnURL: state.url
|
||||||
|
}));
|
||||||
} else {
|
} else {
|
||||||
this.store.dispatch(new SigninContaifnerStore.SigninRedirect({returnURL: state.url}));
|
this.store.dispatch(new SigninContaifnerStore.SigninRedirect({returnURL: state.url}));
|
||||||
}
|
}
|
||||||
|
|
23
src/app/commons/service/auth.service.ts
Normal file
23
src/app/commons/service/auth.service.ts
Normal file
|
@ -0,0 +1,23 @@
|
||||||
|
import { Injectable } from '@angular/core';
|
||||||
|
import { Observable } from 'rxjs/Observable';
|
||||||
|
|
||||||
|
import { RESTService } from '@loafer/ng-rest';
|
||||||
|
import { DomainMember } from '@overflow/commons-typescript/model/domain';
|
||||||
|
|
||||||
|
@Injectable()
|
||||||
|
export class AuthService {
|
||||||
|
|
||||||
|
public constructor(
|
||||||
|
private restService: RESTService,
|
||||||
|
) {
|
||||||
|
}
|
||||||
|
|
||||||
|
public signin_cookie(authToken: string): Observable<DomainMember> {
|
||||||
|
return this.restService.request<DomainMember>('post', '/account/signin_cookie', {
|
||||||
|
body: {
|
||||||
|
authToken: authToken,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -2,6 +2,7 @@ import { Action } from '@ngrx/store';
|
||||||
|
|
||||||
export enum ActionType {
|
export enum ActionType {
|
||||||
SigninRedirect = '[app.signin] SigninRedirect',
|
SigninRedirect = '[app.signin] SigninRedirect',
|
||||||
|
SigninCookie = '[app.signin] SigninCookie',
|
||||||
}
|
}
|
||||||
|
|
||||||
export class SigninRedirect implements Action {
|
export class SigninRedirect implements Action {
|
||||||
|
@ -10,6 +11,14 @@ export class SigninRedirect implements Action {
|
||||||
constructor(public payload: {returnURL: string}) {}
|
constructor(public payload: {returnURL: string}) {}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export class SigninCookie implements Action {
|
||||||
|
readonly type = ActionType.SigninCookie;
|
||||||
|
|
||||||
|
constructor(public payload: { authToken: string, returnURL: string }) { }
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
export type Actions =
|
export type Actions =
|
||||||
| SigninRedirect
|
| SigninRedirect
|
||||||
|
| SigninCookie
|
||||||
;
|
;
|
||||||
|
|
|
@ -2,8 +2,8 @@ import { Injectable } from '@angular/core';
|
||||||
import { Router } from '@angular/router';
|
import { Router } from '@angular/router';
|
||||||
|
|
||||||
import { Effect, Actions, ofType } from '@ngrx/effects';
|
import { Effect, Actions, ofType } from '@ngrx/effects';
|
||||||
|
import { of } from 'rxjs';
|
||||||
import { map, tap } from 'rxjs/operators';
|
import { map, tap, exhaustMap, catchError } from 'rxjs/operators';
|
||||||
|
|
||||||
import { CookieService } from 'ngx-cookie-service';
|
import { CookieService } from 'ngx-cookie-service';
|
||||||
import { RPCService } from '@loafer/ng-rpc';
|
import { RPCService } from '@loafer/ng-rpc';
|
||||||
|
@ -11,14 +11,18 @@ import { RPCService } from '@loafer/ng-rpc';
|
||||||
import {
|
import {
|
||||||
SigninSuccess,
|
SigninSuccess,
|
||||||
SigninCookieSuccess,
|
SigninCookieSuccess,
|
||||||
|
SigninCookieFailure,
|
||||||
ActionType as AuthActionType,
|
ActionType as AuthActionType,
|
||||||
} from '@overflow/shared/auth/store/container/auth';
|
} from '@overflow/shared/auth/store/container/auth';
|
||||||
|
|
||||||
import {
|
import {
|
||||||
SigninRedirect,
|
SigninRedirect,
|
||||||
|
SigninCookie,
|
||||||
ActionType,
|
ActionType,
|
||||||
} from './app-signin.action';
|
} from './app-signin.action';
|
||||||
|
|
||||||
|
import { AuthService } from '../../../service/auth.service';
|
||||||
|
|
||||||
import { DomainMember } from '@overflow/commons-typescript/model/domain';
|
import { DomainMember } from '@overflow/commons-typescript/model/domain';
|
||||||
|
|
||||||
|
|
||||||
|
@ -29,6 +33,7 @@ export class Effects {
|
||||||
private actions$: Actions,
|
private actions$: Actions,
|
||||||
private rpcService: RPCService,
|
private rpcService: RPCService,
|
||||||
private cookieService: CookieService,
|
private cookieService: CookieService,
|
||||||
|
private authService: AuthService,
|
||||||
private router: Router
|
private router: Router
|
||||||
) { }
|
) { }
|
||||||
|
|
||||||
|
@ -47,6 +52,22 @@ export class Effects {
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@Effect()
|
||||||
|
signinCookie$ = this.actions$.pipe(
|
||||||
|
ofType(ActionType.SigninCookie),
|
||||||
|
map((action: SigninCookie) => action.payload),
|
||||||
|
exhaustMap((signinInfo: { authToken: string, returnURL: string }) =>
|
||||||
|
this.authService
|
||||||
|
.signin_cookie(signinInfo.authToken)
|
||||||
|
.pipe(
|
||||||
|
map((domainMember: DomainMember) => {
|
||||||
|
return new SigninCookieSuccess({ domainMember: domainMember, returnURL: signinInfo.returnURL });
|
||||||
|
}),
|
||||||
|
catchError(error => of(new SigninCookieFailure(error)))
|
||||||
|
)
|
||||||
|
)
|
||||||
|
);
|
||||||
|
|
||||||
@Effect({ dispatch: false })
|
@Effect({ dispatch: false })
|
||||||
signinCookieSuccess$ = this.actions$.pipe(
|
signinCookieSuccess$ = this.actions$.pipe(
|
||||||
ofType(AuthActionType.SigninCookieSuccess),
|
ofType(AuthActionType.SigninCookieSuccess),
|
||||||
|
|
Loading…
Reference in New Issue
Block a user