diff --git a/breathecode/authenticate/serializers.py b/breathecode/authenticate/serializers.py index 2e31329e1..18b0f6395 100644 --- a/breathecode/authenticate/serializers.py +++ b/breathecode/authenticate/serializers.py @@ -21,6 +21,7 @@ from breathecode.events.models import Event from breathecode.registry.models import Asset import breathecode.activity.tasks as tasks_activity +import breathecode.authenticate.tasks as tasks_authenticate from breathecode.marketing.actions import validate_email logger = logging.getLogger(__name__) @@ -1477,10 +1478,7 @@ def get_access_token(self, obj: UserInvite): if obj.status != 'ACCEPTED': return None - email_status = validate_email(obj.email, lang) - obj.email_quality = email_status['score'] - obj.email_status = email_status - obj.save() + tasks_authenticate.validate_email.delay(obj.id) if not self.user: self.user = User(email=obj.email, diff --git a/breathecode/authenticate/tasks.py b/breathecode/authenticate/tasks.py index 5f47bf221..4549e5b6c 100644 --- a/breathecode/authenticate/tasks.py +++ b/breathecode/authenticate/tasks.py @@ -1,6 +1,9 @@ import logging, os from celery import shared_task, Task from django.contrib.auth.models import User +from breathecode.authenticate.models import UserInvite +from breathecode.marketing.actions import validate_email +from breathecode.utils.decorators import task, RetryTask from breathecode.utils.decorators.task import task from .actions import set_gitpod_user_expiration, add_to_organization, remove_from_organization @@ -18,6 +21,27 @@ class BaseTaskWithRetry(Task): retry_backoff = True +@task(bind=True) +def async_validate_email_invite(self, invite_id): + logger.debug(f'Validating email for invite {invite_id}') + user_invite = UserInvite.objects.filter(id=invite_id).first() + + if user_invite is None: + logger.error(f'UserInvite {invite_id} not found') + return + + try: + email_status = validate_email(user_invite.email, 'en') + except: + raise RetryTask(f'Retrying email validation for invite {invite_id}') + + user_invite.email_quality = email_status['score'] + user_invite.email_status = email_status + user_invite.save() + + return True + + @shared_task def async_set_gitpod_user_expiration(gitpoduser_id): logger.debug(f'Recalculate gitpoduser expiration for {gitpoduser_id}') diff --git a/breathecode/marketing/actions.py b/breathecode/marketing/actions.py index 850dd77c7..448be74d7 100644 --- a/breathecode/marketing/actions.py +++ b/breathecode/marketing/actions.py @@ -133,7 +133,7 @@ def validate_email(email, lang): 'El correo electrónico que haz especificado parece inválido, por favor corrige tu correo electronico', slug='invalid-email')) - if 'quality_score' in data and float(data['quality_score']) < 0.60: + if 'quality_score' in data and float(data['quality_score']) <= 0.60: raise ValidationException(translation( lang, en=