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