Jump to content

Allow only emails from specific domain to register


Recommended Posts

Hi guys! Im creating a store for a company that only wants to allow people with @thecompany.com domain to register. (they are going to sell products with big discounts only for their workers)

 

Is there a way to allow only emails from specific domain to register and buy?

 

[email protected] ---> NOT ALLOWED

[email protected] --> ALLOWED

 

 

Thanks a lot in advance, any help would be apreciate it because im a litlle bit lost :)

 

 

Link to comment
Share on other sites

 

Thanks a lot Nemo1. My code knowledge is not very good, but I will definetly give it a try.

 

I found this option by Vekia, but I dont really understand it very well

 

you can check email in function (validate class).

use there this simple regular expression:

^[A-Z0-9._%+-]+@fake.com$

 

Is there a way to validate the domain just changing the validate.php?

 

Thanks a lot in advance. I hope I can figure this out!!

Link to comment
Share on other sites

Hello

 

I assume it is not possible to put the site into catalogue mode and then add the employees to a group that would have access to the site.

 

Paul

 

 

Hi Paulito, that is the plan B. The problem is the company wants this to be "automatic", so they dont have to validate every register one by one.

Link to comment
Share on other sites

Hi guys, I think the isEmail function in the Classes/Validate.php is the key, but I cant make it work (parse error everytime)

	public static function isEmail($email)
	{
		return !empty($email) && preg_match(Tools::cleanNonUnicodeSupport('/^[a-z\p{L}0-9!#$%&\'*+\/=?^`{}|~_-]+[.a-z\p{L}0-9!#$%&\'*+\/=?^`{}|~_-]*@[a-z\p{L}0-9]+(?:[.]?[_a-z\p{L}0-9-])*\.[a-z\p{L}0-9]+$/ui'), $email);
	}

I try to implement the code Vekia gave in another post

^[A-Z0-9._%+-][email protected]$

Any help would be awesome. Thanks in advance

Link to comment
Share on other sites

Hi bellini, thanks for the response. I managed to do it after a lot of testing and errors. Im going to put it here in case someone else need it

 

You have to go to Classes/Validate.php and change the function isEmail like this:

public static function isEmail($email)
	{
		return !empty($email) && preg_match(Tools::cleanNonUnicodeSupport('/^[a-z\p{L}0-9!#$%&\'*+\/=?^`{}|~_-]+[.a-z\p{L}0-9!#$%&\'*+\/=?^`{}|~_-]*@fake.[com]+$/ui'), $email);
	}

That will only allow @fake.com emails to be used in the website. (careful! Even administrator!)

 

 

But to crown things off, I want to try to duplicate isEmail function, so this rule only apply to the user register process and I still can use @gmail.com as administrator. I tried to duplicate the function calling it Validation2, and calling it in Authentication.tpl but I can not make it work  :(

 

This is the code im using. I hope someone can give me a hand

 

Validation.php

public static function isEmail($email)
	{
		return !empty($email) && preg_match(Tools::cleanNonUnicodeSupport('/^[a-z\p{L}0-9!#$%&\'*+\/=?^`{}|~_-]+[.a-z\p{L}0-9!#$%&\'*+\/=?^`{}|~_-]*@[a-z\p{L}0-9]+(?:[.]?[_a-z\p{L}0-9-])*\.[a-z\p{L}0-9]+$/ui'), $email);
	}



public static function validation2($email)
	{
		return !empty($email) && preg_match(Tools::cleanNonUnicodeSupport('/^[a-z\p{L}0-9!#$%&\'*+\/=?^`{}|~_-]+[.a-z\p{L}0-9!#$%&\'*+\/=?^`{}|~_-]*@fake.[com]+$/ui'), $email);
	}

and then, in authentication.tpl

<div class="required form-group">
				<label for="email">{l s='Email'} <sup>*</sup></label>
				<input type="email" class="is_required validate form-control" data-validate="validation2" id="email" name="email" value="{if isset($smarty.post.email)}{$smarty.post.email}{/if}" />
			</div>

If I do this, prestashop only recognize the first isEmail function, and ignore the second one (@fake.com)

 

Im sorry if my mistake is obvious, as I said before my code knowledge is kinda poor.

 

 

Thanks in advance!!!

Link to comment
Share on other sites

The validation occurs in 2 places, we call that client side and server side

 

The code you added to Validate.php is server side, and is executed after you try to submit the form to the server.  This is handled by the AuthController

 

The code you changed in authentication.tpl is client side and is executed when you type or leave focus of the email input field.  This is handled via javascript, and the isEmail function for this is located in \js\validate.js.  There is a javascript function called validate_isEmail

 

The problem you are going to have is that you cannot assign 2 different server side validators to the same input field. 

So as I suggested before, you should leave the isEmail validate function alone so that it does its job and validates that the value is a valid formatted email.

 

Then you add your own condition (perhaps in AuthController), that the email provided "ends with" fake.com

Link to comment
Share on other sites

×
×
  • Create New...