Commit a9efdeae authored by Priyanka Vivekanand Upadhye's avatar Priyanka Vivekanand Upadhye
Browse files

Merge branch '67-deactivate-user-api-integration' into 'master'

Account deactivation API integrated

Closes #67

See merge request 92khra1mst/hft_awado_app!59
parents 0cb53260 ccd07189
import { Component, OnInit } from '@angular/core'; import { Component, OnInit } from '@angular/core';
import { Router, LoadChildrenCallback } from '@angular/router'; import { Router, LoadChildrenCallback } from '@angular/router';
import { ToastService } from '../services/toast.service'; 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({ @Component({
selector: 'app-settings', selector: 'app-settings',
templateUrl: './settings.page.html', templateUrl: './settings.page.html',
...@@ -8,15 +13,56 @@ import { ToastService } from '../services/toast.service'; ...@@ -8,15 +13,56 @@ import { ToastService } from '../services/toast.service';
}) })
export class SettingsPage implements OnInit { 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() { ngOnInit() {
} }
ChangePassword() { ChangePassword() {
this.router.navigateByUrl('/reset-password'); this.router.navigateByUrl('/reset-password');
} }
DeactivateUser(){ async DeactivateUser(){
this.toastService.showToast("Account Deactivated Sucessfully"); const alert = await this.alertController.create({
this.router.navigateByUrl('/logout'); header: 'Deactivation!',
message: '<strong>Do you really want to deactivate your account</strong>?',
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();
} }
} }
Supports Markdown
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