From 9655132f5e7c2dabf1d26ec5e46cb22e4c97d829 Mon Sep 17 00:00:00 2001 From: Artur Galyamov Date: Tue, 20 Dec 2022 10:20:29 +0500 Subject: [PATCH] =?UTF-8?q?=D0=94=D0=BE=D0=B1=D0=B0=D0=B2=D0=BB=D0=B5?= =?UTF-8?q?=D0=BD=D0=B0=20=D0=BF=D1=80=D0=BE=D0=B2=D0=B5=D1=80=D0=BA=D0=B0?= =?UTF-8?q?=20=D0=BB=D0=BE=D0=B3=D0=B8=D0=BD=D0=B0=20=D0=B8=20=D0=BF=D0=B0?= =?UTF-8?q?=D1=80=D0=BE=D0=BB=D1=8F=20#17?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- cms/views.py | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/cms/views.py b/cms/views.py index 784ba5b..72e1a2e 100644 --- a/cms/views.py +++ b/cms/views.py @@ -2,14 +2,13 @@ import os from json import JSONEncoder import requests -from django.http import HttpRequest -from django.http import HttpResponse +from django.contrib.auth import authenticate +from django.http import HttpRequest, HttpResponseRedirect from django.shortcuts import render +from django.urls import reverse from django.views import View -from django.views import View as BaseView -from cms.forms import ArticleForm -from cms.forms import UserForm +from cms.forms import ArticleForm, UserForm from cms.models import Article @@ -91,7 +90,7 @@ def new_article(request): context=article_context) -class AuthenticationView(BaseView): +class AuthenticationView(View): def get(self, request, *args, **kwargs): user_form = UserForm() auth_context = { @@ -102,4 +101,11 @@ class AuthenticationView(BaseView): context=auth_context) def post(self, request, *args, **kwargs): - return HttpResponse('ok') + username = request.POST['username'] + password = request.POST['password'] + authenticated = authenticate(username=username, + password=password) + if authenticated: + return HttpResponseRedirect(reverse('new-article')) + else: + return HttpResponseRedirect(reverse('authenticate'))