From d47350dd25f2cbe7b4a262385ffc4bc58616e39e Mon Sep 17 00:00:00 2001 From: user Date: Sat, 15 Jun 2024 21:54:21 +0300 Subject: [PATCH 1/2] Updated models and migrations --- backend/blog/migrations/0011_article_user.py | 22 ++++++++++++++++++++ backend/blog/models.py | 2 +- 2 files changed, 23 insertions(+), 1 deletion(-) create mode 100644 backend/blog/migrations/0011_article_user.py diff --git a/backend/blog/migrations/0011_article_user.py b/backend/blog/migrations/0011_article_user.py new file mode 100644 index 0000000..385f0d0 --- /dev/null +++ b/backend/blog/migrations/0011_article_user.py @@ -0,0 +1,22 @@ +# Generated by Django 5.0.6 on 2024-06-14 16:10 + +import django.db.models.deletion +from django.conf import settings +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('blog', '0010_alter_article_options_remove_article_user'), + migrations.swappable_dependency(settings.AUTH_USER_MODEL), + ] + + operations = [ + migrations.AddField( + model_name='article', + name='user', + field=models.ForeignKey(default=1, on_delete=django.db.models.deletion.PROTECT, related_name='user_article', to=settings.AUTH_USER_MODEL, verbose_name='User'), + preserve_default=False, + ), + ] diff --git a/backend/blog/models.py b/backend/blog/models.py index 5553a5a..00df3a0 100644 --- a/backend/blog/models.py +++ b/backend/blog/models.py @@ -46,7 +46,7 @@ class Meta: verbose_name_plural = 'Articles' ordering = ['-created_at'] - # user = ForeignKey(User, verbose_name='User', on_delete=PROTECT, related_name='user_article') + user = ForeignKey(User, verbose_name='User', on_delete=PROTECT, related_name='user_article') title = CharField(max_length=75, verbose_name='Title', unique=True) image = ImageField(upload_to=get_blog_image_path, verbose_name='Image', blank=True) content = TextField(verbose_name='Content') From a7f7dd37fecce5eb693aebd8134213631b5d64a0 Mon Sep 17 00:00:00 2001 From: user Date: Sat, 15 Jun 2024 21:54:43 +0300 Subject: [PATCH 2/2] Added djoser --- COMMANDS.txt | 1 + backend/backend/settings.py | 12 +++++++++++- backend/requirements.txt | 16 ++++++++++++++++ 3 files changed, 28 insertions(+), 1 deletion(-) diff --git a/COMMANDS.txt b/COMMANDS.txt index e6b8a96..56b42f5 100644 --- a/COMMANDS.txt +++ b/COMMANDS.txt @@ -16,6 +16,7 @@ pip install django-cors-headers pip install psycopg2 pip install gunicorn pip install python-dotenv +pip install djoser diff --git a/backend/backend/settings.py b/backend/backend/settings.py index c7763eb..65278ad 100644 --- a/backend/backend/settings.py +++ b/backend/backend/settings.py @@ -41,6 +41,8 @@ 'django.contrib.messages', 'django.contrib.staticfiles', 'rest_framework', + 'rest_framework.authtoken', + 'djoser', 'corsheaders', 'blog.apps.BlogConfig', 'account.apps.AccountConfig', @@ -148,7 +150,7 @@ ], 'DEFAULT_AUTHENTICATION_CLASSES': ( 'rest_framework_simplejwt.authentication.JWTAuthentication', - # 'rest_framework.authentication.TokenAuthentication', + 'rest_framework.authentication.TokenAuthentication', 'rest_framework.authentication.BasicAuthentication', 'rest_framework.authentication.SessionAuthentication', ), @@ -158,6 +160,14 @@ ] } +DJOSER = { + 'PASSWORD_RESET_CONFIRM_URL': '#/password/reset/confirm/{uid}/{token}', + 'USERNAME_RESET_CONFIRM_URL': '#/username/reset/confirm/{uid}/{token}', + 'ACTIVATION_URL': '#/activate/{uid}/{token}', + 'SEND_ACTIVATION_EMAIL': False, + 'SERIALIZERS': {}, +} + SIMPLE_JWT = { "ACCESS_TOKEN_LIFETIME": timedelta(minutes=5), "REFRESH_TOKEN_LIFETIME": timedelta(days=1), diff --git a/backend/requirements.txt b/backend/requirements.txt index 2c1c688..3badfbf 100644 --- a/backend/requirements.txt +++ b/backend/requirements.txt @@ -1,13 +1,29 @@ asgiref==3.8.1 +certifi==2024.6.2 +cffi==1.16.0 +charset-normalizer==3.3.2 +cryptography==42.0.8 +defusedxml==0.8.0rc2 Django==5.0.6 django-cors-headers==4.3.1 +django-templated-mail==1.1.1 djangorestframework==3.15.1 djangorestframework-simplejwt==5.3.1 +djoser==2.2.3 gunicorn==22.0.0 +idna==3.7 +oauthlib==3.2.2 packaging==24.1 pillow==10.3.0 psycopg2==2.9.9 +pycparser==2.22 PyJWT==2.8.0 python-dotenv==1.0.1 +python3-openid==3.2.0 +requests==2.32.3 +requests-oauthlib==2.0.0 +social-auth-app-django==5.4.1 +social-auth-core==4.5.4 sqlparse==0.5.0 typing_extensions==4.12.1 +urllib3==2.2.1