Browse Source

remove session.handler

pull/7861/head
mehmet-erim 6 years ago
parent
commit
7eee869bfc
  1. 14
      npm/ng-packs/packages/account/config/src/account-config.module.ts
  2. 1
      npm/ng-packs/packages/account/config/src/handlers/index.ts
  3. 53
      npm/ng-packs/packages/account/config/src/handlers/session.handler.ts
  4. 1
      npm/ng-packs/packages/account/config/src/public-api.ts

14
npm/ng-packs/packages/account/config/src/account-config.module.ts

@ -1,6 +1,4 @@
import { noop } from '@abp/ng.core';
import { APP_INITIALIZER, ModuleWithProviders, NgModule } from '@angular/core';
import { SessionHandler } from './handlers/session.handler';
import { ModuleWithProviders, NgModule } from '@angular/core';
import { ACCOUNT_ROUTE_PROVIDERS } from './providers/route.provider';
@NgModule()
@ -8,15 +6,7 @@ export class AccountConfigModule {
static forRoot(): ModuleWithProviders<AccountConfigModule> {
return {
ngModule: AccountConfigModule,
providers: [
ACCOUNT_ROUTE_PROVIDERS,
{
provide: APP_INITIALIZER,
multi: true,
deps: [SessionHandler],
useFactory: noop,
},
],
providers: [ACCOUNT_ROUTE_PROVIDERS],
};
}
}

1
npm/ng-packs/packages/account/config/src/handlers/index.ts

@ -1 +0,0 @@
export * from './session.handler';

53
npm/ng-packs/packages/account/config/src/handlers/session.handler.ts

@ -1,53 +0,0 @@
import { EnvironmentService } from '@abp/ng.core';
import { Injectable } from '@angular/core';
import { OAuthService } from 'angular-oauth2-oidc';
import { filter, take } from 'rxjs/operators';
const cookieKey = 'rememberMe';
const storageKey = 'rememberMe';
@Injectable({ providedIn: 'root' })
export class SessionHandler {
constructor(private oAuthService: OAuthService, environmentService: EnvironmentService) {
environmentService
.getEnvironment$()
.pipe(
filter(env => env && JSON.stringify(env) !== '{}'),
take(1),
)
.subscribe(environment => {
if (environment.oAuthConfig.responseType === 'code') return;
this.init();
});
}
private init() {
this.oAuthService.events.subscribe(event => {
if (event.type === 'logout') {
this.removeRememberInfo();
}
});
if (!getCookieValueByName('rememberMe') && localStorage.getItem(storageKey)) {
this.oAuthService.logOut();
}
}
setRememberInfo(remember: boolean) {
this.removeRememberInfo();
localStorage.setItem(storageKey, 'true');
const expiration = new Date(this.oAuthService.getAccessTokenExpiration()).toUTCString();
document.cookie = `${cookieKey}=true${remember ? `;expires=${expiration}` : ''}`;
}
removeRememberInfo() {
localStorage.removeItem(storageKey);
document.cookie = cookieKey + '= ; expires = Thu, 01 Jan 1970 00:00:00 GMT';
}
}
function getCookieValueByName(name: string) {
var match = document.cookie.match(new RegExp('(^| )' + name + '=([^;]+)'));
return match ? match[2] : '';
}

1
npm/ng-packs/packages/account/config/src/public-api.ts

@ -1,4 +1,3 @@
export * from './account-config.module';
export * from './enums';
export * from './providers';
export * from './handlers';

Loading…
Cancel
Save