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 { Observable } from 'rxjs';
import { take } from 'rxjs/operators';
import { Injectable } from '@angular/core'; import { Injectable } from '@angular/core';
import { import {
@ -9,6 +10,12 @@ import {
Router Router
} from '@angular/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'; import { AppAuthenticationService } from '@app/services/app-authentication.service';
@Injectable({ @Injectable({
@ -16,7 +23,9 @@ import { AppAuthenticationService } from '@app/services/app-authentication.servi
}) })
export class AppAuthenticationGuard implements CanActivate { export class AppAuthenticationGuard implements CanActivate {
constructor( constructor(
private piService: PiService,
private appAuthenticationService: AppAuthenticationService, private appAuthenticationService: AppAuthenticationService,
private store: Store<any>,
private router: Router private router: Router
) {} ) {}
@ -32,8 +41,55 @@ export class AppAuthenticationGuard implements CanActivate {
if (this.appAuthenticationService.loggedIn()) { if (this.appAuthenticationService.loggedIn()) {
resolve(true); resolve(true);
} else { } else {
this.router.navigateByUrl('/account/login'); const userStore = this.appAuthenticationService.useAutoLogin();
resolve(false); 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 { NativeService } from '@ucap/native';
import { SSOMode } from '@ucap/protocol-authentication'; import { SSOMode } from '@ucap/protocol-authentication';
import { LogService } from '@ucap/ng-logger';
import { UCAP_NATIVE_SERVICE } from '@ucap/ng-native'; import { UCAP_NATIVE_SERVICE } from '@ucap/ng-native';
import { SessionStorageService } from '@ucap/ng-web-storage';
import { PublicApiService } from '@ucap/ng-api-public'; import { PublicApiService } from '@ucap/ng-api-public';
import { ExternalApiService } from '@ucap/ng-api-external'; import { ExternalApiService } from '@ucap/ng-api-external';
import { ProtocolService } from '@ucap/ng-protocol'; import { ProtocolService } from '@ucap/ng-protocol';
@ -28,11 +28,7 @@ import {
LoginActions LoginActions
} from '@ucap/ng-store-authentication'; } from '@ucap/ng-store-authentication';
import { LoginSession } from '@app/models/login-session'; import { AppAuthenticationService } from '@app/services/app-authentication.service';
import { AppKey } from '@app/types/app-key.type';
import { AppActions } from '@app/store/actions';
import { LogService } from '@ucap/ng-logger';
@Injectable() @Injectable()
export class AppAuthenticationResolver implements Resolve<void> { export class AppAuthenticationResolver implements Resolve<void> {
@ -43,7 +39,7 @@ export class AppAuthenticationResolver implements Resolve<void> {
private innerProtocolService: InnerProtocolService, private innerProtocolService: InnerProtocolService,
private authenticationProtocolService: AuthenticationProtocolService, private authenticationProtocolService: AuthenticationProtocolService,
private store: Store<any>, private store: Store<any>,
private sessionStorageService: SessionStorageService, private appAuthenticationService: AppAuthenticationService,
private logService: LogService, private logService: LogService,
@Inject(UCAP_NATIVE_SERVICE) private nativeService: NativeService @Inject(UCAP_NATIVE_SERVICE) private nativeService: NativeService
) {} ) {}
@ -54,9 +50,7 @@ export class AppAuthenticationResolver implements Resolve<void> {
): void | Observable<void> | Promise<void> { ): void | Observable<void> | Promise<void> {
return new Promise<void>(async (resolve, reject) => { return new Promise<void>(async (resolve, reject) => {
try { try {
const loginSession = this.sessionStorageService.get<LoginSession>( const loginSession = this.appAuthenticationService.loginSession;
AppKey.LoginSession
);
const networkInfo = await this.nativeService.getNetworkInfo(); const networkInfo = await this.nativeService.getNetworkInfo();
const localIp = const localIp =
!!networkInfo && 0 < networkInfo.length && !!networkInfo[0].ip !!networkInfo && 0 < networkInfo.length && !!networkInfo[0].ip
@ -139,7 +133,7 @@ export class AppAuthenticationResolver implements Resolve<void> {
concatMap(() => { concatMap(() => {
return this.innerProtocolService.conn({}).pipe( return this.innerProtocolService.conn({}).pipe(
take(1), take(1),
concatMap(connRes => { concatMap((connRes) => {
return this.authenticationProtocolService return this.authenticationProtocolService
.login({ .login({
loginId: loginSession.loginId, loginId: loginSession.loginId,
@ -166,7 +160,7 @@ export class AppAuthenticationResolver implements Resolve<void> {
}) })
) )
.subscribe( .subscribe(
loginRes => { (loginRes) => {
this.store.dispatch( this.store.dispatch(
LoginActions.loginSuccess({ LoginActions.loginSuccess({
res: loginRes, res: loginRes,
@ -175,12 +169,12 @@ export class AppAuthenticationResolver implements Resolve<void> {
); );
resolve(); resolve();
}, },
error => { (error) => {
reject(error); reject(error);
} }
); );
}, },
error => { (error) => {
reject(error); reject(error);
} }
); );

View File

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

View File

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

View File

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

View File

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

View File

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