Commit ec1715e2 authored by Lukas Burgey's avatar Lukas Burgey

Implement user deletion

parent d6b72c4f
<p>
You can delete your account. All deployments will be withdrawn if you chose to do so.
</p>
<p>
<mat-checkbox [(ngModel)]="sure"
style="margin-right: 8px"
[checked]="sure">
I'm sure i want to delete all my data on the server.
</mat-checkbox>
<button mat-raised-button mat-dialog-close color="primary" (click)="delete()" [disabled]="!sure">Delete</button>
</p>
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
import { AccountComponent } from './account.component';
describe('AccountComponent', () => {
let component: AccountComponent;
let fixture: ComponentFixture<AccountComponent>;
beforeEach(async(() => {
TestBed.configureTestingModule({
declarations: [ AccountComponent ]
})
.compileComponents();
}));
beforeEach(() => {
fixture = TestBed.createComponent(AccountComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});
it('should create', () => {
expect(component).toBeTruthy();
});
});
import { Component, OnInit } from '@angular/core';
import { UserService } from '../user.service';
@Component({
selector: 'app-account',
templateUrl: './account.component.html',
styleUrls: ['./account.component.css']
})
export class AccountComponent implements OnInit {
public sure: boolean;
constructor(
public userService: UserService,
) {
this.sure = false;
}
ngOnInit() {
}
delete() {
this.userService.deleteUser();
}
}
...@@ -33,6 +33,7 @@ import { LoginComponent } from './login/login.component'; ...@@ -33,6 +33,7 @@ import { LoginComponent } from './login/login.component';
import { ProfileComponent } from './profile/profile.component'; import { ProfileComponent } from './profile/profile.component';
import { ServiceComponent } from './service/service.component'; import { ServiceComponent } from './service/service.component';
import { SshKeysComponent } from './ssh-keys/ssh-keys.component'; import { SshKeysComponent } from './ssh-keys/ssh-keys.component';
import { AccountComponent } from './account/account.component';
/* /*
const routes = [ const routes = [
...@@ -55,6 +56,7 @@ const routes = [ ...@@ -55,6 +56,7 @@ const routes = [
ProfileComponent, ProfileComponent,
ServiceComponent, ServiceComponent,
SshKeysComponent, SshKeysComponent,
AccountComponent,
], ],
imports: [ imports: [
BrowserModule, BrowserModule,
...@@ -95,6 +97,7 @@ const routes = [ ...@@ -95,6 +97,7 @@ const routes = [
entryComponents: [ entryComponents: [
ProfileComponent, ProfileComponent,
SshKeysComponent, SshKeysComponent,
AccountComponent,
], ],
}) })
export class AppModule { export class AppModule {
......
...@@ -3,11 +3,17 @@ import { MatDialog, MatDialogRef } from '@angular/material/dialog'; ...@@ -3,11 +3,17 @@ import { MatDialog, MatDialogRef } from '@angular/material/dialog';
import { ProfileComponent } from './profile/profile.component'; import { ProfileComponent } from './profile/profile.component';
import { SshKeysComponent } from './ssh-keys/ssh-keys.component'; import { SshKeysComponent } from './ssh-keys/ssh-keys.component';
import { AccountComponent } from './account/account.component';
@Injectable() @Injectable()
export class DialogService { export class DialogService {
profileDialog: MatDialogRef<any>; profileDialog: MatDialogRef<any>;
sshKeysDialog: MatDialogRef<any>; sshKeysDialog: MatDialogRef<any>;
accountDialog: MatDialogRef<any>;
settings = {
width: '80%',
};
constructor( constructor(
public dialog: MatDialog, public dialog: MatDialog,
...@@ -16,19 +22,21 @@ export class DialogService { ...@@ -16,19 +22,21 @@ export class DialogService {
public openProfile() { public openProfile() {
this.profileDialog = this.dialog.open( this.profileDialog = this.dialog.open(
ProfileComponent, ProfileComponent,
{ this.settings,
width: '80%',
}
); );
} }
public openSshKeys() { public openSshKeys() {
this.sshKeysDialog = this.dialog.open( this.sshKeysDialog = this.dialog.open(
SshKeysComponent, SshKeysComponent,
{ this.settings,
width: '80%',
}
); );
} }
public openAccount() {
this.accountDialog = this.dialog.open(
AccountComponent,
this.settings,
);
}
} }
...@@ -12,6 +12,9 @@ ...@@ -12,6 +12,9 @@
</form> </form>
</span> </span>
<span *ngIf="userService.loggedIn"> <span *ngIf="userService.loggedIn">
<button mat-button mat-icon-button (click)="dialog.openAccount()">
<mat-icon>settings</mat-icon>
</button>
<button mat-button mat-icon-button (click)="dialog.openSshKeys()"> <button mat-button mat-icon-button (click)="dialog.openSshKeys()">
<mat-icon>vpn_key</mat-icon> <mat-icon>vpn_key</mat-icon>
</button> </button>
......
...@@ -210,4 +210,18 @@ export class UserService { ...@@ -210,4 +210,18 @@ export class UserService {
} }
); );
} }
public deleteUser() {
return this.http.delete('/backend/api/delete_user/').subscribe(
(data) => {
this.snackBar.open('Deleted user from server');
this.updateData(data);
},
(err) => {
this.snackBar.open('Error deleting user from server');
console.log(err);
this.update();
}
);
}
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment