【发布时间】:2018-02-23 19:45:41
【问题描述】:
当新用户注册 Web 应用程序时,会向他发送一封验证电子邮件。我阻止新用户在验证前登录。
同时,如果验证链接过期并且用户忘记了密码,他将单击重置密码链接并收到一封电子邮件。
所以我认为我应该同时处理重置密码操作和验证。否则用户更改密码后也无法登录。
function handleResetPassword(auth, actionCode) {
auth.verifyPasswordResetCode(actionCode)
.then(function (email) {
// Showing the reset screen and ask the user for
// the new password.
}).catch(function (error) {
//
});
};
当用户保存新密码时:
function saveNewPassword() {
auth.confirmPasswordReset(actionCode, vm.form.password).then(function (resp) {
// Password reset has been confirmed and new password updated.
// Now auto sign in user
auth.signInWithEmailAndPassword(vm.email, vm.form.password).catch(function (error) {
// Handle Errors here.
});
firebase.auth().onAuthStateChanged(function (user) {
if (user) {
// user signed in.
// check whether the user is verified
// if not set true
user.updateProfile({ emailVerified: true })
}
});
}).catch(function (error) {
//
});
}
但是下面的代码没有按我的预期工作,因为它没有任何影响。我可以更改其他用户数据(例如 displayName),但不能更改(emailVerified)。它仅适用于 Firebase 电子邮件验证。
user.updateProfile({ emailVerified: true })
这种类型的用户场景推荐的方法是什么?
【问题讨论】:
标签: angularjs firebase firebase-authentication