mirror of
https://github.com/GNS3/gns3-web-ui.git
synced 2025-05-29 13:34:20 +00:00
Add possibility for a user to change his/her password. Ref https://github.com/GNS3/gns3-gui/issues/3698
This commit is contained in:
parent
6b28370111
commit
050d4158ed
@ -67,7 +67,7 @@ export class EditUserDialogComponent implements OnInit {
|
|||||||
|
|
||||||
updatedUser.user_id = this.data.user.user_id;
|
updatedUser.user_id = this.data.user.user_id;
|
||||||
console.log(updatedUser)
|
console.log(updatedUser)
|
||||||
this.userService.update(this.data.controller, updatedUser)
|
this.userService.update(this.data.controller, updatedUser, false)
|
||||||
.subscribe((user: User) => {
|
.subscribe((user: User) => {
|
||||||
console.log("Done ", user)
|
console.log("Done ", user)
|
||||||
this.toasterService.success(`User ${user.username} updated`);
|
this.toasterService.success(`User ${user.username} updated`);
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
<h1 mat-dialog-title>Change password for user : </h1>
|
<h1 mat-dialog-title>Change password for {{ user.username }}</h1>
|
||||||
<div>
|
<div>
|
||||||
<form [formGroup]="editPasswordForm" class="input-field">
|
<form [formGroup]="editPasswordForm" class="input-field">
|
||||||
<mat-form-field class="input-field">
|
<mat-form-field class="input-field">
|
||||||
|
@ -18,7 +18,7 @@ export class ChangeUserPasswordComponent implements OnInit {
|
|||||||
user: User;
|
user: User;
|
||||||
|
|
||||||
constructor(private dialogRef: MatDialogRef<ChangeUserPasswordComponent>,
|
constructor(private dialogRef: MatDialogRef<ChangeUserPasswordComponent>,
|
||||||
@Inject(MAT_DIALOG_DATA) public data: { user: User, controller: Controller },
|
@Inject(MAT_DIALOG_DATA) public data: { user: User, controller: Controller, self_update: boolean },
|
||||||
private userService: UserService,
|
private userService: UserService,
|
||||||
private toasterService: ToasterService) { }
|
private toasterService: ToasterService) { }
|
||||||
|
|
||||||
@ -52,16 +52,14 @@ export class ChangeUserPasswordComponent implements OnInit {
|
|||||||
updatedUser['password'] = this.editPasswordForm.get('password').value;
|
updatedUser['password'] = this.editPasswordForm.get('password').value;
|
||||||
updatedUser['user_id'] = this.user.user_id;
|
updatedUser['user_id'] = this.user.user_id;
|
||||||
|
|
||||||
console.log(updatedUser);
|
this.userService.update(this.data.controller, updatedUser, this.data.self_update)
|
||||||
|
|
||||||
this.userService.update(this.data.controller, updatedUser)
|
|
||||||
.subscribe((user: User) => {
|
.subscribe((user: User) => {
|
||||||
this.toasterService.success(`User ${user.username} password updated`);
|
this.toasterService.success(`User ${user.username} password updated`);
|
||||||
this.editPasswordForm.reset();
|
this.editPasswordForm.reset();
|
||||||
this.dialogRef.close(true);
|
this.dialogRef.close(true);
|
||||||
},
|
},
|
||||||
(error) => {
|
(error) => {
|
||||||
this.toasterService.error('Cannot update password for user : ' + error);
|
this.toasterService.error('Cannot update password for user: ' + error);
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -96,7 +96,7 @@ export class UserDetailComponent implements OnInit {
|
|||||||
const updatedUser = this.getUpdatedValues();
|
const updatedUser = this.getUpdatedValues();
|
||||||
updatedUser['user_id'] = this.user.user_id;
|
updatedUser['user_id'] = this.user.user_id;
|
||||||
|
|
||||||
this.userService.update(this.controller, updatedUser)
|
this.userService.update(this.controller, updatedUser, false)
|
||||||
.subscribe((user: User) => {
|
.subscribe((user: User) => {
|
||||||
this.toasterService.success(`User ${user.username} updated`);
|
this.toasterService.success(`User ${user.username} updated`);
|
||||||
},
|
},
|
||||||
|
@ -7,11 +7,13 @@
|
|||||||
<div class="default-content">
|
<div class="default-content">
|
||||||
<mat-card *ngIf="user">
|
<mat-card *ngIf="user">
|
||||||
<mat-list>
|
<mat-list>
|
||||||
<mat-list-item> Username: {{user.username}} </mat-list-item>
|
<mat-list-item> Username: {{ user.username }} </mat-list-item>
|
||||||
<mat-list-item> Full name: {{user.full_name}} </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-item> Email: {{ user.email }} </mat-list-item>
|
||||||
</mat-list>
|
</mat-list>
|
||||||
|
<div class="buttons-bar">
|
||||||
|
<button mat-raised-button color="primary" class="full_width" (click)="changePassword()">Change password</button><br />
|
||||||
|
</div>
|
||||||
<div class="buttons-bar">
|
<div class="buttons-bar">
|
||||||
<button mat-raised-button color="primary" class="full_width" (click)="copyToken()">Click to copy access token</button><br />
|
<button mat-raised-button color="primary" class="full_width" (click)="copyToken()">Click to copy access token</button><br />
|
||||||
</div>
|
</div>
|
||||||
|
@ -5,6 +5,8 @@ import { UserService } from '../../../services/user.service';
|
|||||||
import { ToasterService } from '../../../services/toaster.service';
|
import { ToasterService } from '../../../services/toaster.service';
|
||||||
import { User } from '../../../models/users/user';
|
import { User } from '../../../models/users/user';
|
||||||
import { Controller } from '../../../models/controller';
|
import { Controller } from '../../../models/controller';
|
||||||
|
import { ChangeUserPasswordComponent } from "@components/user-management/user-detail/change-user-password/change-user-password.component";
|
||||||
|
import { MatDialog } from "@angular/material/dialog";
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
selector: 'app-logged-user',
|
selector: 'app-logged-user',
|
||||||
@ -19,7 +21,8 @@ export class LoggedUserComponent implements OnInit {
|
|||||||
private route: ActivatedRoute,
|
private route: ActivatedRoute,
|
||||||
private controllerService: ControllerService,
|
private controllerService: ControllerService,
|
||||||
private userService: UserService,
|
private userService: UserService,
|
||||||
private toasterService: ToasterService
|
private toasterService: ToasterService,
|
||||||
|
public dialog: MatDialog
|
||||||
) {}
|
) {}
|
||||||
|
|
||||||
ngOnInit() {
|
ngOnInit() {
|
||||||
@ -32,6 +35,11 @@ export class LoggedUserComponent implements OnInit {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
changePassword() {
|
||||||
|
this.dialog.open<ChangeUserPasswordComponent>(ChangeUserPasswordComponent,
|
||||||
|
{width: '400px', height: '300px', data: {user: this.user, controller: this.controller, self_update: true}});
|
||||||
|
}
|
||||||
|
|
||||||
copyToken() {
|
copyToken() {
|
||||||
const selBox = document.createElement('textarea');
|
const selBox = document.createElement('textarea');
|
||||||
selBox.style.position = 'fixed';
|
selBox.style.position = 'fixed';
|
||||||
|
@ -5,6 +5,7 @@ import { Controller } from '../models/controller';
|
|||||||
import { HttpController } from './http-controller.service';
|
import { HttpController } from './http-controller.service';
|
||||||
import { User } from '../models/users/user';
|
import { User } from '../models/users/user';
|
||||||
import { Group } from "@models/groups/group";
|
import { Group } from "@models/groups/group";
|
||||||
|
import {Image} from "@models/images";
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class UserService {
|
export class UserService {
|
||||||
@ -32,7 +33,10 @@ export class UserService {
|
|||||||
return this.httpController.delete(controller, `/access/users/${user_id}`);
|
return this.httpController.delete(controller, `/access/users/${user_id}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
update(controller: Controller, user: any): Observable<User> {
|
update(controller: Controller, user: any, self_update: boolean): Observable<User> {
|
||||||
|
if (self_update) {
|
||||||
|
return this.httpController.put<User>(controller, `/access/users/me`, user);
|
||||||
|
}
|
||||||
return this.httpController.put<User>(controller, `/access/users/${user.user_id}`, user);
|
return this.httpController.put<User>(controller, `/access/users/${user.user_id}`, user);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user