在Meteor中生成验证令牌而不发送电子邮件?

Dis*_*ive 3 email verification meteor

在我的流星应用程序中,我正在设置注册过程.

Meteor有一个Account.sendVerificationEmail方法,可以通过令牌向新用户发送电子邮件,以验证他们的电子邮件地址

我的应用程序确实需要这个功能,但我真的不想使用sendVerificationEmail发送电子邮件,因为我已经有了自己的电子邮件助手,它有一堆逻辑,我希望我系统中的所有电子邮件都传递给我们那个功能.

所以我的问题是我确实想在注册时为用户创建我的验证令牌,但我不希望sendVerificationEmail发送电子邮件,因为我想手动完成.

这可能吗?

Ser*_*soy 5

首先添加核心"随机"包用于随机代码生成

$ meteor add random
Run Code Online (Sandbox Code Playgroud)

然后拦截帐户创建过程

Accounts.onCreateUser(function(options, user) {
  // create a verified flag and set it false
  user.customVerified = false;

  //20 character random lowercase hex string. You can use a hash of some user info if you like. I just put this here for demonstration of the concept :)
  user.customVerificationCode = Random.hexString(20).toLowerCase(); 

  //pass the new user's email and the verification code to your custom email function so that you can craft and send the mail. Please double check the option.profile.emails[0], the email should be available somewhere within the options object
  myCustomEmailFunction(options.profile.emails[0], user.customVerificationCode); 

  // continue with account creation
  return user;
}); 
Run Code Online (Sandbox Code Playgroud)

此时,如果您不想向未验证的用户显示ui元素片段,则可以为其创建模板助手.或者您可以检查您的出版物中是否验证了用户.等等......无论你想限制什么.

现在,您可以使用铁路由器在应用程序中定义路径,以便当用户单击链接时,路径将获取验证码并将用户的已验证标志设置为true.