Osclass Support Forums

Osclass plugin support => Other => Topic started by: oscman on December 23, 2019, 12:32:42 PM

Title: Allow only specific email providers
Post by: oscman on December 23, 2019, 12:32:42 PM
Hello, i have this function so people can register only with gmail and hotmail, when i try to register it works gr8 but i still see spambots registering under different email domains and bypass this code, any idea how they do it?

Code: [Select]
function cust_restrict_mail_providers() {

    $authorized_providers = array(
        'gmail.com',
        'hotmail.com'
    );
    $current_provider = preg_replace('/^.*@(.*)$/i', '$1', Params::getParam('s_email'));

    if (!in_array($current_provider, $authorized_providers)) {
        osc_add_flash_error_message( _m('Your current email is not allowed'));
        osc_redirect_to(osc_register_account_url());
    }
}

osc_add_hook('before_user_register', 'cust_restrict_mail_providers');
Title: Re: Allow only specific email providers
Post by: MB Themes on December 23, 2019, 02:19:21 PM
Code looks OK, but try to put:
Code: [Select]
exit;
after line:
Code: [Select]
osc_redirect_to(osc_register_account_url());
Title: Re: Allow only specific email providers
Post by: oscman on December 23, 2019, 09:14:51 PM
Thanks will see if it makes change
Title: Re: Allow only specific email providers
Post by: Sanjay Srivastava on April 20, 2022, 07:52:26 AM
Hello There ,

I also want to restrict users for registration, where i have to paste this code (in which file ).. I want to allow only some popular email server like gmail.com, live.com and more.. Because too many fake registration in my website.   

I have tried to put this code in user registration php file but not working . Please help me to solve the issue.   

<?php
function cust_restrict_mail_providers() {

    $authorized_providers = array(
        'hotmail.com',
        'mail.live.com',
        'live.com',
        'gmail.com'
    );
    $current_provider = preg_replace('/^.*@(.*)$/i', '$1', Params::getParam('s_email'));

    if (in_array($current_provider, $authorized_providers)) {
        osc_add_flash_error_message( _m('Accounts not allowed'));
        osc_redirect_to(osc_register_account_url());
      exit;
    }
}

osc_add_hook('before_user_register', 'cust_restrict_mail_providers');
?>


Thanks
Title: Re: Allow only specific email providers
Post by: Sanjay Srivastava on April 20, 2022, 07:05:33 PM

Please reply

Code looks OK, but try to put:
Code: [Select]
exit;
after line:
Code: [Select]
osc_redirect_to(osc_register_account_url());
Title: Re: Allow only specific email providers
Post by: MB Themes on April 20, 2022, 08:03:01 PM
You can place it into functions.php of theme
Title: Re: Allow only specific email providers
Post by: Sanjay Srivastava on April 20, 2022, 08:13:28 PM
Thanks for Reply.

I have pasted this code into functions.php but still I am able to register fake account. [email protected]

<?php
function cust_restrict_mail_providers() {

    $authorized_providers = array(
        'hotmail.com',
        'mail.live.com',
        'live.com',
        'gmail.com'
    );
    $current_provider = preg_replace('/^.*@(.*)$/i', '$1', Params::getParam('s_email'));

    if (in_array($current_provider, $authorized_providers)) {
        osc_add_flash_error_message( _m('Accounts not allowed'));
        osc_redirect_to(osc_register_account_url());
      exit;
    }
}

osc_add_hook('before_user_register', 'cust_restrict_mail_providers');
?>


You can place it into functions.php of theme
Title: Re: Allow only specific email providers
Post by: MB Themes on April 20, 2022, 08:20:30 PM
I would double check if email field on register page has nane s_email and then I think condition should be !in_array(...
Title: Re: Allow only specific email providers
Post by: Sanjay Srivastava on April 20, 2022, 09:11:01 PM
Thanks for your Reply. Now its working.  :) :)

I would double check if email field on register page has nane s_email and then I think condition should be !in_array(...
Title: Re: Allow only specific email providers
Post by: MB Themes on April 21, 2022, 10:45:26 AM
I would just summarize final code.

Code: [Select]
// restrict particular email domains
function cust_restrict_mail_providers1() {
    $authorized_providers = array(
        'hotmail.com',
        'mail.live.com',
        'live.com',
        'gmail.com'
    );

    $current_provider = preg_replace('/^.*@(.*)$/i', '$1', Params::getParam('s_email'));

    if (in_array($current_provider, $authorized_providers)) {
        osc_add_flash_error_message(_m('Email domain is blocked'));
        osc_redirect_to(osc_register_account_url());
      exit;
    }
}

osc_add_hook('before_user_register', 'cust_restrict_mail_providers1');

// only allow particular email domains
function cust_restrict_mail_providers2() {
    $authorized_providers = array(
        'hotmail.com',
        'mail.live.com',
        'live.com',
        'gmail.com'
    );

    $current_provider = preg_replace('/^.*@(.*)$/i', '$1', Params::getParam('s_email'));

    if (!in_array($current_provider, $authorized_providers)) {
        osc_add_flash_error_message(_m('Email domain is not allowed'));
        osc_redirect_to(osc_register_account_url());
      exit;
    }
}

osc_add_hook('before_user_register', 'cust_restrict_mail_providers2');

Title: Re: Allow only specific email providers
Post by: Sanjay Srivastava on April 21, 2022, 11:11:46 AM
Thanks for reply.. but its already working