Commit 31545002 authored by Noe Nieto's avatar Noe Nieto 💬

Recovery email must additionally not be associated with existing WooCommerce...

Recovery email must additionally not be associated with existing WooCommerce account; liberty/ldh_middleware#79
parent 49a0e7f0
......@@ -43,6 +43,16 @@ def get_woo_connection():
)
def woo_email_available_validator(value):
wc = get_woo_connection()
result = wc.get('customers?email={}'.format(value))
if result.ok and len(result.json()) > 0:
raise validators.ValidationError(
_('%(email)s is already being used'),
params={'email':value}
)
@deconstructible
class UsernameValidator(validators.RegexValidator):
regex = r'^[A-Za-z][A-Za-z0-9]*$'
......@@ -76,7 +86,7 @@ class User(AbstractUser):
max_length=150,
unique=True,
help_text=_('Required. Start with a letter, followed by letters or numbers.'),
validators=[username_validator],
validators=[username_validator, woo_email_available_validator],
error_messages={
'unique': _("An account with that address already exists."),
},
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment