Meteor.. accounts- password— Create account on client without login

痞子三分冷 提交于 2019-12-12 21:31:05

问题


I'm using accounts-password package - Meteor.

I code interface for admin.

Admin will create accounts for other user.

Accounts.createUser({
        email: "abc@gmail.com", 
        password : "abc123", 
        profile: { name: register_name }
   });

But after this code executed, my application automatic login with account abc@gmail.com, wich i don't want it

Question

How to create accounts without automatic login?

I read accounts-password source but i dont know how to remove automatic login

I also tried to use Meteor.users.insert function but Accounts.setPassword didn't work..


回答1:


This is a normal behavior using accounts package, to avoid messing with the source code use a Meteor.method/Meteor.call.

This is a simple example,also you can use the default username filed and not a profile:{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 )
                }
             })
           }
        })
       }

With this you can create multiple accounts on the admin template, and keep the autologin behavior on the sign-up template (if you have one)



来源:https://stackoverflow.com/questions/29453829/meteor-accounts-password-create-account-on-client-without-login

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!