mirror of
https://github.com/GNS3/gns3-web-ui.git
synced 2024-12-22 06:17:47 +00:00
This commit is contained in:
parent
eb7da2f565
commit
823e9a4b59
@ -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,
|
||||
|
@ -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,
|
||||
|
@ -0,0 +1,20 @@
|
||||
<div class="content">
|
||||
<div class="default-header">
|
||||
<div class="row">
|
||||
<h1 class="col">Logged user info</h1>
|
||||
</div>
|
||||
</div>
|
||||
<div class="default-content">
|
||||
<mat-card *ngIf="user">
|
||||
<mat-list>
|
||||
<mat-list-item> Username: {{user.username}} </mat-list-item>
|
||||
<mat-list-item> Full name: {{user.full_name}} </mat-list-item>
|
||||
<mat-list-item> Email: {{user.email}} </mat-list-item>
|
||||
</mat-list>
|
||||
|
||||
<div class="buttons-bar">
|
||||
<button mat-raised-button color="primary" class="full_width" (click)="copyToken()">Click to copy access token</button><br />
|
||||
</div>
|
||||
</mat-card>
|
||||
</div>
|
||||
</div>
|
@ -0,0 +1,3 @@
|
||||
.full_width {
|
||||
width: 100%;
|
||||
}
|
@ -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');
|
||||
}
|
||||
}
|
@ -31,6 +31,10 @@
|
||||
<mat-icon>help</mat-icon>
|
||||
<span>Help</span>
|
||||
</button>
|
||||
<button mat-menu-item (click)="goToUserInfo()">
|
||||
<mat-icon>person</mat-icon>
|
||||
<span>User info</span>
|
||||
</button>
|
||||
<button mat-menu-item (click)="logout()">
|
||||
<mat-icon>highlight_off</mat-icon>
|
||||
<span>Logout</span>
|
||||
|
@ -8,6 +8,7 @@ import { ProgressService } from '../../common/progress/progress.service';
|
||||
import { RecentlyOpenedProjectService } from '../../services/recentlyOpenedProject.service';
|
||||
import { ServerManagementService } from '../../services/server-management.service';
|
||||
import { ToasterService } from '../../services/toaster.service';
|
||||
import { UserService } from '../../services/user.service';
|
||||
import { version } from './../../version';
|
||||
import { Server } from '../../models/server';
|
||||
|
||||
@ -37,7 +38,8 @@ export class DefaultLayoutComponent implements OnInit, OnDestroy {
|
||||
private toasterService: ToasterService,
|
||||
private progressService: ProgressService,
|
||||
private router: Router,
|
||||
private serverService: ServerService
|
||||
private serverService: ServerService,
|
||||
private userService: UserService
|
||||
) {}
|
||||
|
||||
ngOnInit() {
|
||||
@ -68,6 +70,13 @@ export class DefaultLayoutComponent implements OnInit, OnDestroy {
|
||||
this.shouldStopServersOnClosing = this.electronService.isElectronApp;
|
||||
}
|
||||
|
||||
goToUserInfo() {
|
||||
let serverId = this.router.url.split("/server/")[1].split("/")[0];
|
||||
this.serverService.get(+serverId).then((server: Server) => {
|
||||
this.router.navigate(['/server', server.id, 'loggeduser']);
|
||||
});
|
||||
}
|
||||
|
||||
checkIfUserIsLoginPage() {
|
||||
if (this.router.url.includes("login")) {
|
||||
this.isLoginPage = true;
|
||||
|
10
src/app/models/users/user.ts
Normal file
10
src/app/models/users/user.ts
Normal file
@ -0,0 +1,10 @@
|
||||
export interface User {
|
||||
created_at: string;
|
||||
email: string;
|
||||
full_name: string;
|
||||
is_active: boolean;
|
||||
is_superadmin: boolean;
|
||||
updated_at: string;
|
||||
user_id: string;
|
||||
username: string;
|
||||
}
|
16
src/app/services/user.service.ts
Normal file
16
src/app/services/user.service.ts
Normal file
@ -0,0 +1,16 @@
|
||||
import { Injectable } from '@angular/core';
|
||||
import { Subject } from 'rxjs';
|
||||
import { Server } from '../models/server';
|
||||
import { HttpServer } from './http-server.service';
|
||||
import { User } from '../models/users/user';
|
||||
|
||||
@Injectable()
|
||||
export class UserService {
|
||||
constructor(
|
||||
private httpServer: HttpServer
|
||||
) {}
|
||||
|
||||
getInformationAboutLoggedUser(server: Server) {
|
||||
return this.httpServer.get<User>(server, '/users/me/');
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user