From ccd071893bc61e7ba9b37cc877bd4e01b2fec255 Mon Sep 17 00:00:00 2001 From: Priyanka Upadhye <92uppr1mst@hft-stuttgart.de> Date: Mon, 6 Jan 2020 17:09:13 +0100 Subject: [PATCH] Account deactivation API integrated --- src/app/settings/settings.page.ts | 54 ++++++++++++++++++++++++++++--- 1 file changed, 50 insertions(+), 4 deletions(-) diff --git a/src/app/settings/settings.page.ts b/src/app/settings/settings.page.ts index f8fa8c0..0414735 100644 --- a/src/app/settings/settings.page.ts +++ b/src/app/settings/settings.page.ts @@ -1,6 +1,11 @@ import { Component, OnInit } from '@angular/core'; import { Router, LoadChildrenCallback } from '@angular/router'; import { ToastService } from '../services/toast.service'; +import { AlertController } from '@ionic/angular'; +import { RestService } from '../rest.service'; +import { Observable, Subject } from 'rxjs'; +import { HttpClient, HttpHeaders } from '@angular/common/http'; +import { Storage } from '@ionic/storage'; @Component({ selector: 'app-settings', templateUrl: './settings.page.html', @@ -8,15 +13,56 @@ import { ToastService } from '../services/toast.service'; }) export class SettingsPage implements OnInit { - constructor(private router: Router,private toastService: ToastService) { } + constructor(private router: Router,private toastService: ToastService,public alertController: AlertController, + public restService: RestService, + public httpClient: HttpClient, + private storage: Storage,) { } ngOnInit() { } ChangePassword() { this.router.navigateByUrl('/reset-password'); } - DeactivateUser(){ - this.toastService.showToast("Account Deactivated Sucessfully"); - this.router.navigateByUrl('/logout'); + async DeactivateUser(){ + const alert = await this.alertController.create({ + header: 'Deactivation!', + message: 'Do you really want to deactivate your account?', + buttons: [ + { + text: 'Not Now', + role: 'cancel', + cssClass: 'secondary', + handler: (blah) => { + console.log('Confirm Cancel: blah'); + this.router.navigateByUrl('/settings'); + } + }, { + text: 'Yes', + handler: () => { + console.log('Confirm Okay'); + this.storage.get('token').then((token) => { + let url = 'http://193.196.52.237:8081/deactivate-account'; + const headers = new HttpHeaders().set("Authorization", "Bearer " + token); + let deactivateApi = this.httpClient.delete(url, { headers }); + deactivateApi.subscribe((resp:any) => { + console.log('my data: ', resp); + this.router.navigateByUrl('/login'); + this.toastService.showToast("User account has been deactivated!"); + + }, (error) => { + console.log(error); + + }); + }); + + + } + } + ] + }); + + await alert.present(); + + } } -- GitLab