【问题标题】:resetPassword issues in meteor流星中的重置密码问题
【发布时间】:2015-02-19 20:02:52
【问题描述】:

我向用户发送了注册电子邮件,当他输入密码和其他详细信息时,我正在尝试重置密码,但它抛出错误

uncaught error extpected to find a document to change

如你在法师中所见

我已经订阅了用户记录

我的代码

this.route('enroll', {
        path: '/enroll-account/:token',
        template: 'enroll_page',
        onBeforeAction: function() {
            Meteor.logout();
            Session.set('_resetPasswordToken', this.params.token);
            s = this.subscribe('enrolledUser', this.params.token).wait();
        }
    }),

在我显示表单和提交事件之后

onSubmit: function(creds) {
            var options = {
                _id: Meteor.users.findOne()._id,
                name: creds.name
            }
            var token=Session.get('_resetPasswordToken');
            Meteor.call('updateUser', options, function(error, result) {
                if(!error) {
                    Accounts.resetPassword(token, creds.password, function(error) {
                        if (error) {
                            toastr.error("Sorry we could not update your password. Please try again.");
                            return false;
                        }
                        else{
                            toastr.error("Logged In");
                            Router.go('/');
                        }
                    });
                } else {
                    toastr.error("Sorry we could not update your password. Please try again.");
                    return false;
                }
            });
            this.resetForm();
            this.done();

            return false;
        }

一切正常,但重置密码回调未触发,控制台中显示上述错误。

我的令牌已从用户记录中删除,我可以使用登录表单登录,但

来自文档

Reset the password for a user using a token received in email. Logs the user in afterwards.

重置密码后我无法自动登录,抛出上述错误

我在这里错过了什么?

【问题讨论】:

标签: meteor meteor-accounts


【解决方案1】:
this.subscribe('enrolledUser', this.params.token).wait();

您正在使用 resetPassword 令牌订阅

当您调用Accounts.resetPassword 方法时,该方法将重置密码并从用户记录中删除令牌。

因此您的订阅已丢失,并且客户端没有可修改的记录 (这就是错误Expected to find a document to change)

而是在第一次订阅时保存用户 ID 并使用 Id 订阅用户记录

所以订阅不会丢失

path: '/enroll-account/:token',
        template: 'enroll_page',
        onBeforeAction: function() {
            Meteor.logout();
            Session.set('_resetPasswordToken', this.params.token);
            s = this.subscribe('enrolledUser', this.params.token).wait();
        },
        onAfterAction:function(){
               if(this.ready()){
                  var userid=Meteor.users.findOne()._id;
                  Meteor.subscribe("userRecord",userid);
               }
        }

【讨论】:

  • 你试过了吗?它不适合我。同样的错误。流星是如何做到的?谢谢!
【解决方案2】:

或者,您可以在您的出版物中执行以下操作。这对我有用(但我的查询比这稍微复杂一些)。

Meteor.publish('enrolledUser', function (token) {
  check(token, String);
  return Meteor.users.find({
    $or: [{
      _id: this.userId
    }, {
      'services.password.reset.token': token
    }]
  });
});

从文档中,它说

使用电子邮件中收到的令牌重置用户的密码。 之后让用户登录。

所以基本上,您也必须在事后订阅已登录的用户。有点傻,不过无所谓。

【讨论】:

  • 上述解决方案与meteorhacks:fast-render不兼容。仍然得到 Uncaught Exception: expected to find a document to change 错误。删除快速渲染后,一切都会按预期进行。我正在使用我认为可能有用的 FlowRouter 和基于模板的订阅。一些服务器端日志记录显示注册用户发布始终成功填充。但是,客户端交互中没​​有正确发生某些事情。如果有人有解决这种快速渲染竞争条件的方法,我很想听听。
  • 解决方法是删除订阅。这个表单可以只使用令牌,获取用户只是为了显示用户名和电子邮件。
猜你喜欢
  • 1970-01-01
  • 2020-06-01
  • 2012-12-17
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-06-12
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多