Dj rest auth и allauth возвращают неверный формат электронной почты
Я создаю API, используя DJ rest auth и allauth для регистрации и входа. Я настроил формат электронной почты для регистрации с помощью пользовательских адаптеров. Всякий раз, когда я тестирую его на localhost, он возвращает желаемый формат электронной почты, а именно:
Dear TestUser1,
Welcome to Ekopages, your gateway to sustainable education!
We're thrilled to have you join our community. To get started on your journey towards a greener future, please click the link below to confirm your email address:
https://ekopages.com/registration/account-confirm-email/NTE:1rUpCQ:qimz8K0QFUD5ZM8WbMlmcBqq3HSzNp0vNSziMaJRV44/
Once confirmed, you'll have full access to ekopages.com, where learning meets sustainability.
Thank you for choosing Ekopages. Let's embark on this educational adventure together!
Green regards,
The EkoPages Team.
ekopages.com
после того, как я развернул его, он просто возвращает формат, который я не добавил
Hello from !
Dear testuser,
Welcome to Ekopages, your gateway to sustainable education!
We're thrilled to have you join our community. To get started on your
journey towards a greener future, please click the link below to
confirm your email address:
https://ekopages.com/registration/account-confirm-email/NjI:1rWQ5A:ZKz5BArUgGzhT8tP8KKIuV62vGdVzBQ3blPHALsxWAE/
Once confirmed, you'll have full access to ekopages.com, where
learning meets sustainability.
Thank you for using !
Я тоже настраивал регистрацию и адаптеры, так что не знаю, откуда взялся этот "привет от!"
#models.py
from django.db import models
from django.contrib.auth.models import AbstractBaseUser, BaseUserManager, PermissionsMixin
from django.utils import timezone
class UserManager(BaseUserManager):
def _create_user(self, username, email, password, is_staff, is_superuser, address, **extra_fields):
now = timezone.now()
if not username:
raise ValueError(('The given username must be set'))
email = self.normalize_email(email)
user = self.model(username=username, email=email,
is_staff=is_staff, is_active=True,
is_superuser=is_superuser, last_login=now,
date_joined=now, address=address, **extra_fields)
user.set_password(password)
user.save(using=self._db)
return user
def create_user(self, username, email=None, password=None, **extra_fields):
return self._create_user(username, email, password, False, False, True,
**extra_fields)
def create_superuser(self, username, email, password, **extra_fields):
user=self._create_user(username, email, password, True, True,
**extra_fields)
user.is_active=True
user.save(using=self._db)
return user
class User(AbstractBaseUser, PermissionsMixin):
first_name = models.CharField(max_length=250, blank=True)
last_name = models.CharField(max_length=250, blank=True)
email = models.EmailField(('email address'), unique=True)
username = models.CharField(max_length=50, unique=True, blank=False, default='username')
profile_picture = models.ImageField(upload_to='Pictures', blank=True)
created_at = models.DateField(auto_now_add=True)
is_admin = models.BooleanField(default=False)
is_active = models.BooleanField(default=True)
#subscription_start_dates = models.DateField(null=True, blank=True)
#subscription_end_dates = models.DateField(null=True, blank=True)
objects = UserManager()
USERNAME_FIELD = 'username'
REQUIRED_FIELDS = ['email',]
def get_full_name(self):
return self.email
def get_short_name(self):
return self.email
def __unicode__(self):
return self.email
def has_perm(self, perm, obj=None):
return True
def has_module_perms(self, app_label):
return True
@property
def is_staff(self):
return self.is_admin
#serializers.py
from rest_framework import serializers
from allauth.account import app_settings as allauth_settings
from allauth.account.adapter import get_adapter
from allauth.account.utils import setup_user_email
from allauth.socialaccount.helpers import complete_social_login
from allauth.socialaccount.models import SocialAccount
from allauth.socialaccount.providers.base import AuthProcess
from allauth.utils import email_address_exists, get_username_max_length
from dj_rest_auth.serializers import UserDetailsSerializer
from .models import User
class RegisterSerializer(serializers.Serializer):
first_name = serializers.CharField(required=True, write_only=True)
last_name = serializers.CharField(required=True, write_only=True)
email = serializers.EmailField(required=allauth_settings.EMAIL_REQUIRED)
username = serializers.CharField(required=True, write_only=True)
password1 = serializers.CharField(required=True, write_only=True)
password2 = serializers.CharField(required=True, write_only=True)
def validate_email(self, email):
email = get_adapter().clean_email(email)
if allauth_settings.UNIQUE_EMAIL:
if email and email_address_exists(email):
raise serializers.ValidationError(
("A user is already registered with this e-mail address."))
return email
def validate_password1(self, password):
return get_adapter().clean_password(password)
def validate(self, data):
if data['password1'] != data['password2']:
raise serializers.ValidationError(
("The two password fields didn't match."))
return data
def get_cleaned_data(self):
return {
'password1': self.validated_data.get('password1', ''),
'email': self.validated_data.get('email', ''),
'username': self.validated_data.get('username', ''),
'first_name': self.validated_data.get('first_name', ''),
'last_name': self.validated_data.get('last_name', ''),
}
def save(self, request):
adapter = get_adapter()
user = adapter.new_user(request)
self.cleaned_data = self.get_cleaned_data()
adapter.save_user(request, user, self)
setup_user_email(request, user, [])
first_name = self.cleaned_data.get('first_name')
last_name = self.cleaned_data.get('last_name')
user.first_name = first_name
user.last_name = last_name
user.save()
return user
class UserDetailsSerializer(UserDetailsSerializer):
class Meta:
fields = ['username','email','profile_picture','first_name', 'last_name'] #'subscription_start_dates', 'subscription_end_dates']
read_only_fields = ['username','email',]#' subscription_end_dates', 'subscription_start_dates'
model = User
#settings.py
AUTH_USER_MODEL = 'Account.User'
REST_AUTH_REGISTER_SERIALIZERS = {
'REGISTER_SERIALIZER': 'Account.serializers.RegisterSerializer'
}
REST_AUTH_SERIALIZERS = {
'USER_DETAILS_SERIALIZER': 'Account.serializers.UserDetailsSerializer',
}
#adapters.py
from allauth.account.adapter import DefaultAccountAdapter
from django.contrib.sites.shortcuts import get_current_site
from django.urls import reverse
from django.core.mail import EmailMessage
from django.template.loader import render_to_string
class CustomAccountAdapter(DefaultAccountAdapter):
def send_confirmation_mail(self, request, emailconfirmation, signup):
current_site = get_current_site(request)
activate_url = reverse(
"account_confirm_email",
args=[emailconfirmation.key],
)
activate_url = "https://ekopages.com" + activate_url
ctx = {
"user": emailconfirmation.email_address.user,
"activate_url": activate_url,
"site_name": current_site.name,
"site_domain": current_site.domain,
}
subject = render_to_string("templates/account/email_subject.txt", ctx)
subject = subject.strip()
email_body = render_to_string("templates/account/email_message.txt", ctx)
msg = EmailMessage(subject, email_body, to=[emailconfirmation.email_address.email])
msg.send()
#email message body
{% extends "account/email/base_message.txt" %}
{% load account %}
{% load i18n %}
{% block content %}
{% autoescape off %}
{% user_display user as user_display %}
{% blocktrans with site_name="EkoPages" site_domain="ekopages.com" %}
Dear {{ user_display }},
Welcome to Ekopages, your gateway to sustainable education!
We're thrilled to have you join our community. To get started on your journey towards a greener future, please click the link below to confirm your email address:
{{ activate_url }}
Once confirmed, you'll have full access to {{ site_domain }}, where learning meets sustainability.
{% endblocktrans %}
{% endautoescape %}
{% endblock %}
Я не понимаю, в чем дело. Пожалуйста, любая помощь будет оценена по достоинству