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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
import { Component, OnInit } from '@angular/core';
import { Location } from '@angular/common';
import { Router, ActivatedRoute } from '@angular/router';
import { UpdateUserDetails, UpdatePassword } from '../../config/services/user';
import { UpdateService } from '../../config/update.service';
import { ServiceService } from '../../config/service.service';
import { NgForm } from '@angular/forms';
@Component({
selector: 'app-changedetails',
templateUrl: './changedetails.page.html',
styleUrls: ['./changedetails.page.scss']
})
export class ChangedetailsPage implements OnInit {
userData: any;
updateData: UpdateUserDetails = {
name: '',
phone: ''
};
confPasswordErr: string;
updatePassword: UpdatePassword = {
password: '',
confirmPassword: ''
};
submitted = false;
constructor(
private router: Router,
private route: ActivatedRoute,
private location: Location,
public register: UpdateService,
private service: ServiceService
) {
// Gets userdata
this.service.get('userData').then(val => {
console.log(JSON.parse(val));
this.userData = JSON.parse(val);
console.log(this.userData);
});
// this.service.get('user').then(data => {
// if (data) {
// this.userData = JSON.parse(data);
// console.log(this.userData);
// }
// });
}
ngOnInit() {}
goToPage(path, data = null) {
this.router.navigateByUrl(path, { queryParams: data });
document.body.scrollTop = document.documentElement.scrollTop = 0;
}
goBack() {
this.location.back();
}
onFormSubmit(form: NgForm) {
this.submitted = true;
console.log(form.value);
if (form.valid) {
// Change Password
if (form.value.currentPassword && form.value.password) {
if (
form.value.password &&
form.value.password === form.value.confirmPassword
) {
// this.register.updateData(form.value, this.userData.uid);
this.register.updatePassword(
form.value.currentPassword,
form.value.password
);
console.log('Password Changed and profile updated'), form.value;
} else {
console.log('Password should match');
this.confPasswordErr = 'Password should match';
}
} else {
// this.register.updateData(form.value, this.userData);
console.log('profile updated', form.value);
}
// console.log('valid form values', form.value);
} else {
console.log(form);
}
}
}