Skip to content
Snippets Groups Projects
Commit c9a9ac11 authored by Callari, Roberto's avatar Callari, Roberto
Browse files

logout

parent 4199d16d
No related branches found
No related tags found
No related merge requests found
Showing
with 104 additions and 61 deletions
...@@ -26,6 +26,7 @@ ...@@ -26,6 +26,7 @@
[matRippleUnbounded]="true" [matRippleUnbounded]="true"
[matRippleCentered]="true"> [matRippleCentered]="true">
<nb-user [nbContextMenu]="userMenu" <nb-user [nbContextMenu]="userMenu"
nbContextMenuTag="user-menu"
[onlyPicture]="userPictureOnly" [onlyPicture]="userPictureOnly"
[name]="user?.username" [name]="user?.username"
[title]="user?.role" [title]="user?.role"
......
import { Component, OnDestroy, OnInit } from '@angular/core'; import { Component, Inject, OnDestroy, OnInit } from '@angular/core';
import { NbMediaBreakpointsService, NbMenuService, NbSidebarService, NbThemeService } from '@nebular/theme'; import { NbMediaBreakpointsService, NbMenuItem, NbMenuService, NbSidebarService, NbThemeService, NB_WINDOW } from '@nebular/theme';
import { LayoutService } from '../../../@core/utils'; import { LayoutService } from '../../../@core/utils';
import { map, takeUntil } from 'rxjs/operators'; import { filter, map, takeUntil } from 'rxjs/operators';
import { Subject, Observable } from 'rxjs'; import { Subject, Observable } from 'rxjs';
import { RippleService } from '../../../@core/utils/ripple.service'; import { RippleService } from '../../../@core/utils/ripple.service';
import { UserInformationService } from '../../../oauth/services/user-information.service'; import { UserInformationService } from '../../../oauth/services/user-information.service';
import { IDMUser } from '../../../oauth/model/idmuser'; import { IDMUser } from '../../../oauth/model/idmuser';
import { NbAuthService } from '@nebular/auth';
import { Router } from '@angular/router';
@Component({ @Component({
selector: 'ngx-header', selector: 'ngx-header',
...@@ -22,7 +24,7 @@ export class HeaderComponent implements OnInit, OnDestroy { ...@@ -22,7 +24,7 @@ export class HeaderComponent implements OnInit, OnDestroy {
currentTheme = 'default'; currentTheme = 'default';
userMenu = [ { title: 'Profile' }, { title: 'Log out' } ]; userMenu:NbMenuItem[] = [ { title: 'Profile', hidden:true }, { title: 'Log out', data:{tag:"logout"} } ];
public constructor( public constructor(
private sidebarService: NbSidebarService, private sidebarService: NbSidebarService,
...@@ -32,6 +34,7 @@ export class HeaderComponent implements OnInit, OnDestroy { ...@@ -32,6 +34,7 @@ export class HeaderComponent implements OnInit, OnDestroy {
private layoutService: LayoutService, private layoutService: LayoutService,
private breakpointService: NbMediaBreakpointsService, private breakpointService: NbMediaBreakpointsService,
private rippleService: RippleService, private rippleService: RippleService,
@Inject(NB_WINDOW) private window
) { ) {
this.materialTheme$ = this.themeService.onThemeChange() this.materialTheme$ = this.themeService.onThemeChange()
.pipe(map(theme => { .pipe(map(theme => {
...@@ -64,6 +67,17 @@ export class HeaderComponent implements OnInit, OnDestroy { ...@@ -64,6 +67,17 @@ export class HeaderComponent implements OnInit, OnDestroy {
this.currentTheme = themeName; this.currentTheme = themeName;
this.rippleService.toggle(themeName?.startsWith('material')); this.rippleService.toggle(themeName?.startsWith('material'));
}); });
this.menuService.onItemClick()
.pipe(
filter(({ tag }) => tag === 'user-menu'),
map(({ item: { data } }) => data),
)
.subscribe(res=>{
if(res["tag"]=="logout"){
window.open(this.userService.getLogoutUrl(),'_self');
}
});
} }
ngOnDestroy() { ngOnDestroy() {
......
...@@ -4,6 +4,7 @@ import { NbAuthComponent } from '@nebular/auth'; ...@@ -4,6 +4,7 @@ import { NbAuthComponent } from '@nebular/auth';
import { NbOAuth2LoginComponent } from './oauth/nb-oauth2-login/nb-oauth2-login.component'; import { NbOAuth2LoginComponent } from './oauth/nb-oauth2-login/nb-oauth2-login.component';
import { NbOAuth2CallbackComponent } from './oauth/nb-oauth2-callback/nb-oauth2-callback.component'; import { NbOAuth2CallbackComponent } from './oauth/nb-oauth2-callback/nb-oauth2-callback.component';
import { AuthGuard } from './oauth/services/auth.guard'; import { AuthGuard } from './oauth/services/auth.guard';
import { NbOauth2LogoutComponent } from './oauth/nb-oauth2-logout/nb-oauth2-logout.component';
export const routes: Routes = [ export const routes: Routes = [
{ {
...@@ -23,6 +24,10 @@ export const routes: Routes = [ ...@@ -23,6 +24,10 @@ export const routes: Routes = [
{ {
path: 'callback', path: 'callback',
component: NbOAuth2CallbackComponent, component: NbOAuth2CallbackComponent,
},
{
path: 'logout',
component: NbOauth2LogoutComponent,
} }
], ],
}, },
......
...@@ -28,6 +28,7 @@ import { NbRoleProvider, NbSecurityModule } from '@nebular/security'; ...@@ -28,6 +28,7 @@ import { NbRoleProvider, NbSecurityModule } from '@nebular/security';
import { UserInformationService } from './oauth/services/user-information.service'; import { UserInformationService } from './oauth/services/user-information.service';
import { TokenInterceptor } from './oauth/services/token.interceptor'; import { TokenInterceptor } from './oauth/services/token.interceptor';
import { AuthGuard } from './oauth/services/auth.guard'; import { AuthGuard } from './oauth/services/auth.guard';
import { NbOauth2LogoutComponent } from './oauth/nb-oauth2-logout/nb-oauth2-logout.component';
export function configFactory(http: HttpClient): ConfigLoader { export function configFactory(http: HttpClient): ConfigLoader {
return new ConfigHttpLoader(http, './assets/config.json'); return new ConfigHttpLoader(http, './assets/config.json');
...@@ -38,7 +39,7 @@ export function createTranslateLoader(http: HttpClient) { ...@@ -38,7 +39,7 @@ export function createTranslateLoader(http: HttpClient) {
} }
@NgModule({ @NgModule({
declarations: [AppComponent], declarations: [AppComponent, NbOauth2LogoutComponent],
imports: [ imports: [
BrowserModule, BrowserModule,
BrowserAnimationsModule, BrowserAnimationsModule,
......
<p>nb-oauth2-callback works!</p>
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
import { NbOAuth2CallbackComponent } from './nb-oauth2-callback.component';
describe('NbOAuth2CallbackComponent', () => {
let component: NbOAuth2CallbackComponent;
let fixture: ComponentFixture<NbOAuth2CallbackComponent>;
beforeEach(async(() => {
TestBed.configureTestingModule({
declarations: [ NbOAuth2CallbackComponent ]
})
.compileComponents();
}));
beforeEach(() => {
fixture = TestBed.createComponent(NbOAuth2CallbackComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});
it('should create', () => {
expect(component).toBeTruthy();
});
});
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
import { NbOAuth2LoginComponent } from './nb-oauth2-login.component';
describe('NbOAuth2LoginComponent', () => {
let component: NbOAuth2LoginComponent;
let fixture: ComponentFixture<NbOAuth2LoginComponent>;
beforeEach(async(() => {
TestBed.configureTestingModule({
declarations: [ NbOAuth2LoginComponent ]
})
.compileComponents();
}));
beforeEach(() => {
fixture = TestBed.createComponent(NbOAuth2LoginComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});
it('should create', () => {
expect(component).toBeTruthy();
});
});
import { Component, OnDestroy, OnInit } from '@angular/core';
import { Router } from '@angular/router';
import { NbAuthResult, NbAuthService } from '@nebular/auth';
import { Subject } from 'rxjs';
import { takeUntil } from 'rxjs/operators';
@Component({
selector: 'ngx-nb-oauth2-logout',
template: ``
})
export class NbOauth2LogoutComponent implements OnDestroy {
private destroy$ = new Subject<void>();
constructor(private authService: NbAuthService, private router: Router) {
this.authService.logout('idm')
.pipe(takeUntil(this.destroy$))
.subscribe((authResult: NbAuthResult) => {
if (authResult.isSuccess()) {
this.router.navigateByUrl('/auth')
}else{
this.router.navigateByUrl('');
}
},(error)=>{
console.log(error)
});
}
ngOnDestroy(): void {
this.destroy$.next();
this.destroy$.complete();
}
}
...@@ -10,10 +10,11 @@ import { map } from 'rxjs/operators'; ...@@ -10,10 +10,11 @@ import { map } from 'rxjs/operators';
providedIn: 'root' providedIn: 'root'
}) })
export class UserInformationService { export class UserInformationService {
apiURL: any; apiURL: string;
client_id:string;
constructor(configService: ConfigService, private http: HttpClient) { constructor(configService: ConfigService, private http: HttpClient) {
this.apiURL = configService.getSettings("idmBaseURL"); this.apiURL = configService.getSettings("idmBaseURL");
this.client_id = configService.getSettings("client_id");
} }
getRole(): Observable<string[]> { getRole(): Observable<string[]> {
...@@ -34,4 +35,7 @@ export class UserInformationService { ...@@ -34,4 +35,7 @@ export class UserInformationService {
return this.http.get<IDMUser>(`${this.apiURL}/user`); return this.http.get<IDMUser>(`${this.apiURL}/user`);
} }
getLogoutUrl():string{
return `${this.apiURL}/auth/external_logout?_method=DELETE&client_id=${this.client_id}`;
}
} }
import { Component, OnInit } from '@angular/core'; import { Component, OnInit } from '@angular/core';
import { NbAccessChecker } from '@nebular/security';
import { OwlOptions } from 'ngx-owl-carousel-o'; import { OwlOptions } from 'ngx-owl-carousel-o';
@Component({ @Component({
......
import { Component } from '@angular/core'; import { Component, OnInit } from '@angular/core';
import { NbAccessChecker } from '@nebular/security';
import { NbMenuItem } from '@nebular/theme';
import { UserInformationService } from '../oauth/services/user-information.service';
import { MENU_ITEMS } from './pages-menu'; import { MENU_ITEMS } from './pages-menu';
...@@ -12,7 +15,37 @@ import { MENU_ITEMS } from './pages-menu'; ...@@ -12,7 +15,37 @@ import { MENU_ITEMS } from './pages-menu';
</ngx-one-column-layout> </ngx-one-column-layout>
`, `,
}) })
export class PagesComponent { export class PagesComponent implements OnInit{
menu = MENU_ITEMS; menu = MENU_ITEMS;
userRoles: string[];
constructor(
private accessChecker: NbAccessChecker) {
}
ngOnInit() {
this.authMenuItems();
}
authMenuItems() {
this.menu.forEach(item => {
this.authMenuItem(item);
});
}
authMenuItem(menuItem: NbMenuItem) {
if(menuItem.data && menuItem.data['name']) {
this.accessChecker.isGranted('view',menuItem.data['name']).subscribe(res =>
menuItem.hidden=!res
)
} else {
menuItem.hidden = true;
}
if (!menuItem.hidden && menuItem.children != null) {
menuItem.children.forEach(item => {
item.hidden = menuItem.hidden;
});
}
}
} }
{ "idmBaseURL":"http://192.168.99.100:3000", { "idmBaseURL":"http://192.168.99.100:3000",
"client_id":"d3f0bbb0-6846-446a-bce4-2755ad9adcd2",
"client_secret":"",
"external-application-cards":[ "external-application-cards":[
{ {
"url": "http://217.172.12.141:8080", "url": "http://217.172.12.141:8080",
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment