Commit 4995603e by muhsin

added change password

parent 30081a1f
......@@ -72,9 +72,22 @@
<div class="row">
<h6>Change Password</h6>
</div>
<!-- <div class="row">
<input class="" type="password" placeholder="Current Password" />
</div> -->
<div class="row">
<input
class=""
type="password"
minlength="6"
#currentPassword="ngModel"
[(ngModel)]="updatePassword.currentPassword"
name="currentPassword"
placeholder="Current Password"
/>
<div
*ngIf="currentPassword.errors && currentPassword.errors.minlength"
>
Password must be at least 6 characters
</div>
</div>
<div class="row">
<input
class=""
......@@ -83,6 +96,7 @@
type="password"
placeholder="New Password"
minlength="6"
[required]="currentPassword ? true: false"
#password="ngModel"
/>
<div *ngIf="password.errors && password.errors.minlength">
......@@ -96,10 +110,11 @@
[(ngModel)]="updatePassword.confirmPassword"
name="confirmPassword"
type="password"
[required]="currentPassword ? true: false"
placeholder="Confirm Password"
/>
<div *ngIf="">
Password should match
<div *ngIf="confirmPassword.errors">
{{confPasswordErr}}
</div>
</div>
</div>
......
......@@ -17,6 +17,7 @@ export class ChangedetailsPage implements OnInit {
name: '',
phone: ''
};
confPasswordErr: string;
updatePassword: UpdatePassword = {
password: '',
......@@ -62,19 +63,28 @@ export class ChangedetailsPage implements OnInit {
console.log(form.value);
if (form.valid) {
// Change Password
if (form.value.password) {
if (form.value.password === form.value.confirmPassword) {
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.password);
console.log('Password Changed and profile updated');
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');
// this.register.updateData(form.value, this.userData);
console.log('profile updated', form.value);
}
console.log('valid form values', form.value);
// console.log('valid form values', form.value);
} else {
console.log(form);
}
}
}
......@@ -48,6 +48,7 @@ export class UpdateService {
// });
}
// Update User Data
updateData(userData: UpdateUserDetails, oldData: User) {
this.loader = true;
this.type = 2;
......@@ -85,4 +86,50 @@ export class UpdateService {
console.log(error);
});
}
// Change user password
updatePassword(currentPassword: string, newPasswd: string) {
this.loader = true;
let currentUser = this.afAuth.auth.currentUser; // Gets current user
// Credential is required for re-authentication
const credential = auth.EmailAuthProvider.credential(
currentUser.email,
currentPassword
);
// Re-authenticate user
currentUser
.reauthenticateWithCredential(credential)
.then(() => {
currentUser
.updatePassword(newPasswd) // Update password
.then(success => {
console.log('password changed');
this.loader = false;
this.service
.showToast('Password Changed!', 'top', 'my-toast', 1000) //success toast
.then(res => {
this.router.navigateByUrl('profile');
this.loader = false;
});
})
.catch(error => {
console.log('something fishy');
this.service
.showToast('Something went wrong', 'top', 'my-toast', 1000) //failure toast
.then(res => {
this.loader = false;
});
});
})
.catch(error => {
console.log(error);
this.service
.showToast(error.message, 'top', 'my-error', 3000) //failure toast
.then(res => {
this.loader = false;
});
});
}
}
Markdown is supported
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