From 1a34329937017731be58044689d2730dad731b2b Mon Sep 17 00:00:00 2001
From: Piotr Kopycki
Date: Mon, 20 Dec 2021 20:37:32 +0100
Subject: [PATCH] Login fix
---
templates/login.html | 133 +++++----------------------------------
templates/login2.html | 21 -------
templates/login_old.html | 120 +++++++++++++++++++++++++++++++++++
users/forms.py | 11 +---
users/urls.py | 2 +-
users/views.py | 28 ++-------
6 files changed, 145 insertions(+), 170 deletions(-)
delete mode 100644 templates/login2.html
create mode 100644 templates/login_old.html
diff --git a/templates/login.html b/templates/login.html
index fcc6db3..60ab399 100644
--- a/templates/login.html
+++ b/templates/login.html
@@ -1,120 +1,21 @@
-
+{% extends "authBase.html" %}
-
- Login
-
-
-
+{% block title %}Login{% endblock %}
+{% block content %}
+ Log In
+
- {% endfor %}
-
-
-{% endblock %}
-
diff --git a/templates/login_old.html b/templates/login_old.html
new file mode 100644
index 0000000..fcc6db3
--- /dev/null
+++ b/templates/login_old.html
@@ -0,0 +1,120 @@
+
+
+
+ Login
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Don't have an account?
Sign Up
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/users/forms.py b/users/forms.py
index 87838e5..791dab1 100644
--- a/users/forms.py
+++ b/users/forms.py
@@ -11,13 +11,4 @@ class RegistrationForm(UserCreationForm):
class Meta:
model = User
- fields = ("email", "first_name", "last_name", "password1", "password2")
-
-
-class LoginForm(AuthenticationForm):
- #email = forms.EmailField(max_length=60, widget=forms.EmailInput(attrs={'placeholder': 'Enter Email'}))
- password = forms.CharField(widget=forms.PasswordInput(attrs={'placeholder': 'Enter Password'}))
-
- class Meta:
- model = User
- fields = ("email", "password")
+ fields = ("email", "first_name", "last_name", "password1", "password2")
\ No newline at end of file
diff --git a/users/urls.py b/users/urls.py
index aa89add..42c9169 100644
--- a/users/urls.py
+++ b/users/urls.py
@@ -4,7 +4,7 @@ from django.urls import path
from users.views import UserModelViewSet
from rest_framework_simplejwt.views import TokenObtainPairView
from rest_framework_simplejwt.views import TokenRefreshView
-from .views import PasswordReset, UserPasswordResetConfirmView, RegisterViewSet, login, logout, register, register_success, login2
+from .views import PasswordReset, UserPasswordResetConfirmView, RegisterViewSet, login, logout, register, register_success
router = DefaultRouter(trailing_slash=False)
diff --git a/users/views.py b/users/views.py
index c4b4fb8..29cc290 100644
--- a/users/views.py
+++ b/users/views.py
@@ -10,7 +10,7 @@ from .serializers import UserPasswordResetSerializer, UserPasswordResetConfirmSe
from rest_framework.response import Response
from django.shortcuts import render, redirect
from django.template import loader
-from .forms import RegistrationForm, LoginForm
+from .forms import RegistrationForm
from django.contrib.auth.forms import AuthenticationForm
from django.contrib.auth import login as auth_login
from config.authh import SettingsBackend
@@ -103,30 +103,10 @@ def login_success(request):
return render(request, 'great.html')
-def login2(request):
- context = {}
- if request.POST:
- form = LoginForm(request.POST)
- if form.is_valid():
- email = form.cleaned_data["email"],
- password = form.cleaned_data["password1"]
- # username = request.POST.get("email")
- # password = request.POST.get("password")
- user = SettingsBackend().authenticate(request, email=email, password=password)
- if user is not None:
- auth_login(request, user)
- return redirect('home')
- else:
- context['login_form'] = form
- else:
- form = LoginForm()
- context['login_form'] = form
- return render(request, 'login2.html', context)
-
-
def login(request):
context = {}
if request.POST:
+ form = AuthenticationForm(request.POST)
username = request.POST.get("username")
password = request.POST.get("password")
@@ -134,4 +114,8 @@ def login(request):
if user is not None:
auth_login(request, user)
return redirect('home')
+ context['login_form'] = form
+ else:
+ form = AuthenticationForm()
+ context['login_form'] = form
return render(request, 'login.html', context)