javascript - 在更改密码时更改 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>
解决方案
推荐阅读
- r - 如何在 R 中计算卫星数据的区域(国家)平均值?
- r - 将行应用于名义行之间的值
- dart - 从 Dartz 中的不同 Either 返回一个 Either 对象
- sql - SQL Server:仅锁定一行并在并发访问中更新它
- c - 使用 sizeof 检查 int、char、float、double 的 10 元素数组中使用的内存,并找到数组中单个元素所需的内存
- html - 在滚动的 html 下拉列表中对齐所选项目
- python-3.x - 查找字符串中所有索引的最佳方法,然后使用索引在 Hangman Game 的另一个字符串中编辑这些位置的字母
- r - 添加行值然后在数据框之间划分
- sql - SQL 仅显示具有唯一值的行
- java - 我如何模拟这个参数匹配器?