我正在使用accounts-password package - meteor 。
我为管理员编写了界面。
管理员将为其他用户创建帐户。
Accounts.createUser({
email: "<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="18797a7b587f75797174367b7775" rel="noreferrer noopener nofollow">[email protected]</a>",
password : "abc123",
profile: { name: register_name }
});
但是执行此代码后,我的应用程序自动使用帐户登录 [email protected] ,但我不想要它
问题
如何创建不自动登录的帐户?
我阅读了accounts-password
源代码,但我不知道如何删除自动登录
我也尝试使用 Meteor.users.insert 函数,但 Accounts.setPassword
不起作用..
最佳答案
这是使用帐户包的正常行为,为避免弄乱源代码,请使用 Meteor.method/Meteor.call .
这是一个简单的示例,您也可以使用默认提交的用户名
,而不是个人资料:{name:register_name}
。
if(Meteor.isServer){
Meteor.methods({
createUserFromAdmin:function(emai,password,username){
Accounts.createUser({email:email,password:password,username:username})
}
})
}else if(Meteor.isClient){
Template.admin.events({
'click #createAccount':function(){
Meteor.call('createUserFromAdmin',email,password,username,function(err,result){
if(!err){
console.log("a new user just got created")
}else{
console.log("something goes wrong with the following error message " +err.reason )
}
})
}
})
}
通过此功能,您可以在管理模板上创建多个帐户,并在注册模板上保留自动登录行为(如果有的话)
关于Meteor..账户-密码--无需登录即可在客户端创建账户,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29453829/