*

selixa

  • *
  • 2 posts
email domain whitelist
« on: October 28, 2024, 05:04:45 PM »
Hello there.
I discover OsClass and it's awesome.

I have a special need, I have to limit registration to people of my association only. The best way to do it IMO is to restrict subscription by email domain.
It's exactly like email ban rules, but reversed. This can help everyone using osclass in a closed community.

what do you think ?
If I can be of any help, please contact me ;)

Thanks a lot.

*

MB Themes

Re: email domain whitelist
« Reply #1 on: October 28, 2024, 05:43:39 PM »
Easiest would be to add email domain check before user record is entered into db.
  To get fast support, we need following details: Detail description, URL to reproduce problem, Screenshots

*

selixa

  • *
  • 2 posts
Re: email domain whitelist
« Reply #2 on: October 29, 2024, 11:47:36 AM »
Absolutely

*

MB Themes

Re: email domain whitelist
« Reply #3 on: October 30, 2024, 09:00:14 PM »
Try this. Place it to functions.php of theme.

Code: [Select]
// Whitelist user email domain
function whitelist_email_domain($user) {
  $whitelist_domains = array('gmail.com','hotmail.com');
  $email = trim((string)osc_esc_html(Params::getParam('s_email')));

  if($email != '') {
    $mail_parts = explode('@', $email);
    $mail_domain = @$mail_parts[1];

    if(!in_array($mail_domain, $whitelist_domains)) {
      osc_add_flash_error_message(__('Your mail domain is not allowed, registration process was stoped!', 'theme_name'));
      header('Location:' . osc_register_account_url()); 
      exit;
    }
  }
}

osc_add_hook('before_user_register', 'whitelist_email_domain');
  To get fast support, we need following details: Detail description, URL to reproduce problem, Screenshots