From 369b33de6fcb86313fd5161d075b5396c6530649 Mon Sep 17 00:00:00 2001 From: ayxan Date: Thu, 8 Dec 2022 09:33:57 +0400 Subject: [PATCH] Added 'send_email' feature --- requirements.txt | 8 ++- src/account/admin.py | 4 +- src/account/forms/profile_editing.py | 2 +- src/account/forms/register.py | 3 +- src/account/models.py | 9 +++- src/account/templates/profile_detail.html | 28 ++++++++--- src/account/templates/profile_editing.html | 5 +- src/account/templates/register.html | 12 +++-- src/account/urls.py | 1 + src/account/views/__init__.py | 5 +- src/account/views/email_activate.py | 21 ++++++++ src/account/views/profile_editing.py | 55 ++++++++++++--------- src/account/views/register.py | 47 +++--------------- src/account/views/send_otp.py | 45 +++++++++++++++++ src/series/tasks.py | 2 +- src/static/icons/false.png | Bin 0 -> 10833 bytes src/static/icons/true.png | Bin 0 -> 9690 bytes 17 files changed, 161 insertions(+), 86 deletions(-) create mode 100644 src/account/views/email_activate.py create mode 100644 src/account/views/send_otp.py create mode 100644 src/static/icons/false.png create mode 100644 src/static/icons/true.png diff --git a/requirements.txt b/requirements.txt index a0de788..1a61be7 100644 --- a/requirements.txt +++ b/requirements.txt @@ -10,25 +10,29 @@ click-didyoumean==0.3.0 click-plugins==1.1.1 click-repl==0.2.0 Deprecated==1.2.13 -Django==4.1 +Django==4.0.8 django-autoslug==1.9.8 django-compat==1.0.15 django-crispy-forms==1.14.0 django-environ==0.9.0 +django-ratelimit==4.0.0 django-smtp-ssl==1.0 +django-timezone-field==5.0 idna==3.3 kombu==5.2.4 packaging==21.3 prompt-toolkit==3.0.31 psycopg2==2.9.3 pyparsing==3.0.9 +python-crontab==2.6.0 +python-dateutil==2.8.2 pytz==2022.2.1 redis==4.3.4 requests==2.28.1 six==1.16.0 sqlparse==0.4.2 +tzdata==2022.5 urllib3==1.26.12 vine==5.0.0 wcwidth==0.2.5 wrapt==1.14.1 -gunicorn \ No newline at end of file diff --git a/src/account/admin.py b/src/account/admin.py index ed2c911..2673829 100644 --- a/src/account/admin.py +++ b/src/account/admin.py @@ -8,7 +8,7 @@ class CustomAdmin(UserAdmin): fieldsets = ( (None, {'fields': ('username', 'email', 'password')}), (('Permissions'), { - 'fields': ('is_active', 'email_notification_is_active', 'is_staff', 'is_superuser', 'groups', 'user_permissions'), + 'fields': ('is_active', 'email_is_verified', 'send_email', 'is_staff', 'is_superuser', 'groups', 'user_permissions'), }), (('Important dates'), {'fields': ('last_login', 'date_joined')}), ) @@ -19,7 +19,7 @@ class CustomAdmin(UserAdmin): }), ) list_display = ('username', 'email', 'is_staff') - list_filter = ('is_staff', 'email_notification_is_active', 'is_superuser', 'is_active', 'groups') + list_filter = ('is_staff', 'email_is_verified', 'send_email', 'is_superuser', 'is_active', 'groups') search_fields = ('email',) ordering = ('email',) filter_horizontal = ('groups', 'user_permissions',) \ No newline at end of file diff --git a/src/account/forms/profile_editing.py b/src/account/forms/profile_editing.py index 1403837..4c1dd3e 100644 --- a/src/account/forms/profile_editing.py +++ b/src/account/forms/profile_editing.py @@ -7,4 +7,4 @@ class ProfileEditingForm(UserChangeForm): class Meta: model = User - fields = ('email', 'username', 'imdb_api_key') \ No newline at end of file + fields = ('email', 'username', 'imdb_api_key', 'send_email') \ No newline at end of file diff --git a/src/account/forms/register.py b/src/account/forms/register.py index 30e8d38..e599aa0 100644 --- a/src/account/forms/register.py +++ b/src/account/forms/register.py @@ -11,4 +11,5 @@ class RegisterForm(UserCreationForm): 'email', 'password1', 'password2', - 'imdb_api_key') + 'imdb_api_key', + 'send_email') diff --git a/src/account/models.py b/src/account/models.py index b75dd8f..b8cee53 100644 --- a/src/account/models.py +++ b/src/account/models.py @@ -5,9 +5,14 @@ from django.contrib.auth.models import AbstractUser class User(AbstractUser): first_name = None last_name = None - email = models.EmailField('email', unique=True, blank=True, null=True) + email = models.EmailField('email', null=True, blank=True, unique=True) imdb_api_key = models.CharField(max_length=15, blank=False, null=False) - email_notification_is_active = models.BooleanField(default=False) + email_is_verified = models.BooleanField(default=False) + send_email = models.BooleanField(default=False) + + def clean(self): + if self.email == '': + self.email = None class Meta: db_table = 'user' diff --git a/src/account/templates/profile_detail.html b/src/account/templates/profile_detail.html index 4dc392a..504bfd8 100644 --- a/src/account/templates/profile_detail.html +++ b/src/account/templates/profile_detail.html @@ -2,19 +2,33 @@ {% load static %} {% block title %} Profile {% endblock title %} - {% block content %}
Username: {{profile.username}}
- {% if profile.email_notification_is_active %} -
Email: {{profile.email|default:""}} - {% static 'icons/verified.png' %} -
- {% else %} -
Email: {{profile.email|default:""}}
+ {% if profile.email %} + {% if profile.email_is_verified %} +
Email: {{profile.email|default:""}} + {% static 'icons/verified.png' %} +
+ {% if profile.send_email %} +
Send Email: + {% static 'icons/true.png' %} +
+ {% else %} +
Send Email: + {% static 'icons/false.png' %} +
+ {% endif %} + {% else %} +
Email: {{profile.email|default:""}} + + Verify + +
+ {% endif %} {% endif %}
IMDB API Key: {{profile.imdb_api_key}}
diff --git a/src/account/templates/profile_editing.html b/src/account/templates/profile_editing.html index 3b86d6f..819fc14 100644 --- a/src/account/templates/profile_editing.html +++ b/src/account/templates/profile_editing.html @@ -9,7 +9,10 @@
{% csrf_token %} - {{form|crispy}} + {{form.username|as_crispy_field}}
+ {{form.email|as_crispy_field}}
+ {{form.imdb_api_key|as_crispy_field}}
+ {{form.send_email|as_crispy_field}}