首页 > 解决方案 > 在更改密码时更改 Firebase 中的用户信息(Angular)

问题描述

我最近使用 Firebase 在我的应用中实现了更改密码功能 - 用户将点击一个项目并收到一封电子邮件。这是通过登录功能连接起来的,该功能会检查 firebase 以查找“活动”布尔值。如果为 false,用户将被重定向到更改密码页面。

我现在的问题是,一旦密码更改,我想连接到 Firebase 并将“活动”设置为 true。我不想在用户与更改密码电子邮件交互之前执行此操作,但不知道如何执行此操作。一些帮助将不胜感激!

  login(email: string, password: string): void {
      this.firebaseAuth.signInWithEmailAndPassword(email, password)
      .then(value => {
        var userId = value.user.uid;
        this.db.database.ref(('users/' + userId)).get().then(value => {
          var userInfo = value.toJSON();
          if ( userInfo['active'] == false ) {
            this.router.navigate(['changepw']);
          } else {
            this.router.navigate(['']);
          }
        })
      })
      .catch(err => {
        console.log('Something went wrong:', err.message);
        alert(err.message);
      });
    }

  sendResetEmail() {
    this.clearErrorMessage()

    this.authService.resetPassword(this.email)
      .then(() => this.resetPassword = true)
      .catch(_error => {
        this.error = _error
      })
  }

<div>
  <div class="outer">
    <div class="welcome"><p>Resetting your password</p>
      <p>Fill out the fields below. If an email is found in our system we will send reset instructions to it.</p></div>
      <form class="form">
        <mat-form-field appearance="outline" class="form-control">
          <mat-label><i>E-Mail</i></mat-label>
          <input matInput type="text" id="email" [(ngModel)]="email" name="email" required>
          <mat-hint>Enter your account's e-mail address</mat-hint>
        </mat-form-field>

        <mat-form-field appearance="outline" class="form-control">
          <mat-label><i>Password</i></mat-label>
          <input matInput type="password" id="password" [(ngModel)]="password" name="password" required>
          <mat-hint>Enter your current password</mat-hint>
        </mat-form-field>

        <div class="form-footer"><br>
          <p><a *ngIf="!resetPassword && isValidMailFormat(email)" class="text-danger" (click)="sendResetEmail()">Click to send reset instructions to {{email}}</a></p>
          <p *ngIf="resetPassword" class="text-success">Check your email for instructions on how to reset your password!</p>
          
        </div><br><br>
      </form>
  </div>
</div>

标签: javascriptangularfirebase

解决方案


推荐阅读