在登录之前创建OAUTH帐户

时间:2015-04-08 00:53:59

标签: meteor meteor-accounts

我有一个我正在处理的应用程序,它有一个或两个" main"与其他帐户关联的帐户。我目前正在使用帐户密码,帐户-ogle和alanning:角色,但我稍后可能会添加其他OAuth提供商。

这个想法是会有一两个用户是"管理员"对于一个更大的群体,因此我希望能够允许他们添加用户。我不介意在首次登录时必须通过OAuth授权页面,但我希望能够将用户添加到Meteor.users集合中,并允许管理员在记录之前进行设置在,但我不知道如何做到这一点。我是否可以简单地将用户添加到Meteor.users集合中,只填充email子文档的google属性?我猜这封电子邮件不是Meteor用来将存储的Meteor.users文档连接到相应的Google OAuth帐户的内容,因为还有一个id属性似乎对此目的更有用。

1 个答案:

答案 0 :(得分:0)

因此,基于您在评论中所说的内容,我详细说明了这个DEMO,因为您想要创建用户并将用户添加到某种角色"或" group"我在这里使用meteor-roles包。

  

允许人们创建一组用户

这可以通过一些不同的方式来完成,为演示目的我创建1x1用户和leater为他们分配一个角色。

要避免autologin行为,请使用Meteor.method

//server
Meteor.methods({
   createSimpleUser:function(email){
      return  Accounts.createUser({
               email:email,
               password:"test123" //you can force the user in the first login to change the password.
            })
     }
  })
//Client
Meteor.call('createUser',"test@gmail.com")

现在你已经创建了用户,你应该为他们分配一个角色。

所以在你想要的某些event handler上,做一些这样的事情。

   //this should be incide an {{#each}} or {{#with}} in order to this._id works, if not use Sessions
   Meteor.users.update({_id:this._id},{$set:{group:newGroup}})

这只是全球性的想法,你应该在允许规则中保护,谁可以编辑用户组,你也可以使用模板助手如

{{if userIsInRole 'nameGroup'}}
  <!-- Show content only available to users in this group -->
{{else}}
  <!-- Some warning access denied template -->
{{/if}}
  

此过程会将一些内容添加到用户的个人资料中,以便应用   可以将所有用户关联在一起

按群组过滤。

Template.example.helpers({
 groupX:function(){
   return Meteor.users.find({group:"X"})
  }
})
  

当他们第一次登录时没有删除我之前为他们设置的内容   他们登录。

这里可能还有很多原因,例如你可以在当前创建的用户中添加一些字段。

Meteor.methods({
       createSimpleUser:function(email){
          return  Accounts.createUser({
                   email:email,
                   password:"test123",
                   firstLogin:false //by default the users login is false.
                })
         }
      })

并在铁路线中创建一个函数(为什么在路由器上?请参阅David Weldon网页上的Overworked helpers)。

   requireEdit = function(){
      var query = Meteor.users.findOne({_id:this.params._id})
      if(query.firstLogin == false){
        this.render('profileEditin') //do some change password here and other stuff
      }else{
        this.next()'
     }
  }

并在onBeforeAction()方法

上调用它

这只是一个想法和演示是一个丑陋的例子,它应该如何工作,祝你好运