Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/file/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 我应该如何构造Firebase身份验证密码重置流?_Javascript_Angularjs_Firebase_Ionic Framework - Fatal编程技术网

Javascript 我应该如何构造Firebase身份验证密码重置流?

Javascript 我应该如何构造Firebase身份验证密码重置流?,javascript,angularjs,firebase,ionic-framework,Javascript,Angularjs,Firebase,Ionic Framework,我正在使用该解决方案在我的Ionic应用程序中注册/登录用户。我正在努力实现我的“密码重置流程” 当前,当用户忘记密码时,流程开始如下: html: 授权服务: function resetPassword(email) { auth.$resetPassword({ email: email }).then(function() { $location.path('/intro'); }).catch(function(error) {

我正在使用该解决方案在我的Ionic应用程序中注册/登录用户。我正在努力实现我的“密码重置流程”

当前,当用户忘记密码时,流程开始如下:

html:

授权服务:

function resetPassword(email) {
    auth.$resetPassword({
        email: email
    }).then(function() {
        $location.path('/intro');
    }).catch(function(error) {
        alert(error);
    });
}
function loginUser(email, password) {
    auth.$authWithPassword({
        email: email,
        password: password
    }).then(function(authData) {
        if (authData.password.isTemporaryPassword) {
            $location.path('/reset');
        } else {
            $location.path('/people');
        }
    }).catch(function(error) {
        alert(error);
    });
}
因此,用户会收到一封带有临时密码的电子邮件。谢天谢地,用户登录时返回的
authData
对象上有一个
isTemporaryPassword
字段

我在authService中利用了这一点:

function resetPassword(email) {
    auth.$resetPassword({
        email: email
    }).then(function() {
        $location.path('/intro');
    }).catch(function(error) {
        alert(error);
    });
}
function loginUser(email, password) {
    auth.$authWithPassword({
        email: email,
        password: password
    }).then(function(authData) {
        if (authData.password.isTemporaryPassword) {
            $location.path('/reset');
        } else {
            $location.path('/people');
        }
    }).catch(function(error) {
        alert(error);
    });
}
这就是我的问题所在。当用户到达
/reset
时,我希望他们能够简单地输入两次新密码(第二次输入以确认),但是Firebase
$changePassword
方法不仅接收电子邮件和新密码,还接收旧密码。这对我来说似乎是多余的,因为用户刚刚输入了他们的旧(临时)密码,以便到达这个屏幕。下面是my
authService
中的
changePassword

function changePassword(email, oldPassword, newPassword) {
    auth.$changePassword({
        email: email,
        oldPassword: oldPassword,
        newPassword: newPassword
    }).then(function() {
        $location.path('/people');
    }).catch(function(error) {
        alert(error);
    });
}

我可以随时强制用户再次输入临时密码,也可以将此临时密码设置为
$rootScope
,但我觉得必须有一个更干净的选项。有什么想法吗?

我能以一种非常简单的方式解决这个问题。我将我的
authService
$resetPassword
函数中的
$location.path
行更改为以下内容:

$location.path('/reset');
然后,我将我的
reset password.html
更新为以下内容:

<ion-view view-title="Reset Password" class="login-background">

<div class="signup-form">

<div class="list list-inset signup">
  <label class="item item-input">
    <span class="input-label" style="text-align:right">Email</span>
    <input type="text" placeholder="name@example.com" ng-model="reset.email">
  </label>
  <label class="item item-input">
    <span class="input-label" style="text-align:right">Temporary Password</span>
    <input type="password" ng-model="reset.tempPassword">
  </label>
  <label class="item item-input">
    <span class="input-label" style="text-align:right">New Password</span>
    <input type="password" ng-model="reset.newPassword">
  </label>
  <label class="item item-input">
    <span class="input-label" style="text-align:right">Confirm</span>
    <input type="password" ng-model="reset.confirmedPassword">
  </label>
</div>

<button class="button button-balanced" ng-click="reset.changePassword()">Update Password</button>

<p class="mismatch" ng-show="reset.mismatch">{{ reset.mismatchMessage }}</p>

这归结为在页面导航/页面上下文之间维护客户端上的某些状态。由于您使用的是Angular,而不是强制浏览器进行实际刷新,因此我将利用您建议的可用globals。否则,它将作为临时cookie、URL参数或LocalStorage中的位而成为标准的后备方法。@RobDiMarco,我一直在过度思考这个问题。我的解决方案出现在下面,结果证明我根本不需要使用
isTemporaryPassword
字段。
vm.changePassword = function() {
  vm.mismatch = false;

  if (vm.newPassword === vm.confirmedPassword) {
    authService.changePassword(vm.email, vm.tempPassword, vm.newPassword);
  } else {
    vm.mismatch = true;
    vm.mismatchMessage = 'Password and confirmation must match';
  }
};