简体   繁体   English

流星忘记密码的实现

[英]Meteor forgot password implementation

I'm using meteor Accounts package for user management. 我正在使用流星帐户软件包进行用户管理。 i want to implement forgot password functionality. 我想实现忘记密码功能。 for that i'm going to use Accounts.forgotPassword(options, [callback]) 为此,我将使用Accounts.forgotPassword(options,[callback])

Here is my client side function to trigger forgot password 这是我的客户端功能,触发忘记密码

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

Here is my server side function 这是我的服务器端功能

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.');
       }
     });
  }

I'm getting below error while i call this functions 我调用此函数时遇到错误

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)

How do i implement this functionality. 我如何实现此功能。 please help me 请帮我

Accounts.forgotPassword is a client-side only function. Accounts.forgotPassword是仅客户端功能。 Instead of calling a meteor method, you can just call this function in your client code: 无需调用流星方法,只需在客户端代码中调用此函数即可:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM