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