Restrict registration to specific email addresses

Permalink 1 user found helpful
Is it possible to restrict registration to specific email addresses (eg., only those with @myschool.com can register)?

 
mkly replied on at Permalink Reply
mkly
I'm not sure of your experience and particular skill set but there is a controller in
/concrete/controllers/register.php

you can override this by copying that file to
/controllers/register.php

There is a method in there called 'do_register'
This is where the magic happens including validation. You could add an additional validation for the $_POST['uEmail']

If you are curious about the validation the simplest thing is that $e is the error helper. You can do some php to check $_POST['uEmail'] and if it fails you can do
$e->add('Registrations are only allowed from @example.com');

The method will pick this up at the bottom and not register the new user but instead show the error above.
agpate replied on at Permalink Reply
Thanks MLKY. I think I'm JUST about at the level where that makes sense. I'll try it out on a test site first. I appreciate you taking the time to respond. Thanks.

:-)
agpate replied on at Permalink Reply
Drat. Clearly I'm not nearly as well-versed in this as I thought I was. (thumps head).

I found the file and I understand the principle of what needs to be done. Unfortunately, my knowledge of PHP is ... well, dire. I'll try doing an online search to see if I can find what exactly needs to be written to only allow @myaddress.com (or whatever). Once I have that, I think I'll be fine. :-)
mkly replied on at Permalink Best Answer Reply
mkly
if(!preg_match('/@example\.com$/', $_POST['uEmail'])) {
  $e->add('Registrations are only allowed from @example.com');
}

Should do it.
agpate replied on at Permalink Reply
Thanks for that! Very much appreciated. :-)