Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import { Component, OnInit } from '@angular/core';
- import {NgForm} from "@angular/forms";
- import * as firebase from "firebase";
- import {NotificationService} from "../shared/notification.service";
- @Component({
- selector: 'app-user-settings',
- templateUrl: './user-settings.component.html',
- styleUrls: ['./user-settings.component.css']
- })
- export class UserSettingsComponent implements OnInit {
- constructor(private notifier: NotificationService) { }
- ngOnInit() {
- }
- changePassword(form: NgForm){
- var newPassword = form.value.newPassword;
- var oldPassword = form.value.oldPassword;
- var user = firebase.auth().currentUser;
- // Prompt the user to re-provide their sign-in credentials
- var credentials = firebase.auth.EmailAuthProvider.credential(
- user.email,
- oldPassword
- );
- user.reauthenticateWithCredential(credentials)
- .then(() => {
- user.updatePassword(newPassword)
- .then(() => {
- this.notifier.display("success", "Password successfully changed");
- })
- .catch((error) => {
- this.notifier.display("error", error.message);
- })
- })
- .catch((error) => {
- this.notifier.display("error", "Your old password is wrong: ");
- });
- }
- setEmail(form: NgForm){
- console.log("nieco");
- var password = form.value.password;
- var user = firebase.auth().currentUser;
- var credentials = firebase.auth.EmailAuthProvider.credential(
- user.email,
- password
- );
- user.reauthenticateWithCredential(credentials)
- .then(()=>{
- user.updateEmail(form.value.email)
- .then(() =>{
- this.notifier.display("success", "Email address has been changed");
- })
- .catch((error)=>{
- this.notifier.display("error", error.message)
- })
- })
- .catch((error)=>{
- this.notifier.display("error", "Your old password is wrong:");
- })
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement