From 34259d5977730bde626662614c0eb30f621320cc Mon Sep 17 00:00:00 2001 From: Artur Galyamov Date: Tue, 20 Dec 2022 09:47:43 +0500 Subject: [PATCH] =?UTF-8?q?=D0=A1=D0=BE=D0=B7=D0=B4=D0=B0=D0=BD=D0=B0=20?= =?UTF-8?q?=D0=BE=D1=81=D0=BD=D0=BE=D0=B2=D0=B0=20=D0=B0=D1=83=D1=82=D0=B5?= =?UTF-8?q?=D0=BD=D1=82=D0=B8=D1=84=D0=B8=D0=BA=D0=B0=D1=86=D0=B8=D0=B8=20?= =?UTF-8?q?=D0=BF=D0=BE=D0=BB=D1=8C=D0=B7=D0=BE=D0=B2=D0=B0=D1=82=D0=B5?= =?UTF-8?q?=D0=BB=D1=8F=20#17?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- cms/forms.py | 9 +++++++++ cms/templates/user/sign_in.html | 26 ++++++++++++++++++++++++++ cms/urls.py | 7 ++++++- cms/views.py | 17 +++++++++++++++++ crossposting_backend/urls.py | 2 ++ crossposting_backend/views.py | 8 ++++++++ 6 files changed, 68 insertions(+), 1 deletion(-) create mode 100644 cms/templates/user/sign_in.html create mode 100644 crossposting_backend/views.py diff --git a/cms/forms.py b/cms/forms.py index a2fb53f..48e66aa 100644 --- a/cms/forms.py +++ b/cms/forms.py @@ -1,4 +1,5 @@ from django import forms +from django.contrib.auth import models as auth_models from .models import Article @@ -7,3 +8,11 @@ class ArticleForm(forms.ModelForm): class Meta: model = Article fields = ('body', 'link',) + + +class UserForm(forms.ModelForm): + password = forms.PasswordInput() + + class Meta: + model = auth_models.User + fields = ('username', 'password',) diff --git a/cms/templates/user/sign_in.html b/cms/templates/user/sign_in.html new file mode 100644 index 0000000..0e0cb94 --- /dev/null +++ b/cms/templates/user/sign_in.html @@ -0,0 +1,26 @@ +{% extends 'base.html' %} +{% load bootstrap5 %} +{% block content %} +
+
+
+
+ {% csrf_token %} + {% bootstrap_form user_form %} + {% buttons %} + + {% endbuttons %} +
+
+
+
+{% endblock %} \ No newline at end of file diff --git a/cms/urls.py b/cms/urls.py index 0f5fd29..2ac74d8 100644 --- a/cms/urls.py +++ b/cms/urls.py @@ -1,8 +1,13 @@ from django.urls import path -from .views import ArticleView, new_article +from .views import ArticleView, new_article, AuthenticationView urlpatterns = [ path('articles/', ArticleView.as_view(), name='create-article'), path('articles/new/', new_article, name='new-article'), + path( + '', + AuthenticationView.as_view(), + name='authenticate' + ) ] diff --git a/cms/views.py b/cms/views.py index 853657e..784ba5b 100644 --- a/cms/views.py +++ b/cms/views.py @@ -3,10 +3,13 @@ from json import JSONEncoder import requests from django.http import HttpRequest +from django.http import HttpResponse from django.shortcuts import render from django.views import View +from django.views import View as BaseView from cms.forms import ArticleForm +from cms.forms import UserForm from cms.models import Article @@ -86,3 +89,17 @@ def new_article(request): return render(request, template_name='articles/new.html', context=article_context) + + +class AuthenticationView(BaseView): + def get(self, request, *args, **kwargs): + user_form = UserForm() + auth_context = { + 'user_form': user_form, + } + return render(request, + 'user/sign_in.html', + context=auth_context) + + def post(self, request, *args, **kwargs): + return HttpResponse('ok') diff --git a/crossposting_backend/urls.py b/crossposting_backend/urls.py index 9dd2af0..ee6aecb 100644 --- a/crossposting_backend/urls.py +++ b/crossposting_backend/urls.py @@ -15,8 +15,10 @@ Including another URLconf """ from django.contrib import admin from django.urls import path, include +from .views import handle_root_path urlpatterns = [ path('admin/', admin.site.urls), path('cms/', include('cms.urls')), + path('', handle_root_path, name='root'), ] diff --git a/crossposting_backend/views.py b/crossposting_backend/views.py new file mode 100644 index 0000000..1497406 --- /dev/null +++ b/crossposting_backend/views.py @@ -0,0 +1,8 @@ +from django.http import HttpResponseRedirect +from django.urls import reverse + + +def handle_root_path(request): + return HttpResponseRedirect(reverse('authenticate')) + +