Welcome to the Question2Answer Q&A. There's also a demo if you just want to try it out.
+6 votes
566 views
in Q2A Core by
For example limit the registration to only email holders of @myDomain.com r.
Q2A version: 1.8
by
Just follow a similar approach to the one I mentioned in your previous question which, for some reason, you never replied back: http://www.question2answer.org/qa/59636?show=59642#a59642

1 Answer

+3 votes
by

Hi

I had a similar need as I installed Q2A on a website I developed on my workplace. I wanted my collegues to use their professionnal email adress (we just have one domain as to email), and it turned out to be quite simple

  1. I added a check with strpos to the class qa_filter_basic (plugins\qa-filter-basic.php) : strpos($email,'@yourdomain.ext')===false
  2. If the verification fails (the email does not belong to the specified domain), then return a message ("email_conseil_dep") saying only their professionnal mail is allowed. Message that I added - with a translation in French - to fr\qa-lang-users.php (you will have to do it in your specific folder)

This did the job for me. Hope it will be useful for someone out there

Kind regards

Paul V
France


 

by
Hi Paul V...
I know little bit coding.
Can you please explain in step-by-step.
I just want to allow gmail.com, yahoo.com, outlook.com & hotmail.com email address to register & rest of others domain extension email addresses not allowed for registration.
Can you please help.
by
edited by
+1
Hi Alok

You will have to add some verifications in the file qa-filter-basic.php (you can find it in folder qa-include\plugins)

You can (must) insert these verifications in the class qa_filter_basic, more specifically, inside the function filter_email

I had only one domain, so for me that was rather simple. You have four domains, so you will have to combine all four domains in one single condition, and if all 4 checks are false, that means that the new user does not have one of the 4 email adresses you would like to pass.

On the contrary, if he or she has a (for exemple) @gmail.com adress, one of the four checks will return a number (the start position of the string in the email adress), and a number is something different than false, so one of the four checks is not false, thus the entire test is invalid (dont't forget that you're working with the logical operator AND)

so, in your case, the four-fold check would be :

if(strpos($email,'@gmail.com')===false and strpos($email,'@yahoo.com')===false and strpos($email,'@outlook.com')===false and strpos($email,'@hotmail.com')===false){
return qa_lang('users/your_refusal_message');
}

You will then have to add "your_refusal_message" (or whatever code you want to use), and its translation (if you're working in another language than english) in the language-translation file of your Questions2Answers installation, so that the internal Questions2Answers function called qa_lang can use your argument "your_refusal_message".

I have a french installation so my french language file(qa-lang-users.php) is located in qa_lang\fr
You will have to find your own (sorry, I can't help you there), and insert your_refusal_message somewhere in the array with all the codes and their translations

This is the line I added somewhere in the middle
'email_conseil_dep' => 'Seulement votre adresse mail professionelle',

which means (in my case) that if someone want to subscribe with an email adress that does not contain our company's domain name, he or she will be reminded that only a professionnal email adress of our company can be used, and the submission of the form will fail.
Hope this is explicit enough
Kind greetings

Paul
by
If you want, you can try the four-fold condition with this example in a php file

$email = "johntravolta@gmail.com";

if(strpos($email,'@gmail.com')===false and strpos($email,'@yahoo.com')===false and strpos($email,'@outlook.com')===false and strpos($email,'@hotmail.com')===false){
echo "Sorry, you don't have the right email adress";
}
else
echo "You are welcome ".$email;

In this example, it will welcome John Travolta. But if you change .com to .fr, he's no longer welcome
by
Hi Paul....
Many Many Thanks. This is Working. This will help to Stop spammy user registration.
by
It probably won't help as much as you hope it would. A lot of the spammer registrations on my site use Gmail or Yahoo addresses.
Also, instead of modifying core code (which is discouraged b/c the modifications need to be re-applied after every update), you could use my plugin Registration Blocker (https://github.com/ansgarwiechers/q2a-registration-blocker ), which has an option to whitelist allowed mail domains (and block everything else).</shameless plug>
by
edited by
For me it will perfectly do the job, as my use of Q2A is limited to an internal network (we have a lot a tools at the entrance of our network)
And adding my core modifications to un update will take me 3 seconds
But thanks anyway for your comment
And thanks for picking up development of the registration-tool
...