【发布时间】:2015-07-16 04:36:21
【问题描述】:
我希望每个在我的应用中验证其电子邮件的用户之后都能获得特定的角色。我正在使用 alanning:roles 包。无论如何,在他点击验证链接后,我有一个功能可以为他在 Mongo 中设置角色。
所以我找到了这个功能,但它显然只是客户端:
// (client-side)
Template.Homepage.created = function() {
if (Accounts._verifyEmailToken) {
Accounts.verifyEmail(Accounts._verifyEmailToken, function(err) {
if (err != null) {
if (err.message = 'Verify email link expired [403]') {
console.log('Sorry this verification link has expired.')
}
} else {
console.log('Thank you! Your email address has been confirmed.')
}
});
}
};
而且我有在服务器端设置角色的方法
Accounts.onCreateUser(function (options, user) {
Roles.setRolesOnUserObj(user, ['employer']);
if (options.profile) {
// include the user profile
user.profile = options.profile
}
如何将这两者联系起来,或者有更好的方法来实现这个逻辑。我知道这现在在函数“onCreateUser”中,但如果有更好的方法,我会单独放置。
【问题讨论】:
标签: meteor