mediacms/users/adapter.py

27 lines
1.2 KiB
Python
Raw Permalink Normal View History

2020-12-15 22:33:43 +01:00
from allauth.account.adapter import DefaultAccountAdapter
2021-05-26 17:35:21 +02:00
from django.conf import settings
2020-12-15 22:33:43 +01:00
from django.core.exceptions import ValidationError
2021-05-26 17:35:21 +02:00
from django.urls import reverse
2020-12-15 22:33:43 +01:00
class MyAccountAdapter(DefaultAccountAdapter):
def get_email_confirmation_url_stub(self, request, emailconfirmation):
url = reverse("account_confirm_email", args=[emailconfirmation.key])
return settings.SSL_FRONTEND_HOST + url
def clean_email(self, email):
2024-11-20 12:17:25 +01:00
if hasattr(settings, "ALLOWED_DOMAINS_FOR_USER_REGISTRATION") and settings.ALLOWED_DOMAINS_FOR_USER_REGISTRATION:
if email.split("@")[1] not in settings.ALLOWED_DOMAINS_FOR_USER_REGISTRATION:
raise ValidationError("Domain is not in the permitted list")
2024-11-20 12:17:25 +01:00
2020-12-15 22:33:43 +01:00
if email.split("@")[1] in settings.RESTRICTED_DOMAINS_FOR_USER_REGISTRATION:
raise ValidationError("Domain is restricted from registering")
return email
def is_open_for_signup(self, request):
return settings.USERS_CAN_SELF_REGISTER
def send_mail(self, template_prefix, email, context):
msg = self.render_mail(template_prefix, email, context)
msg.send(fail_silently=True)