我正在使用meteor Accounts包进行用户管理。我想实现忘记密码功能。因为我将使用 Accounts.forgotPassword(选项,[回调])
这是我的客户端功能,用于触发忘记密码
> 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)
我如何实现此功能。请帮帮我
答案 0 :(得分:1)
Accounts.forgotPassword
是仅限客户端的功能。您可以在客户端代码中调用此函数,而不是调用流星方法:
forgetPassword = () => {
let email = this.refs.email.value;
Accounts.forgotPassword({email: email}, function (e, r) {
if (e) {
console.log(e.reason);
} else {
// success
}
});
}