Please upgrade here. These earlier versions are no longer being updated and have security issues.
HackerOne users: Testing against this community violates our program's Terms of Service and will result in your bounty being denied.
Limit registrations to specific emails/domains.
Anonymoose
✭✭
Looking for someone to point me in the right direction on how to write an addon to limit registrations from a specific domain, ie. only emails@someplace.org for example.
Tagged:
0
Best Answer
-
Todd Vanilla StaffHere is the event you tie into:
public function UserModel_BeforeRegister_Handler($Sender, $Args) {
$User = $Args['User'];
if (!StringEndsWith($User['Email'], '@someplace.org') {
$Sender->Validation->AddValidationResult('Email', 'We only allow people from someplace.org');
$Args['Valid'] = FALSE;
}
}6
Answers
@Anonymoose, did you build a plugin with todd's Code? I would like to use it!
Sorry, not yet.
Hmm, i dont know where to put the code from Todd.
inside Google Sign In plugin, or whatever authentication plugin you are using
Now trying to build my first plugin for Vanilla. Coming up with this:
Parse error: syntax error, unexpected '{' in /home/forum/html/plugins/LimitRegistrations/default.php on line 19
This is the line: if (!StringEndsWith($User['Email'], '@someplace.org') {
not sure why. The other { } are balanced...
Fixed.
Changing line 19 to this:
if (!(preg_match("/someplace.org$/i", $User['Email']))) {
Plugin uploaded: http://vanillaforums.org/addon/limitregistrations-plugin
Yes. After all, I did, and it is now posted as the LimitRegistrations plugin. The next step might be to add more features like limiting registrations by IP and so on and to add configuration form the dashboard. Otherwise, it just works.
At which line to add fake email
@Anonymoose the plugin need update for vanilla 2.3
@Todd Could you also take a look? the piece of code might not work under 2.3
Never mind, just replace $User['Email'] above into $Args['RegisteringUser']['Email']