bug fixed

This commit is contained in:
richard-loafle 2020-04-07 14:23:34 +09:00
parent 1a052bf765
commit bb2ce39e6b
7 changed files with 152 additions and 109 deletions

View File

@ -1,4 +1,5 @@
import { Observable } from 'rxjs';
import { take } from 'rxjs/operators';
import { Injectable } from '@angular/core';
import {
@ -9,6 +10,12 @@ import {
Router
} from '@angular/router';
import { Store } from '@ngrx/store';
import { PiService } from '@ucap/ng-pi';
import { LoginActions } from '@ucap/ng-store-authentication';
import { AppAuthenticationService } from '@app/services/app-authentication.service';
@Injectable({
@ -16,7 +23,9 @@ import { AppAuthenticationService } from '@app/services/app-authentication.servi
})
export class AppAuthenticationGuard implements CanActivate {
constructor(
private piService: PiService,
private appAuthenticationService: AppAuthenticationService,
private store: Store<any>,
private router: Router
) {}
@ -32,8 +41,55 @@ export class AppAuthenticationGuard implements CanActivate {
if (this.appAuthenticationService.loggedIn()) {
resolve(true);
} else {
this.router.navigateByUrl('/account/login');
resolve(false);
const userStore = this.appAuthenticationService.useAutoLogin();
if (!!userStore) {
const loginSession = this.appAuthenticationService.loginSession;
const onWebLoginFailure = (error: any) => {
userStore.settings.general.autoLogin = false;
this.appAuthenticationService.userStore = userStore;
this.router.navigateByUrl('/account/login');
resolve(false);
};
this.piService
.login2({
companyCode: userStore.companyCode,
loginId: userStore.loginId,
loginPw: userStore.loginPw,
deviceType: loginSession.deviceType
})
.pipe(take(1))
.subscribe(
(res) => {
if ('success' !== res.status.toLowerCase()) {
onWebLoginFailure(res.status);
return;
} else {
this.store.dispatch(
LoginActions.webLoginSuccess({
companyCode: userStore.companyCode,
loginId: userStore.loginId,
loginPw: userStore.loginPw,
autoLogin: true,
rememberMe: userStore.rememberMe,
login2Response: res
})
);
resolve(true);
return;
}
},
(error) => {
onWebLoginFailure(error);
},
() => {}
);
} else {
this.router.navigateByUrl('/account/login');
resolve(false);
}
}
});
}

View File

@ -14,8 +14,8 @@ import { StatusCode } from '@ucap/api';
import { NativeService } from '@ucap/native';
import { SSOMode } from '@ucap/protocol-authentication';
import { LogService } from '@ucap/ng-logger';
import { UCAP_NATIVE_SERVICE } from '@ucap/ng-native';
import { SessionStorageService } from '@ucap/ng-web-storage';
import { PublicApiService } from '@ucap/ng-api-public';
import { ExternalApiService } from '@ucap/ng-api-external';
import { ProtocolService } from '@ucap/ng-protocol';
@ -28,11 +28,7 @@ import {
LoginActions
} from '@ucap/ng-store-authentication';
import { LoginSession } from '@app/models/login-session';
import { AppKey } from '@app/types/app-key.type';
import { AppActions } from '@app/store/actions';
import { LogService } from '@ucap/ng-logger';
import { AppAuthenticationService } from '@app/services/app-authentication.service';
@Injectable()
export class AppAuthenticationResolver implements Resolve<void> {
@ -43,7 +39,7 @@ export class AppAuthenticationResolver implements Resolve<void> {
private innerProtocolService: InnerProtocolService,
private authenticationProtocolService: AuthenticationProtocolService,
private store: Store<any>,
private sessionStorageService: SessionStorageService,
private appAuthenticationService: AppAuthenticationService,
private logService: LogService,
@Inject(UCAP_NATIVE_SERVICE) private nativeService: NativeService
) {}
@ -54,9 +50,7 @@ export class AppAuthenticationResolver implements Resolve<void> {
): void | Observable<void> | Promise<void> {
return new Promise<void>(async (resolve, reject) => {
try {
const loginSession = this.sessionStorageService.get<LoginSession>(
AppKey.LoginSession
);
const loginSession = this.appAuthenticationService.loginSession;
const networkInfo = await this.nativeService.getNetworkInfo();
const localIp =
!!networkInfo && 0 < networkInfo.length && !!networkInfo[0].ip
@ -139,7 +133,7 @@ export class AppAuthenticationResolver implements Resolve<void> {
concatMap(() => {
return this.innerProtocolService.conn({}).pipe(
take(1),
concatMap(connRes => {
concatMap((connRes) => {
return this.authenticationProtocolService
.login({
loginId: loginSession.loginId,
@ -166,7 +160,7 @@ export class AppAuthenticationResolver implements Resolve<void> {
})
)
.subscribe(
loginRes => {
(loginRes) => {
this.store.dispatch(
LoginActions.loginSuccess({
res: loginRes,
@ -175,12 +169,12 @@ export class AppAuthenticationResolver implements Resolve<void> {
);
resolve();
},
error => {
(error) => {
reject(error);
}
);
},
error => {
(error) => {
reject(error);
}
);

View File

@ -1,4 +1,5 @@
import { Subscription } from 'rxjs';
import { take, filter } from 'rxjs/operators';
import { Component, OnInit, OnDestroy, Input, ViewChild } from '@angular/core';
@ -20,7 +21,7 @@ import { LoginActions } from '@ucap/ng-store-authentication';
import { UserStore } from '@app/models/user-store';
import { LoginSession } from '@app/models/login-session';
import { AppKey } from '@app/types/app-key.type';
import { take, filter } from 'rxjs/operators';
import { AppAuthenticationService } from '@app/services/app-authentication.service';
@Component({
selector: 'app-sections-account-login',
@ -64,13 +65,12 @@ export class LoginSectionComponent implements OnInit, OnDestroy {
private sessionStorageService: SessionStorageService,
private i18nService: I18nService,
private store: Store<any>,
private appAuthenticationService: AppAuthenticationService,
private logService: LogService
) {}
ngOnInit(): void {
this.loginSession = this.sessionStorageService.get<LoginSession>(
AppKey.LoginSession
);
this.loginSession = this.appAuthenticationService.loginSession;
this.loginTry = this.sessionStorageService.get<LoginTry>(AppKey.LoginTry);
@ -84,13 +84,13 @@ export class LoginSectionComponent implements OnInit, OnDestroy {
this.companyListSubscription = this.store
.pipe(select(CompanySelector.companyList))
.subscribe(companyList => {
.subscribe((companyList) => {
this.companyList = companyList;
});
this.loginTrySubscription = this.sessionStorageService.changed$
.pipe(filter(param => AppKey.LoginTry === param.key))
.subscribe(param => {
.pipe(filter((param) => AppKey.LoginTry === param.key))
.subscribe((param) => {
this.loginTry = param.value as LoginTry;
});
}
@ -125,7 +125,7 @@ export class LoginSectionComponent implements OnInit, OnDestroy {
})
.pipe(take(1))
.subscribe(
res => {
(res) => {
if ('success' !== res.status.toLowerCase()) {
this.onWebLoginFailure(event, res.status);
return;
@ -143,7 +143,7 @@ export class LoginSectionComponent implements OnInit, OnDestroy {
return;
}
},
error => {
(error) => {
this.onWebLoginFailure(event, error);
},
() => {

View File

@ -29,21 +29,65 @@ export class AppAuthenticationService {
@Inject(UCAP_NATIVE_SERVICE) private nativeService: NativeService
) {}
loggedIn(): boolean {
get userStore(): UserStore {
const userStore = this.localStorageService.encGet<UserStore>(
AppKey.UserStore,
environment.productConfig.localEncriptionKey
);
return userStore;
}
set userStore(userStore: UserStore) {
const oldUserStore = this.userStore;
this.localStorageService.encSet<UserStore>(
AppKey.UserStore,
{
...oldUserStore,
...userStore
},
environment.productConfig.localEncriptionKey
);
}
get loginSession(): LoginSession {
const loginSession = this.sessionStorageService.get<LoginSession>(
AppKey.LoginSession
);
return loginSession;
}
set loginSession(loginSession: LoginSession) {
const oldLoginSession = this.loginSession;
this.sessionStorageService.set<LoginSession>(AppKey.LoginSession, {
...oldLoginSession,
...loginSession
});
}
loggedIn(): boolean {
const loginSession = this.loginSession;
return !!loginSession && !!loginSession.loginId;
}
async login(
useAutoLogin(): UserStore | null {
const userStore = this.userStore;
return !!userStore &&
!!userStore.settings &&
!!userStore.settings.general &&
userStore.settings.general.autoLogin
? userStore
: null;
}
async postWebLogin(
loginSession: LoginSession,
rememberMe: boolean,
autoLogin: boolean
) {
const prevLoginSession = this.sessionStorageService.get<LoginSession>(
AppKey.LoginSession
);
const prevLoginSession = this.loginSession;
loginSession = {
...prevLoginSession,
@ -52,16 +96,13 @@ export class AppAuthenticationService {
};
const encLoginPw = PasswordUtil.encrypt(loginSession.loginPw);
this.sessionStorageService.set<LoginSession>(AppKey.LoginSession, {
this.loginSession = {
...loginSession,
initPw: loginSession.loginId === loginSession.loginPw,
loginPw: encLoginPw
});
};
let userStore = this.localStorageService.encGet<UserStore>(
AppKey.UserStore,
environment.productConfig.localEncriptionKey
);
let userStore = this.userStore;
if (!userStore) {
userStore = {
@ -101,11 +142,7 @@ export class AppAuthenticationService {
userStore.settings.general.autoLogin = autoLogin;
}
this.localStorageService.encSet<UserStore>(
AppKey.UserStore,
userStore,
environment.productConfig.localEncriptionKey
);
this.userStore = userStore;
this.sessionStorageService.remove(AppKey.LogoutSession);
}
@ -117,10 +154,7 @@ export class AppAuthenticationService {
this.sessionStorageService.remove(AppKey.UrlInfoResponse);
this.sessionStorageService.remove(AppKey.AuthResponse);
let userStore = this.localStorageService.encGet<UserStore>(
AppKey.UserStore,
environment.productConfig.localEncriptionKey
);
let userStore = this.userStore;
if (!!userStore) {
userStore = {
@ -134,11 +168,7 @@ export class AppAuthenticationService {
}
};
this.localStorageService.encSet<UserStore>(
AppKey.UserStore,
userStore,
environment.productConfig.localEncriptionKey
);
this.userStore = userStore;
}
}
}

View File

@ -11,21 +11,20 @@ import { PingProtocolService } from '@ucap/ng-protocol-ping';
import { DateService } from '@ucap/ng-ui';
import { TranslateService } from '@ucap/ng-ui-organization';
import { LoginSession } from '@app/models/login-session';
import { AppKey } from '@app/types/app-key.type';
import { environment } from '@environments';
import { AppAuthenticationService } from './app-authentication.service';
@Injectable()
export class AppService {
readonly companyGroupCode = environment.companyConfig.companyGroupCode;
constructor(
private sessionStorageService: SessionStorageService,
private i18nService: I18nService,
private translateService: TranslateService,
private dateService: DateService,
private pingProtocolService: PingProtocolService,
private appAuthenticationService: AppAuthenticationService,
private logService: LogService,
@Inject(UCAP_NATIVE_SERVICE) private nativeService: NativeService
) {}
@ -33,9 +32,7 @@ export class AppService {
initialize(): Promise<void[]> {
const initSession = new Promise<void>(async (resolve, reject) => {
try {
let loginSession = this.sessionStorageService.get<LoginSession>(
AppKey.LoginSession
);
let loginSession = this.appAuthenticationService.loginSession;
loginSession = loginSession || {};
@ -67,12 +64,12 @@ export class AppService {
break;
}
this.sessionStorageService.set<LoginSession>(AppKey.LoginSession, {
this.appAuthenticationService.loginSession = {
...loginSession,
deviceType,
desktopType,
companyGroupCode: this.companyGroupCode
});
};
this.dateService.setDefaultTimezone('Asia/Seoul');
this.dateService.use('Asia/Seoul');

View File

@ -31,9 +31,9 @@ export class Effects {
() =>
this.actions$.pipe(
ofType(LoginActions.webLoginSuccess),
tap(params => {
tap((params) => {
this.nativeService.checkForUpdates(params.login2Response.version);
this.appAuthenticationService.login(
this.appAuthenticationService.postWebLogin(
{
companyCode: params.companyCode,
loginId: params.loginId,
@ -52,7 +52,7 @@ export class Effects {
() =>
this.actions$.pipe(
ofType(LoginActions.webLoginFailure),
tap(params => {
tap((params) => {
let loginTry = this.sessionStorageService.get<LoginTry>(
AppKey.LoginTry
);
@ -91,14 +91,14 @@ export class Effects {
interval(1000)
.pipe(takeUntil(waitTimer$))
.subscribe(
v => {
(v) => {
loginTry.remainTimeForNextTry = this.intervalForRetry - v;
this.sessionStorageService.set<LoginTry>(
AppKey.LoginTry,
loginTry
);
},
error => {},
(error) => {},
() => {
loginTry = {
failCount: 0,

View File

@ -9,28 +9,12 @@
"component-class-suffix": true,
"contextual-lifecycle": true,
"directive-class-suffix": true,
"directive-selector": [
true,
"attribute",
"app",
"camelCase"
],
"component-selector": [
true,
"element",
"app",
"kebab-case"
],
"import-blacklist": [
true,
"rxjs/Rx"
],
"directive-selector": [true, "attribute", "app", "camelCase"],
"component-selector": [true, "element", "app", "kebab-case"],
"import-blacklist": [true, "rxjs/Rx"],
"interface-name": false,
"max-classes-per-file": false,
"max-line-length": [
true,
140
],
"max-line-length": [true, 140],
"member-access": false,
"member-ordering": [
true,
@ -44,33 +28,17 @@
}
],
"no-consecutive-blank-lines": false,
"no-console": [
true,
"debug",
"info",
"time",
"timeEnd",
"trace"
],
"no-console": [true, "debug", "info", "time", "timeEnd", "trace"],
"no-empty": false,
"no-inferrable-types": [
true,
"ignore-params"
],
"no-non-null-assertion": true,
"no-inferrable-types": [true, "ignore-params"],
"no-non-null-assertion": false,
"no-redundant-jsdoc": true,
"no-switch-case-fall-through": true,
"no-var-requires": false,
"object-literal-key-quotes": [
true,
"as-needed"
],
"object-literal-key-quotes": [true, "as-needed"],
"object-literal-sort-keys": false,
"ordered-imports": false,
"quotemark": [
true,
"single"
],
"quotemark": [true, "single"],
"trailing-comma": false,
"no-conflicting-lifecycle": true,
"no-host-metadata-property": true,
@ -85,7 +53,5 @@
"use-lifecycle-interface": true,
"use-pipe-transform-interface": true
},
"rulesDirectory": [
"codelyzer"
]
"rulesDirectory": ["codelyzer"]
}