From 823e9a4b5904a540c7df71e5933d90eb814073e1 Mon Sep 17 00:00:00 2001
From: piotrpekala7 <31202938+piotrpekala7@users.noreply.github.com>
Date: Mon, 17 May 2021 15:12:57 +0200
Subject: [PATCH] https://github.com/GNS3/gns3-web-ui/issues/1143
---
src/app/app-routing.module.ts | 2 +
src/app/app.module.ts | 6 ++-
.../logged-user/logged-user.component.html | 20 ++++++++
.../logged-user/logged-user.component.scss | 3 ++
.../logged-user/logged-user.component.spec.ts | 0
.../logged-user/logged-user.component.ts | 50 +++++++++++++++++++
.../default-layout.component.html | 4 ++
.../default-layout.component.ts | 11 +++-
src/app/models/users/user.ts | 10 ++++
src/app/services/user.service.ts | 16 ++++++
10 files changed, 120 insertions(+), 2 deletions(-)
create mode 100644 src/app/components/users/logged-user/logged-user.component.html
create mode 100644 src/app/components/users/logged-user/logged-user.component.scss
create mode 100644 src/app/components/users/logged-user/logged-user.component.spec.ts
create mode 100644 src/app/components/users/logged-user/logged-user.component.ts
create mode 100644 src/app/models/users/user.ts
create mode 100644 src/app/services/user.service.ts
diff --git a/src/app/app-routing.module.ts b/src/app/app-routing.module.ts
index 7edf8dc4..0e73f12c 100644
--- a/src/app/app-routing.module.ts
+++ b/src/app/app-routing.module.ts
@@ -56,6 +56,7 @@ import { ConsoleGuard } from './guards/console-guard';
import { LoginGuard } from './guards/login-guard';
import { DefaultLayoutComponent } from './layouts/default-layout/default-layout.component';
import { ServerResolve } from './resolvers/server-resolve';
+import { LoggedUserComponent } from './components/users/logged-user/logged-user.component';
const routes: Routes = [
{
@@ -66,6 +67,7 @@ const routes: Routes = [
{ path: 'servers', component: ServersComponent },
{ path: 'bundled', component: BundledServerFinderComponent },
{ path: 'server/:server_id/login', component: LoginComponent },
+ { path: 'server/:server_id/loggeduser', component: LoggedUserComponent },
{
path: 'server/:server_id/projects',
component: ProjectsComponent,
diff --git a/src/app/app.module.ts b/src/app/app.module.ts
index 89ffa0a0..17cce65c 100644
--- a/src/app/app.module.ts
+++ b/src/app/app.module.ts
@@ -274,10 +274,13 @@ import { MarkedDirective } from './directives/marked.directive';
import { LoginComponent } from './components/login/login.component';
import { LoginService } from './services/login.service';
import { HttpRequestsInterceptor } from './interceptors/http.interceptor';
+import { UserService } from './services/user.service';
+import { LoggedUserComponent } from './components/users/logged-user/logged-user.component';
@NgModule({
declarations: [
AppComponent,
+ LoggedUserComponent,
ProjectMapComponent,
LoginComponent,
ServersComponent,
@@ -558,7 +561,8 @@ import { HttpRequestsInterceptor } from './interceptors/http.interceptor';
Title,
ApplianceService,
UpdatesService,
- LoginService
+ LoginService,
+ UserService
],
entryComponents: [
AddServerDialogComponent,
diff --git a/src/app/components/users/logged-user/logged-user.component.html b/src/app/components/users/logged-user/logged-user.component.html
new file mode 100644
index 00000000..de49f6e7
--- /dev/null
+++ b/src/app/components/users/logged-user/logged-user.component.html
@@ -0,0 +1,20 @@
+
+
+
+
+
+ Username: {{user.username}}
+ Full name: {{user.full_name}}
+ Email: {{user.email}}
+
+
+
+
+
+
+
+
diff --git a/src/app/components/users/logged-user/logged-user.component.scss b/src/app/components/users/logged-user/logged-user.component.scss
new file mode 100644
index 00000000..e9958114
--- /dev/null
+++ b/src/app/components/users/logged-user/logged-user.component.scss
@@ -0,0 +1,3 @@
+.full_width {
+ width: 100%;
+}
diff --git a/src/app/components/users/logged-user/logged-user.component.spec.ts b/src/app/components/users/logged-user/logged-user.component.spec.ts
new file mode 100644
index 00000000..e69de29b
diff --git a/src/app/components/users/logged-user/logged-user.component.ts b/src/app/components/users/logged-user/logged-user.component.ts
new file mode 100644
index 00000000..e8b79ab4
--- /dev/null
+++ b/src/app/components/users/logged-user/logged-user.component.ts
@@ -0,0 +1,50 @@
+import { Component, OnInit } from '@angular/core';
+import { ActivatedRoute } from '@angular/router';
+import { ServerService } from '../../../services/server.service';
+import { UserService } from '../../../services/user.service';
+import { ToasterService } from '../../../services/toaster.service';
+import { User } from '../../../models/users/user';
+import { Server } from '../../../models/server';
+
+@Component({
+ selector: 'app-logged-user',
+ templateUrl: './logged-user.component.html',
+ styleUrls: ['./logged-user.component.scss'],
+})
+export class LoggedUserComponent implements OnInit {
+ public user: User;
+ public server: Server;
+
+ constructor(
+ private route: ActivatedRoute,
+ private serverService: ServerService,
+ private userService: UserService,
+ private toasterService: ToasterService
+ ) {}
+
+ ngOnInit() {
+ let serverId = this.route.snapshot.paramMap.get('server_id');
+ this.serverService.get(+serverId).then((server: Server) => {
+ this.server = server;
+ this.userService.getInformationAboutLoggedUser(server).subscribe((response: any) => {
+ this.user = response;
+ });
+ });
+ }
+
+ copyToken() {
+ const selBox = document.createElement('textarea');
+ selBox.style.position = 'fixed';
+ selBox.style.left = '0';
+ selBox.style.top = '0';
+ selBox.style.opacity = '0';
+ selBox.value = this.server.authToken;
+ document.body.appendChild(selBox);
+ selBox.focus();
+ selBox.select();
+ document.execCommand('copy');
+ document.body.removeChild(selBox);
+
+ this.toasterService.success('Token copied');
+ }
+}
diff --git a/src/app/layouts/default-layout/default-layout.component.html b/src/app/layouts/default-layout/default-layout.component.html
index 1bdb062a..a995ee4e 100644
--- a/src/app/layouts/default-layout/default-layout.component.html
+++ b/src/app/layouts/default-layout/default-layout.component.html
@@ -31,6 +31,10 @@
help
Help
+