Conditionally allow new user registration

Hello,
I am new to Discourse administration/development, and do not speak Ruby (yet – though I’m totally willing to learn). My first task was set up a Discourse installation and I’ve done that on on Digital Ocean using the official docker image. So far so good – shout out to the people who made it so easy!

My next task is more challenging (for me). I have volunteered to set up this Discourse for a non-profit organization that wants to restrict user registration and participation to members of that organization. So I need to somehow modify, or hook into, (or replace?) the new user creation process so that we programmatically check whether the submitted email address matches that of a current member of an existing organization, and whether the member’s expiration date is in the future.

The organization uses NeonCRM, and they provide an API that makes this verification reasonably easy. Discourse, as I understand it, provides an API that also lets you do anything you can do manually. So it’s more than theoretically possible to do what I want to do, right? The question is what is the best approach.

If, for example, Discourse lets you write an event listener (or plugin?) that observes the new user signup, does this verification logic, and can abort the registration with an informative message I can somehow display (“Sorry, you need to be a members of The XYZ Association”) – that would be brilliant.

Alternatively, I can imagine writing my own user-registration page (in PHP, a language I know well) that would use both APIs. But then I would need to somehow hack my Discourse installation so that the sign-up page redirects the user to my custom version.

So I would love to hear some suggestions as to what the overall strategy should look like, and where I should look to start learning how to do this.

Many thanks!

2 Likes

You can limit registrations by email domain and if your users all use the same one, no one from outside that organization will be able to join. In settings search for allowed email domains.

A pipe-delimited list of email domains that users MUST register accounts with. WARNING: Users with email domains other than those listed will not be allowed!*

2 Likes

Ah, that could work if the set of possible domains were limited to a reasonable size, but in this case the email addresses are arbitrary. Thanks for the suggestion.

2 Likes

Does this help?

https://developer.neoncrm.com/api/accounts/authenticating-users/

@Jonathan5 thanks for the suggestion. I looked through that thread and frankly it looks like a nightmare. What’s more, the members of this association are not using NeonCRM directly to log into anything, only the association managers do. It’s complicated.

I had another thought. I have Discourse set up as invitation-only. Suppose I were to leave it that way, but modify the text of the login page to say something like “please go to my.example.org/discourse-invitation to request an invitation.” And at that URL I would have my script that uses the NeonCRM API to verify the prospective user’s membership, uses the Discourse API to create the user (if verification passes), and sends them the invitation. I think my reasoning here is sound. Am I right?