added call to marketplace user endpoint and pass the results to the globalnav library.

pull/1/head
Chris Veilleux 2018-11-15 16:16:47 -06:00
parent ced5cca325
commit d87250a233
4 changed files with 50 additions and 3 deletions

View File

@ -1,4 +1,7 @@
<globalnav-sidenav [environment]="environment">
<globalnav-sidenav
[mycroftUrls]="environment.mycroftUrls"
[userName]="userName"
>
<!--
Inject the marketplace app into the <mat-sidenav-content> component
of the global navigation menu library.

View File

@ -1,5 +1,6 @@
import { Component, OnInit } from '@angular/core';
import { AppService } from './app.service';
import { environment } from '../environments/environment';
@Component({
@ -9,10 +10,22 @@ import { environment } from '../environments/environment';
})
export class AppComponent implements OnInit {
public environment = environment;
public userName = '';
constructor() {
constructor(private service: AppService) {
}
ngOnInit() {
this.service.setLoginStatus();
this.getUser();
}
getUser() {
if (this.service.isLoggedIn) {
this.service.getUser().subscribe(
(user) => { this.userName = user.name; }
);
}
}
}

View File

@ -5,6 +5,7 @@ import { NgModule } from '@angular/core';
import { AppRoutingModule } from './app-routing.module';
import { AppComponent } from './app.component';
import { AppService } from './app.service';
import { GlobalnavModule } from 'globalnav';
import { MaterialModule } from './shared/material.module';
import { SkillsModule } from './skills/skills.module';
@ -22,7 +23,7 @@ import { PageNotFoundComponent } from './page-not-found/page-not-found.component
SkillsModule,
AppRoutingModule
],
providers: [ ],
providers: [ AppService ],
bootstrap: [ AppComponent ]
}
)

View File

@ -0,0 +1,30 @@
import { HttpClient } from '@angular/common/http';
import { Injectable } from '@angular/core';
import { Observable } from 'rxjs';
const userUrl = '/api/user';
@Injectable({
providedIn: 'root'
})
export class AppService {
public isLoggedIn: boolean;
constructor(private http: HttpClient) {
}
/**
* API call to retrieve user info to display.
*/
getUser(): Observable<any> {
return this.http.get<any>(userUrl);
}
setLoginStatus(): void {
const cookies = document.cookie;
const seleneTokenExists = cookies.includes('seleneToken');
const seleneTokenEmpty = cookies.includes('seleneToken=""');
this.isLoggedIn = seleneTokenExists && !seleneTokenEmpty;
}
}