settings.page.ts 2.19 KB
Newer Older
Priyanka Upadhye's avatar
Priyanka Upadhye committed
1
2
3
import { Component, OnInit } from '@angular/core';
import { Router, LoadChildrenCallback } from '@angular/router';
import { ToastService } from '../services/toast.service';
4
5
6
7
8
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';
Priyanka Upadhye's avatar
Priyanka Upadhye committed
9
10
11
12
13
14
15
@Component({
  selector: 'app-settings',
  templateUrl: './settings.page.html',
  styleUrls: ['./settings.page.scss'],
})
export class SettingsPage implements OnInit {

16
17
18
19
  constructor(private router: Router,private toastService: ToastService,public alertController: AlertController,
    public restService: RestService,
    public httpClient: HttpClient,
    private storage: Storage,) { }
Priyanka Upadhye's avatar
Priyanka Upadhye committed
20
21
22
23
24
25

  ngOnInit() {
  }
  ChangePassword() {
    this.router.navigateByUrl('/reset-password');
  }
26
27
28
29
30
31
32
33
34
35
  async DeactivateUser(){
    const alert = await this.alertController.create({
      header: 'Deactivation!',
      message: '<strong>Do you really want to deactivate your account</strong>?',
      buttons: [
        {
          text: 'Not Now',
          role: 'cancel',
          cssClass: 'secondary',
          handler: (blah) => {
36
            //console.log('Confirm Cancel: blah');
37
38
39
40
41
42
43
44
45
46
47
            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) => {
48
                //console.log('my data: ', resp);
49
50
51
52
                this.router.navigateByUrl('/login');
                this.toastService.showToast("User account has been deactivated!");
                
              }, (error) => {
53
                //console.log(error);
54
55
56
57
58
59
60
61
62
63
64
65
66
                
              });
            });
           
                
          }
        }
      ]
    });

    await alert.present();
  
    
Priyanka Upadhye's avatar
Priyanka Upadhye committed
67
68
  }
}