使用REST进行环回电子邮件验证(其中是必需的verifyOptions配置)

问题描述:

在回环api资源管理器(localhost:3000/explorer)中,有一个端点{POST/users/{id}/verify},我可以用它来发送验证邮件。在说明中指出,使用REST进行环回电子邮件验证(其中是必需的verifyOptions配置)

“与配置verifyOptions触发用户的身份验证”我非常想知道在哪里/这verifyOptions是如何配置的。 在此先感谢

正如user.js的评论说:(node_modules /回环/普通/型号)

* Verify a user's identity by sending them a confirmation message. 
    * NOTE: Currently only email verification is supported 
    * 
    * ```js 
    * var verifyOptions = { 
    * type: 'email', 
    * from: '[email protected]' 
    * template: 'verify.ejs', 
    * redirect: '/', 
    * generateVerificationToken: function (user, options, cb) { 
    *  cb('random-token'); 
    * } 
    * }; 

你应该创建这个对象,并调用这个对象的user.verify功能。您可以在afterRemote钩这样做:

//send verification email after registration 
    User.afterRemote('create', function(context, user, next) { 
    var options = { 
     type: 'email', 
     to: user.email, 
     from: '[email protected]', 
     subject: 'Thanks for registering.', 
     template: path.resolve(__dirname, '../../server/views/verify.ejs'), 
     redirect: '/verified', 
     user: user 
    }; 

    user.verify(options, function(err, response) { 
     if (err) { 
     User.deleteById(user.id); 
     return next(err); 
     } 
     context.res.render('response', { 
     title: 'Signed up successfully', 
     content: 'Please check your email and click on the verification link ' + 
      'before logging in.', 
     redirectTo: '/', 
     redirectToLinkText: 'Log in' 
     }); 
    }); 
    }); 

这个链接也显示了如何配置这条路线:

https://apidocs.strongloop.com/loopback/#user-prototype-verify

此示例显示了一个样本项目的全过程:

https://github.com/strongloop/loopback-example-user-management

这个链接也可以帮助你看到这个过程的一个样本:

https://github.com/strongloop/loopback/issues/590