MyBB Community Forums

Full Version: How do I filter emails from 1 domain in regsitration?
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hi there,,

I want to allow registration for users that have only emails from a specific domain like: *********@mydomain.com

I want only users from that (@mydomain.com) to register


since the forum is for only university students I want only students who have the univ account to register.

I hope the point is clear Big Grin

~ forum: www.aus-cafe.com ~
You should add your check in
function verify_email()
in inc/datahandlers/user.php file.
can you explain more, plz
I didn't test but it should work.

Open inc/datahandlers/user.php with your favourite code editor.

Find:
		if($mybb->settings['allowmultipleemails'] == 0)
		{
			if(email_already_in_use($user['email'], $user['uid']))
			{
				$this->set_error('email_already_in_use');
				return false;
			}
		}

After add:
		$domain = "example.com";
		$mail = trim($user['mail']);
		
		if(substr($mail, strlen($mail) - strlen($domain) - 1) != "@" . $domain)
		{
			$this->set_error('missing_email');
			return false;
		}

Theoretically it shoukd work. Smile
thnx bro ,, u rock Wink

it worked .. now I want to set a custom error .. saying that : you didnt use the email from that domain..
In inc/languages/english/datahandler_user.lang.php add the following:
$l['userdata_wrong_mail_domain'] = 'you didnt use the email from that domain';
and replace in the code above:
 $this->set_error('missing_email');
with
 $this->set_error('wrong_mail_domain');

I would suggest you a plugin also, it'll be easier to maintain, make use of the datahandler_user_validate hook. Wink
thnx again ....... plug in? .. where is it ?
loooooooooooooooool

something wrong ...... with the code ..

all emails are filterd now even the ones from that domain !!!

please check ur code Confused
Replace
$mail = trim($user['mail']);
with
$mail = trim($user['email']);
Tested .. and working ~

Thnx double bro Smile