reset-password.page.ts 2.13 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
import { Component, OnInit } from '@angular/core';
import { Router } from '@angular/router';
import { HttpClient, HttpHeaders } from '@angular/common/http';
import { Observable } from 'rxjs';
import { Storage } from '@ionic/storage';
import { ToastService } from '../../services/toast.service';
import { UserService } from '../../services/user.service';
import { RestService } from '../../rest.service';

@Component({
  selector: 'app-reset-password',
  templateUrl: './reset-password.page.html',
  styleUrls: ['./reset-password.page.scss'],
})
export class ResetPasswordPage implements OnInit {
 oldPassword="";
 newPassword=""; 
 confirmPassword="";
 username="";
 ResetPasswordApi : Observable<any>;
  constructor(private router: Router,
     public httpClient: HttpClient,
     private toastService: ToastService,
     public restService: RestService,
    private storage: Storage,
    public userService: UserService) { 
    this.username = this.userService.getUsername();}
  ngOnInit() {
  }
  login(){
    this.router.navigateByUrl('/login');
  }
  resetPassword(){
Priyanka Upadhye's avatar
Priyanka Upadhye committed
34
35
    if(this.oldPassword=="" || this.confirmPassword=="" || this.newPassword=="")
    this.toastService.showToast("All Feilds are mandatory");
36
37
    else if(this.newPassword.length < 4)
    this.toastService.showToast("Weak Password");
Priyanka Upadhye's avatar
Priyanka Upadhye committed
38
    else if(this.confirmPassword!=this.newPassword)
39
    this.toastService.showToast("Please Confirm Password Again");
40
    
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
    else{
    this.storage.get('token').then((token) => {
      let url = 'http://193.196.52.237:8081/password-reset/'
      
      const headers = new HttpHeaders().set("Authorization", "Bearer " + token);
      this.ResetPasswordApi = this.httpClient.post<any>(url, {"oldPassword":this.oldPassword,"newPassword": this.newPassword},{headers});
      this.ResetPasswordApi.subscribe((resp) => {
        console.log("PasswordChanged", resp);
        
        this.toastService.showToast("Password Changed Sucessfully!Login Again");
        this.router.navigateByUrl('/login');

      }, (error) => {console.log(error)
        //this.loadingService.hideLoader();
        this.toastService.showToast("Please Try Again");
      });
    });
  }
  }
  
}