Advertisement
dajolazar

formulare.ts

Nov 30th, 2017
165
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import { Component, OnInit } from '@angular/core';
  2. import {NgForm} from "@angular/forms";
  3. import * as firebase from "firebase";
  4. import {NotificationService} from "../shared/notification.service";
  5.  
  6. @Component({
  7.   selector: 'app-user-settings',
  8.   templateUrl: './user-settings.component.html',
  9.   styleUrls: ['./user-settings.component.css']
  10. })
  11. export class UserSettingsComponent implements OnInit {
  12.  
  13.   constructor(private notifier: NotificationService) { }
  14.  
  15.   ngOnInit() {
  16.   }
  17.  
  18.   changePassword(form: NgForm){
  19.     var newPassword = form.value.newPassword;
  20.     var oldPassword = form.value.oldPassword;
  21.  
  22.     var user = firebase.auth().currentUser;
  23.  
  24.     // Prompt the user to re-provide their sign-in credentials
  25.     var credentials = firebase.auth.EmailAuthProvider.credential(
  26.       user.email,
  27.       oldPassword
  28.     );
  29.     user.reauthenticateWithCredential(credentials)
  30.       .then(() => {
  31.         user.updatePassword(newPassword)
  32.           .then(() => {
  33.             this.notifier.display("success", "Password successfully changed");
  34.           })
  35.           .catch((error) => {
  36.             this.notifier.display("error", error.message);
  37.           })
  38.       })
  39.       .catch((error) => {
  40.       this.notifier.display("error", "Your old password is wrong: ");
  41.     });
  42.  
  43.   }
  44.  
  45.   setEmail(form: NgForm){
  46.     console.log("nieco");
  47.     var password = form.value.password;
  48.     var user = firebase.auth().currentUser;
  49.     var credentials = firebase.auth.EmailAuthProvider.credential(
  50.       user.email,
  51.       password
  52.     );
  53.     user.reauthenticateWithCredential(credentials)
  54.       .then(()=>{
  55.         user.updateEmail(form.value.email)
  56.           .then(() =>{
  57.             this.notifier.display("success", "Email address has been changed");
  58.           })
  59.           .catch((error)=>{
  60.             this.notifier.display("error", error.message)
  61.           })
  62.       })
  63.       .catch((error)=>{
  64.         this.notifier.display("error", "Your old password is wrong:");
  65.       })
  66.   }
  67. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement