注册和登录与Meteor.loginWithExternalService区分() [英] Distinguishing between Sign Up and Sign In with Meteor.loginWithExternalService()

查看:303
本文介绍了注册和登录与Meteor.loginWithExternalService区分()的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

流星提供了一组 loginWithExternalService()方法(如 loginWithTwitter()),让用户可以创建帐户或重新登录与这些第三方身份验证提供者。

Meteor provides a set of loginWithExternalService() methods (such as loginWithTwitter()) that lets users either create accounts or log back in with these third-party auth providers.

但是,有没有办法既行为区别开来?即让人们的登录的与Twitter,而不必让他们的它通过同样的动作签署的?

But is there a way to distinguish between both actions? i.e. let people sign in with Twitter without necessarily letting them sign up with it via the same action?

实际使用情况是在哪里注册人数被限制一个网站,你有一个私人网址​​签署的最多的,但是签署一个公共页面的的。我正在寻找一种方式来prevent人能够通过登录首次只需创建帐户。

The practical use case is for a site where sign-ups are restricted and you have a private URL for signing up, but a public page for signing in. I'm looking for a way to prevent people from being able to create accounts simply by signing in for the first time.

推荐答案

您也许可以挂接到 Accounts.onCreateUser (服务器端)

You could probably hook into Accounts.onCreateUser (server side)

像这样的东西可能有帮助:

Something like this might help:

服务器端的js

Accounts.onCreateUser(function(options, user) {

  //Check if this user can be created, if not throw an error
  var canCreate = false

  if(!canCreate) 
      throw new Meteor.Error(403, 'You cant sign up', "Sorry you can only sign in but not sign up");

  //Create the user like normal if we can.
  if (options.profile)
    user.profile = options.profile;
  return user;
});

这回并创建一个帐户抛出错误prevents方法。它仅当有人正在创建帐户运行,并没有已经有一个(外部服务提供者太)

Throwing the error prevents the method from returning and creating an account. It only runs if someone is creating an account and doesn't already have one (external service providers too)

在客户端可以处理错误,但在帐户的用户界面包你得到一个内部服务器错误的信息。你也许可以自定义此为你需要一个管理员'什么的。

On the client you can handle the error but on the accounts-ui package you get an 'internal server error' message. You could probably customize this to 'you need to be an admin' or something

这篇关于注册和登录与Meteor.loginWithExternalService区分()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆