mediacms/users/adapter.py

23 lines
891 B
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):
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)