Meteor忘记了密码的实现

Meteor forgot password implementation

本文关键字:实现 密码 忘记了 Meteor      更新时间:2023-09-26

我正在使用流星帐户包进行用户管理。我想实现忘记密码功能。为此,我将使用Accounts.forgetPassword(options,[callback])

这是我的客户端功能,可以触发忘记密码的

> forgetPassword = () => {
>   let email = this.refs.email.value;
>   Meteor.call('forgetPassword',email, function(err,list) {
>     console.log(err);
>   });   
>}

这是我的服务器端功能

forgetPassword: function(email){
    Accounts.forgotPassword({email: email}, function(err) {
       if (err) {
         if (err.message === 'User not found [403]') {
           console.log('This email does not exist.');
         } else {
           console.log('We are sorry but something went wrong.');
         }
       } else {
         console.log('Email Sent. Check your mailbox.');
       }
     });
  }

当我调用这个函数时,我得到了以下错误

I20160517-21:33:53.292(5.5)? Exception while invoking method 'forgetPassword' Ty
peError: Object [object Object] has no method 'forgotPassword'
I20160517-21:33:53.293(5.5)?     at [object Object].forgetPassword (meteor://?ap
p/webpack:///C:/wamp/www/avo_eth_v2.1/modules/TruthHurts/server/methods/user-met
hods.js:225:5)
I20160517-21:33:53.293(5.5)?     at maybeAuditArgumentChecks (meteor://?app/live
data_server.js:1698:12)
I20160517-21:33:53.293(5.5)?     at meteor://?app/livedata_server.js:708:19
I20160517-21:33:53.294(5.5)?     at [object Object]._.extend.withValue (meteor:/
/?app/packages/meteor/dynamics_nodejs.js:56:1)
I20160517-21:33:53.294(5.5)?     at meteor://?app/livedata_server.js:706:40
I20160517-21:33:53.294(5.5)?     at [object Object]._.extend.withValue (meteor:/
/?app/packages/meteor/dynamics_nodejs.js:56:1)
I20160517-21:33:53.294(5.5)?     at meteor://?app/livedata_server.js:704:46
I20160517-21:33:53.294(5.5)?     at tryCallTwo (C:'Users'sameera'AppData'Local'.
meteor'packages'promise'0.5.1'npm'node_modules'meteor-promise'node_modules'promi
se'lib'core.js:45:5)
I20160517-21:33:53.294(5.5)?     at doResolve (C:'Users'sameera'AppData'Local'.m
eteor'packages'promise'0.5.1'npm'node_modules'meteor-promise'node_modules'promis
e'lib'core.js:171:13)
I20160517-21:33:53.294(5.5)?     at new Promise (C:'Users'sameera'AppData'Local'
.meteor'packages'promise'0.5.1'npm'node_modules'meteor-promise'node_modules'prom
ise'lib'core.js:65:3)

如何实现此功能。请帮我

Accounts.forgotPassword是一个仅用于客户端的函数。您可以在客户端代码中调用以下函数,而不是调用流星方法:

forgetPassword = () => {
    let email = this.refs.email.value;
    Accounts.forgotPassword({email: email}, function (e, r) {
        if (e) {
            console.log(e.reason);
        } else {
            // success
        }
    }); 
}