ing
This commit is contained in:
parent
c1a5179bfc
commit
dfd124f62c
|
@ -19,9 +19,8 @@ import { CookieService } from 'ngx-cookie-service';
|
||||||
import { RPCClient } from 'packages/core/rpc/client/RPCClient';
|
import { RPCClient } from 'packages/core/rpc/client/RPCClient';
|
||||||
|
|
||||||
import {
|
import {
|
||||||
Signin,
|
|
||||||
SigninSuccess,
|
SigninSuccess,
|
||||||
SigninFailure,
|
SigninCookieSuccess,
|
||||||
ActionType,
|
ActionType,
|
||||||
} from 'packages/member/store/auth';
|
} from 'packages/member/store/auth';
|
||||||
|
|
||||||
|
@ -53,4 +52,17 @@ export class Effects {
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@Effect({ dispatch: false })
|
||||||
|
signinCookieSuccess$ = this.actions$
|
||||||
|
.ofType(ActionType.SigninCookieSuccess)
|
||||||
|
.map((action: SigninCookieSuccess) => action.payload)
|
||||||
|
.do(
|
||||||
|
(result) => {
|
||||||
|
const authToken = this.cookieService.get('authToken');
|
||||||
|
// console.log(`authToken: ${authToken}`);
|
||||||
|
const queryString = `authToken=${authToken}`;
|
||||||
|
|
||||||
|
this.rpcClient.connect(queryString);
|
||||||
|
}
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
|
@ -35,8 +35,6 @@ export class RESTClient {
|
||||||
reportProgress?: boolean;
|
reportProgress?: boolean;
|
||||||
withCredentials?: boolean;
|
withCredentials?: boolean;
|
||||||
}): Observable<T> {
|
}): Observable<T> {
|
||||||
// options.withCredentials = true;
|
|
||||||
|
|
||||||
return this._httpClient
|
return this._httpClient
|
||||||
.request<T>(method, Location.joinWithSlash(this._baseURL, entry), options)
|
.request<T>(method, Location.joinWithSlash(this._baseURL, entry), options)
|
||||||
.map(
|
.map(
|
||||||
|
|
|
@ -84,9 +84,7 @@ export class SigninComponent implements OnInit {
|
||||||
}
|
}
|
||||||
signin() {
|
signin() {
|
||||||
const signinValue = Object.assign({}, this.signinForm.value);
|
const signinValue = Object.assign({}, this.signinForm.value);
|
||||||
signinValue.options = {
|
signinValue.returnURL = this.returnURL;
|
||||||
returnURL: this.returnURL,
|
|
||||||
};
|
|
||||||
|
|
||||||
this.store.dispatch(new AuthStore.Signin(signinValue));
|
this.store.dispatch(new AuthStore.Signin(signinValue));
|
||||||
console.log('signin component signin fnc');
|
console.log('signin component signin fnc');
|
||||||
|
|
|
@ -28,6 +28,16 @@ export class MemberService {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public signin_cookie(authToken: string): Observable<DomainMember> {
|
||||||
|
const body = {
|
||||||
|
authToken: authToken,
|
||||||
|
};
|
||||||
|
|
||||||
|
return this.restClient.request<DomainMember>('post', '/account/signin_cookie', {
|
||||||
|
body: body,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
public signup(member: Member): Observable<Member> {
|
public signup(member: Member): Observable<Member> {
|
||||||
return this.restClient.request<Member>('post', '/account/signup', {
|
return this.restClient.request<Member>('post', '/account/signup', {
|
||||||
body: member,
|
body: member,
|
||||||
|
|
|
@ -10,6 +10,11 @@ export enum ActionType {
|
||||||
SigninSuccess = '[member.auth] SigninSuccess',
|
SigninSuccess = '[member.auth] SigninSuccess',
|
||||||
SigninFailure = '[member.auth] SigninFailure',
|
SigninFailure = '[member.auth] SigninFailure',
|
||||||
SigninRedirect = '[member.auth] SigninRedirect',
|
SigninRedirect = '[member.auth] SigninRedirect',
|
||||||
|
|
||||||
|
SigninCookie = '[member.auth] SigninCookie',
|
||||||
|
SigninCookieSuccess = '[member.auth] SigninCookieSuccess',
|
||||||
|
SigninCookieFailure = '[member.auth] SigninCookieFailure',
|
||||||
|
|
||||||
Signout = '[member.auth] Signout',
|
Signout = '[member.auth] Signout',
|
||||||
SignoutSuccess = '[member.auth] SignoutSuccess',
|
SignoutSuccess = '[member.auth] SignoutSuccess',
|
||||||
SignoutFailure = '[member.auth] SignoutFailure',
|
SignoutFailure = '[member.auth] SignoutFailure',
|
||||||
|
@ -18,7 +23,7 @@ export enum ActionType {
|
||||||
export class Signin implements Action {
|
export class Signin implements Action {
|
||||||
readonly type = ActionType.Signin;
|
readonly type = ActionType.Signin;
|
||||||
|
|
||||||
constructor(public payload: {email: string, password: string, options: any}) {}
|
constructor(public payload: {email: string, password: string, returnURL: string}) {}
|
||||||
}
|
}
|
||||||
|
|
||||||
export class SigninSuccess implements Action {
|
export class SigninSuccess implements Action {
|
||||||
|
@ -38,6 +43,24 @@ export class SigninRedirect implements Action {
|
||||||
constructor(public payload: string) {}
|
constructor(public payload: string) {}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export class SigninCookie implements Action {
|
||||||
|
readonly type = ActionType.SigninCookie;
|
||||||
|
|
||||||
|
constructor(public payload: {authToken: string, returnURL: string}) {}
|
||||||
|
}
|
||||||
|
|
||||||
|
export class SigninCookieSuccess implements Action {
|
||||||
|
readonly type = ActionType.SigninCookieSuccess;
|
||||||
|
|
||||||
|
constructor(public payload: DomainMember) {}
|
||||||
|
}
|
||||||
|
|
||||||
|
export class SigninCookieFailure implements Action {
|
||||||
|
readonly type = ActionType.SigninCookieFailure;
|
||||||
|
|
||||||
|
constructor(public payload: RESTError) {}
|
||||||
|
}
|
||||||
|
|
||||||
export class Signout implements Action {
|
export class Signout implements Action {
|
||||||
readonly type = ActionType.Signout;
|
readonly type = ActionType.Signout;
|
||||||
}
|
}
|
||||||
|
@ -57,6 +80,9 @@ export type Actions =
|
||||||
| SigninSuccess
|
| SigninSuccess
|
||||||
| SigninFailure
|
| SigninFailure
|
||||||
| SigninRedirect
|
| SigninRedirect
|
||||||
|
| SigninCookie
|
||||||
|
| SigninCookieSuccess
|
||||||
|
| SigninCookieFailure
|
||||||
| Signout
|
| Signout
|
||||||
| SignoutSuccess
|
| SignoutSuccess
|
||||||
| SignoutFailure
|
| SignoutFailure
|
||||||
|
|
|
@ -26,12 +26,16 @@ import {
|
||||||
SigninSuccess,
|
SigninSuccess,
|
||||||
SigninFailure,
|
SigninFailure,
|
||||||
SigninRedirect,
|
SigninRedirect,
|
||||||
|
SigninCookie,
|
||||||
|
SigninCookieSuccess,
|
||||||
|
SigninCookieFailure,
|
||||||
|
|
||||||
ActionType,
|
ActionType,
|
||||||
} from './auth.action';
|
} from './auth.action';
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class Effects {
|
export class Effects {
|
||||||
private _options: any;
|
private _returnURL: any;
|
||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
private actions$: Actions,
|
private actions$: Actions,
|
||||||
|
@ -44,12 +48,12 @@ export class Effects {
|
||||||
.ofType(ActionType.Signin)
|
.ofType(ActionType.Signin)
|
||||||
.map((action: Signin) => action.payload)
|
.map((action: Signin) => action.payload)
|
||||||
.switchMap(payload => {
|
.switchMap(payload => {
|
||||||
this._options = payload.options;
|
this._returnURL = payload.returnURL;
|
||||||
return this.memberService.signin(payload.email, payload.password);
|
return this.memberService.signin(payload.email, payload.password);
|
||||||
})
|
})
|
||||||
.map((result: any) => {
|
.map((result: any) => {
|
||||||
const authToken = result['authToken'];
|
const authToken = result['authToken'];
|
||||||
const domainMember = JSON.parse(result['domainMember']);
|
const domainMember = result['domainMember'];
|
||||||
return new SigninSuccess({authToken: authToken, domainMember: domainMember});
|
return new SigninSuccess({authToken: authToken, domainMember: domainMember});
|
||||||
})
|
})
|
||||||
.catch((error: RESTError) => {
|
.catch((error: RESTError) => {
|
||||||
|
@ -60,7 +64,7 @@ export class Effects {
|
||||||
signinSuccess$ = this.actions$
|
signinSuccess$ = this.actions$
|
||||||
.ofType(ActionType.SigninSuccess)
|
.ofType(ActionType.SigninSuccess)
|
||||||
.do(() => {
|
.do(() => {
|
||||||
this.router.navigateByUrl(this._options.returnURL);
|
this.router.navigateByUrl(this._returnURL);
|
||||||
});
|
});
|
||||||
|
|
||||||
@Effect({ dispatch: false })
|
@Effect({ dispatch: false })
|
||||||
|
@ -71,4 +75,33 @@ export class Effects {
|
||||||
this.router.navigate(['/auth/signin'], {queryParams: {returnURL: returnURL}});
|
this.router.navigate(['/auth/signin'], {queryParams: {returnURL: returnURL}});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
|
@Effect()
|
||||||
|
signinCookie$: Observable<Action> = this.actions$
|
||||||
|
.ofType(ActionType.SigninCookie)
|
||||||
|
.map((action: SigninCookie) => action.payload)
|
||||||
|
.switchMap((payload) => {
|
||||||
|
this._returnURL = payload.returnURL;
|
||||||
|
return this.memberService.signin_cookie(payload.authToken);
|
||||||
|
})
|
||||||
|
.map((domainMember: DomainMember) => {
|
||||||
|
return new SigninCookieSuccess(domainMember);
|
||||||
|
})
|
||||||
|
.catch((error: RESTError) => {
|
||||||
|
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);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
|
@ -45,6 +45,29 @@ export function reducer(state = initialState, action: Actions): State {
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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: {
|
case ActionType.Signout: {
|
||||||
return {
|
return {
|
||||||
...state,
|
...state,
|
||||||
|
|
Loading…
Reference in New Issue
Block a user