Browse Source

Вывожу сообщение в случае успешного либо неудачного сличений (аутентификации) #17

pull/32/head
Artur Galyamov 2 years ago
parent
commit
82b151a3a7
  1. 7
      cms/views.py

7
cms/views.py

@ -2,6 +2,7 @@ import os
from json import JSONEncoder from json import JSONEncoder
import requests import requests
from django.contrib import messages
from django.contrib.auth import authenticate, login from django.contrib.auth import authenticate, login
from django.contrib.auth.decorators import login_required from django.contrib.auth.decorators import login_required
from django.contrib.auth.mixins import LoginRequiredMixin from django.contrib.auth.mixins import LoginRequiredMixin
@ -109,8 +110,14 @@ class AuthenticationView(View):
authenticated_user = authenticate(username=username, authenticated_user = authenticate(username=username,
password=password) password=password)
if authenticated_user is None: if authenticated_user is None:
messages.add_message(request,
messages.ERROR,
'Неправильное имя пользователя и/или пароль')
return HttpResponseRedirect(reverse('authenticate')) return HttpResponseRedirect(reverse('authenticate'))
else: else:
messages.add_message(request,
messages.SUCCESS,
'Поздравляю, вы вошли успешно')
login(request, login(request,
user=authenticated_user) user=authenticated_user)
return HttpResponseRedirect(reverse('new-article')) return HttpResponseRedirect(reverse('new-article'))

Loading…
Cancel
Save