login is implemented
This commit is contained in:
parent
9913c89689
commit
d60ebd06ee
@ -45,7 +45,7 @@ export class LoginPageComponent implements OnInit {
|
||||
notValid: () => void;
|
||||
}) {
|
||||
this.store.dispatch(
|
||||
AuthenticationStore.login({
|
||||
AuthenticationStore.webLogin({
|
||||
loginInfo: {
|
||||
companyCode: value.companyCode,
|
||||
loginId: value.loginId,
|
||||
|
@ -4,8 +4,8 @@ import {
|
||||
ActivatedRouteSnapshot,
|
||||
RouterStateSnapshot
|
||||
} from '@angular/router';
|
||||
import { Observable } from 'rxjs';
|
||||
import { take, map } from 'rxjs/operators';
|
||||
import { Observable, of } from 'rxjs';
|
||||
import { take, map, catchError } from 'rxjs/operators';
|
||||
|
||||
import { Store, select } from '@ngrx/store';
|
||||
|
||||
@ -22,6 +22,7 @@ import {
|
||||
SSOMode
|
||||
} from '@ucap-webmessenger/protocol-authentication';
|
||||
import { LocaleCode } from '@ucap-webmessenger/core';
|
||||
import * as AuthenticationStore from '@app/store/account/authentication';
|
||||
|
||||
@Injectable()
|
||||
export class AppMessengerResolver implements Resolve<void> {
|
||||
@ -83,7 +84,16 @@ export class AppMessengerResolver implements Resolve<void> {
|
||||
.pipe(
|
||||
take(1),
|
||||
map(loginRes => {
|
||||
console.log('loginRes', loginRes);
|
||||
this.store.dispatch(
|
||||
AuthenticationStore.loginSuccess({
|
||||
loginInfo: loginRes
|
||||
})
|
||||
);
|
||||
}),
|
||||
catchError(err => {
|
||||
return of(
|
||||
AuthenticationStore.loginFailure({ error: err })
|
||||
);
|
||||
})
|
||||
)
|
||||
.subscribe();
|
||||
|
@ -1,19 +1,20 @@
|
||||
import { createAction, props } from '@ngrx/store';
|
||||
|
||||
import { Login2Response } from '@ucap-webmessenger/pi';
|
||||
import { LoginResponse } from '@ucap-webmessenger/protocol-authentication';
|
||||
|
||||
import { LoginInfo } from '../../../types';
|
||||
|
||||
export const login = createAction(
|
||||
'[Account::Authentication] Login',
|
||||
export const webLogin = createAction(
|
||||
'[Account::Authentication] Web Login',
|
||||
props<{
|
||||
loginInfo: LoginInfo;
|
||||
rememberMe: boolean;
|
||||
}>()
|
||||
);
|
||||
|
||||
export const loginSuccess = createAction(
|
||||
'[Account::Authentication] Login Success',
|
||||
export const webLoginSuccess = createAction(
|
||||
'[Account::Authentication] Web Login Success',
|
||||
props<{
|
||||
loginInfo: LoginInfo;
|
||||
rememberMe: boolean;
|
||||
@ -21,6 +22,18 @@ export const loginSuccess = createAction(
|
||||
}>()
|
||||
);
|
||||
|
||||
export const webLoginFailure = createAction(
|
||||
'[Account::Authentication] Web Login Failure',
|
||||
props<{ error: any }>()
|
||||
);
|
||||
|
||||
export const loginSuccess = createAction(
|
||||
'[Account::Authentication] Login Success',
|
||||
props<{
|
||||
loginInfo: LoginResponse;
|
||||
}>()
|
||||
);
|
||||
|
||||
export const loginFailure = createAction(
|
||||
'[Account::Authentication] Login Failure',
|
||||
props<{ error: any }>()
|
||||
|
@ -20,22 +20,24 @@ import {
|
||||
} from '@ucap-webmessenger/ui';
|
||||
|
||||
import {
|
||||
login,
|
||||
loginSuccess,
|
||||
loginFailure,
|
||||
loginRedirect,
|
||||
logout,
|
||||
logoutConfirmation,
|
||||
logoutConfirmationDismiss
|
||||
logoutConfirmationDismiss,
|
||||
webLogin,
|
||||
webLoginSuccess,
|
||||
webLoginFailure
|
||||
} from './actions';
|
||||
import { LoginInfo } from '../../../types';
|
||||
import { AppAuthenticationService } from '../../../services/authentication.service';
|
||||
|
||||
@Injectable()
|
||||
export class Effects {
|
||||
login$ = createEffect(() =>
|
||||
webLogin$ = createEffect(() =>
|
||||
this.actions$.pipe(
|
||||
ofType(login),
|
||||
ofType(webLogin),
|
||||
map(action => action),
|
||||
exhaustMap((params: { loginInfo: LoginInfo; rememberMe: boolean }) =>
|
||||
this.piService
|
||||
@ -47,25 +49,25 @@ export class Effects {
|
||||
.pipe(
|
||||
map((res: Login2Response) => {
|
||||
if (res.status === ResponseStatus.Fail) {
|
||||
return loginFailure({ error: 'Failed' });
|
||||
return webLoginFailure({ error: 'Failed' });
|
||||
} else {
|
||||
return loginSuccess({
|
||||
return webLoginSuccess({
|
||||
loginInfo: params.loginInfo,
|
||||
rememberMe: params.rememberMe,
|
||||
login2Response: res
|
||||
});
|
||||
}
|
||||
}),
|
||||
catchError(error => of(loginFailure({ error })))
|
||||
catchError(error => of(webLoginFailure({ error })))
|
||||
)
|
||||
)
|
||||
)
|
||||
);
|
||||
|
||||
loginSuccess$ = createEffect(
|
||||
webLoginSuccess$ = createEffect(
|
||||
() =>
|
||||
this.actions$.pipe(
|
||||
ofType(loginSuccess),
|
||||
ofType(webLoginSuccess),
|
||||
tap(params => {
|
||||
this.nativeService
|
||||
.checkForUpdates()
|
||||
|
@ -1,6 +1,13 @@
|
||||
import { Action, combineReducers } from '@ngrx/store';
|
||||
import { State } from './state';
|
||||
import { Action, combineReducers, createReducer, on } from '@ngrx/store';
|
||||
import { State, initialState } from './state';
|
||||
import { loginSuccess } from './actions';
|
||||
|
||||
export function reducers(state: State | undefined, action: Action) {
|
||||
return combineReducers({})(state, action);
|
||||
}
|
||||
export const reducer = createReducer(
|
||||
initialState,
|
||||
on(loginSuccess, (state, action) => {
|
||||
return {
|
||||
...state,
|
||||
loginInfo: action.loginInfo
|
||||
};
|
||||
})
|
||||
);
|
||||
|
@ -1,10 +1,20 @@
|
||||
import { Selector } from '@ngrx/store';
|
||||
import { Selector, createSelector } from '@ngrx/store';
|
||||
import { LoginResponse } from '@ucap-webmessenger/protocol-authentication';
|
||||
|
||||
// tslint:disable-next-line: no-empty-interface
|
||||
export interface State {}
|
||||
export interface State {
|
||||
loginInfo: LoginResponse | null;
|
||||
}
|
||||
|
||||
export const initialState: State = {};
|
||||
export const initialState: State = {
|
||||
loginInfo: null
|
||||
};
|
||||
|
||||
export function selectors<S>(selector: Selector<any, State>) {
|
||||
return {};
|
||||
return {
|
||||
loginInfo: createSelector(
|
||||
selector,
|
||||
(state: State) => state.loginInfo
|
||||
)
|
||||
};
|
||||
}
|
||||
|
@ -11,7 +11,7 @@ export const effects: Type<any>[] = [AuthenticationStore.Effects];
|
||||
|
||||
export function reducers(state: State | undefined, action: Action) {
|
||||
return combineReducers({
|
||||
authentication: AuthenticationStore.reducers
|
||||
authentication: AuthenticationStore.reducer
|
||||
})(state, action);
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user