Send confirmation email after signup

This commit is contained in:
aldrin 2021-04-14 10:55:23 +02:00
parent c040a5077a
commit a6300d0388
3 changed files with 21 additions and 1 deletions

4
requirements.txt Normal file
View file

@ -0,0 +1,4 @@
setuptools~=56.0.0
django~=2.2.13
djangorestframework~=3.12.4
djoser~=2.1.0

View file

@ -1,6 +1,7 @@
from django.contrib.auth.base_user import AbstractBaseUser, BaseUserManager from django.contrib.auth.base_user import AbstractBaseUser, BaseUserManager
from django.contrib.auth.models import PermissionsMixin from django.contrib.auth.models import PermissionsMixin
from django.contrib.auth.validators import UnicodeUsernameValidator from django.contrib.auth.validators import UnicodeUsernameValidator
from django.core.mail import send_mail
from django.db import models from django.db import models
from django.utils import timezone from django.utils import timezone
from django.utils.translation import gettext_lazy as _ from django.utils.translation import gettext_lazy as _
@ -34,7 +35,7 @@ class UserManager(BaseUserManager):
if extra_fields.get('is_superuser') is not True: if extra_fields.get('is_superuser') is not True:
raise ValueError('Superuser must have is_superuser=True.') raise ValueError('Superuser must have is_superuser=True.')
return self._create_user(username, email, password, **extra_fields) return self._create_user(email, password, **extra_fields)
class User(AbstractBaseUser, PermissionsMixin): class User(AbstractBaseUser, PermissionsMixin):

View file

@ -134,3 +134,18 @@ STATIC_URL = '/static/'
MEDIA_ROOT = os.path.join(BASE_DIR, 'media') MEDIA_ROOT = os.path.join(BASE_DIR, 'media')
MEDIA_URL = '/media/' MEDIA_URL = '/media/'
# Djoser settings
# https://djoser.readthedocs.io/en/2.1.0/settings.html
DJOSER = {
"ACTIVATION_URL": "confirm/{uid}/{token}",
"SEND_ACTIVATION_EMAIL": True,
}
# Sending email
# https://docs.djangoproject.com/en/3.2/topics/email/
EMAIL_BACKEND = 'django.core.mail.backends.console.EmailBackend'