Meteor:如果未验证用户的电子邮件,则阻止对应用程序的访问 [英] Meteor: Block access to application if user's email is not verified

查看:58
本文介绍了Meteor:如果未验证用户的电子邮件,则阻止对应用程序的访问的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有办法限制应用程序的可访问性并将用户重定向到一个路径,该路径呈现一个模板,说明请检查您的电子邮件并验证您的电子邮件."

Is there a way to restrict accessibility to the app and redirect the user to a path that renders a template stating "please check your email and verify your email."

用户在创建帐户时会收到一个验证链接,当他们点击它时,emails.verified 会被设置为 true - 很棒.

The user receives a verification link upon account creation, when they click it, emails.verified is then set to true - great.

在创建帐户和验证他们的电子邮件之间,我想限制对应用程序的访问.我不希望用户在我的应用上创建个人资料并在线发布,因为他们可能是恶意"用户.

Between the time of account creation and verifying their email, I would like to restrict access to the application. I dont want a user to create profile on my app and post online as they maybe a 'malicious' user.

解决方案一?:创建帐户后,我是否可以立即将用户注销并将其引导至包含模板消息请检查您的电子邮件并验证您的电子邮件"的路径.

SOLUTION ONE ?: upon account creation, can I log the user out immediately and direct them to a path with the template message "please check your email and verify your email."

然后,在 Accounts.onLogin 上,检查用户的电子邮件是否经过验证.

Then, on Accounts.onLogin, check if a users email is verified or not.

server.js

 if ( user.user.emails.verified === false ) {
     //render please verify email template
      }
      else  {
       //continue as usual
       }



Accounts.config({
 sendVerificationEmail: true,
 forbidClientAccountCreation: false,
 loginExpirationInDays: null
});

是否有我缺少的更简单、更合乎逻辑的方法?

Is there a simpler and more logical method that I'm missing?

推荐答案

如果你使用 Iron Router 你可以添加一个 before 钩子:

If you are using Iron Router you can add a before hook:

Router.onBeforeAction(function(){
  if (Meteor.loggingIn()){
    this.render('loading');
  } else if (Meteor.user() && !Meteor.user().emails[0].verified){
    this.render('verification');
  } else {
    this.next();
  }
});

这篇关于Meteor:如果未验证用户的电子邮件,则阻止对应用程序的访问的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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