如何在流星应用程序中重置密码 [英] How to reset password in meteor application

查看:27
本文介绍了如何在流星应用程序中重置密码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在构建一个 Meteor 应用程序并使用 oaf:accounts-entry 包来处理我的用户注册 &验证.我现在正在研究重置密码功能.但是,当我单击电子邮件重置密码链接"时,该应用程序不会向我发送任何电子邮件.有人可以帮助我或向我指出有关如何为 oaf:accounts-entry 包配置重置密码功能的说明吗?谷歌搜索后,我找不到有关如何配置它的说明.我安装的相关包是:

I am building a Meteor application and am using the oaf:accounts-entry package to handle my user registration & authentication. I am working on the reset password function right now. However, when I click on "email reset password link", the application doesn't email me anything. Can someone help me or point me to instructions on how to configure the reset password function for the oaf:accounts-entry package? After doing a google search, I could not find instructions on how to configure it. The relevant packages I have installed are:

  • oaf:accounts-entry
  • 账户密码
  • 电子邮件

谢谢!!

推荐答案

注意:使用 Meteor JS 1.6.1.1,需要的包是 accounts-ui、accounts-password

NOTE: Using Meteor JS 1.6.1.1, package required are accounts-ui, accounts-password

要使忘记密码链接在小部件的注册/登录中可见,您需要在位于 ROOT_FOLDER/client/main.js.代码如下,

To make forgot password link visible in the signup/sign in a widget, you need to do add little configuration in a file at location ROOT_FOLDER/client/main.js. The code is as below,

Accounts.ui.config({
    passwordSignupFields: "USERNAME_AND_EMAIL"
});

如果您不选择 passwordSignupFields: "USERNAME_AND_EMAIL" 并选择类似 passwordSignupFields: "USERNAME_ONLY" 的内容,您将看不到 忘记密码 选项在注册小部件中.(没有人会告诉你这个,我自己发现了这个奇怪的场景.不过,我想知道 MDG 团队为什么要这样做?)

If you do not choose passwordSignupFields: "USERNAME_AND_EMAIL" and choose something like passwordSignupFields: "USERNAME_ONLY", you won't be able to see forgot password option in the signup widget. (No one will tell you this, I discovered this weird scenario myself. Still, I wonder why MDG team did this? )

在服务器端你还需要在 PROJECT/server/main.js 位置添加少量代码,就在 Meteor.startup(()=>{}); 提供用于重置密码链接的电子邮件模板.下面是你需要自己调整一些属性的代码.

At Server end you also need to add little code at location PROJECT/server/main.js just outside Meteor.startup(()=>{}); to provide an email template for reset password link. Below is the code you need to adjust some properties yourself.

var username = 'you_id@gmail.com'; 
var password = 'your password';
var server = 'smtp.gmail.com';
var port = '465';

process.env.MAIL_URL = 'smtps://' +
encodeURIComponent(username) + ':' +
encodeURIComponent(password) + '@' +
encodeURIComponent(server) + ':' + port;

process.env.NODE_TLS_REJECT_UNAUTHORIZED = 0;

Accounts.emailTemplates.from = 'support_team@yourappname.com';


Accounts.emailTemplates.siteName = 'APP NAME';

Accounts.emailTemplates.resetPassword = {
  subject(user) {
    return "Reset Password Link.";
  },
  text(user, url) {
    return `Hello! 

    Click the link below to reset your password.

    ${url}

    If you didn't request this email, please ignore it.

Thanks,
APP Team.
`
  },
  html(user, url) {
    // This is where HTML email content would go.
    // See the section about html emails below.
  }
};

第 1 步:

看看您是否可以在注册小部件上查看忘记密码,如下所示.

See if you are able to view forgot password on the signup widget as below.

第 2 步:

当您点击忘记密码"时,您应该能够在与下面相同的小部件位置查看下面的弹出窗口.

When you click "forgot password", you should be able to view below popup at same widget location as below.

在有效的电子邮件条目中,您必须看到成功的完整通知,最重要的是您必须收到一封邮件以重置密码链接,如下所示.

on valid Email entry, you must see a success full notification and most importantly you must receive a mail for reset password link as below.

第 3 步:

当您点击该链接时,您会看到一个带有如下弹出窗口的新窗口(注意:您必须在给定的令牌到期时间之前点击该链接).

When you click on the link, you can see a new window with a popup as below (NOTE: You must click the link before given token expiry time).

瞧!!!只需添加一个新密码,您就会自动登录到给定的页面.正如上面所讨论的,Meteor 已经向我们提供了一切.你只需要配置这些东西并让它运行.

Voila!!! just add a new password and you automatically login to given page. Everything is already provided to us as discussed above by Meteor. You just need to configure the stuff and get it running.

这篇关于如何在流星应用程序中重置密码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆