From aa3f17fe1d81f909c9b8cf519d46d72f9cfbb37d Mon Sep 17 00:00:00 2001
From: Karlie Fang <380923800@qq.com>
Date: Mon, 30 Oct 2023 03:15:20 +0800
Subject: [PATCH 01/10] Basic UI & functionality for login, logout, change pwd
---
web-app/django/VIM/apps/main/forms.py | 12 +++++
web-app/django/VIM/apps/main/models.py | 6 +--
.../VIM/apps/main/static/main/css/login.css | 37 +++++++++++++
.../registration/change_password.html | 39 ++++++++++++++
.../main/templates/registration/login.html | 52 +++++++++++++++++++
web-app/django/VIM/apps/main/urls.py | 5 +-
web-app/django/VIM/apps/main/views.py | 33 ++++++++++--
web-app/django/VIM/templates/base.html | 16 +++++-
8 files changed, 192 insertions(+), 8 deletions(-)
create mode 100644 web-app/django/VIM/apps/main/forms.py
create mode 100644 web-app/django/VIM/apps/main/static/main/css/login.css
create mode 100644 web-app/django/VIM/apps/main/templates/registration/change_password.html
create mode 100644 web-app/django/VIM/apps/main/templates/registration/login.html
diff --git a/web-app/django/VIM/apps/main/forms.py b/web-app/django/VIM/apps/main/forms.py
new file mode 100644
index 0000000..224aa3e
--- /dev/null
+++ b/web-app/django/VIM/apps/main/forms.py
@@ -0,0 +1,12 @@
+from django import forms
+from django.contrib.auth.forms import AuthenticationForm
+
+class LoginForm(AuthenticationForm):
+ username = forms.EmailField(
+ widget=forms.TextInput(attrs={'class': 'form-control'}),
+ label="Username"
+ )
+ password = forms.CharField(
+ widget=forms.PasswordInput(attrs={'class': 'form-control'}),
+ label="Password"
+ )
\ No newline at end of file
diff --git a/web-app/django/VIM/apps/main/models.py b/web-app/django/VIM/apps/main/models.py
index 71a8362..fd18c6e 100644
--- a/web-app/django/VIM/apps/main/models.py
+++ b/web-app/django/VIM/apps/main/models.py
@@ -1,3 +1,3 @@
-from django.db import models
-
-# Create your models here.
+from django.db import models
+
+# Create your models here.
diff --git a/web-app/django/VIM/apps/main/static/main/css/login.css b/web-app/django/VIM/apps/main/static/main/css/login.css
new file mode 100644
index 0000000..a692702
--- /dev/null
+++ b/web-app/django/VIM/apps/main/static/main/css/login.css
@@ -0,0 +1,37 @@
+.login-form {
+ color: #435334;
+}
+
+input {
+ border: 1px solid #9EB384;
+ border-radius: 4px;
+ background-color: #FAF1E4;
+ padding: 5px;
+ color: #435334;
+}
+
+input:hover {
+ border: 1px solid #435334;
+ background-color: #FAF1E4;
+ color: #435334;
+}
+
+input:focus {
+ border: 1px solid #435334;
+ box-shadow: 0 0 5px #9EB384;
+ outline: none;
+}
+
+input::placeholder {
+ color: #9EB384;
+}
+
+.btn-primary {
+ background-color: #435334;
+ border: 1px solid #435334;
+}
+
+.btn-primary:hover {
+ background-color: #9EB384;
+ border: 1px solid #9EB384;
+}
\ No newline at end of file
diff --git a/web-app/django/VIM/apps/main/templates/registration/change_password.html b/web-app/django/VIM/apps/main/templates/registration/change_password.html
new file mode 100644
index 0000000..aabdcb6
--- /dev/null
+++ b/web-app/django/VIM/apps/main/templates/registration/change_password.html
@@ -0,0 +1,39 @@
+{% extends "base.html" %}
+{% load static %}
+
+{% block title %}
+Login
+{% endblock %}
+
+{% block css_files %}
+
+{% endblock %}
+
+{% block content %}
+
-
+ {% if user.is_authenticated %}
+
+
+
+
+ {% else %}
+
+
+
+ {% endif %}
Date: Mon, 30 Oct 2023 03:50:49 +0800
Subject: [PATCH 02/10] Reformat login function
---
web-app/django/VIM/apps/main/forms.py | 10 ++--------
web-app/django/VIM/apps/main/urls.py | 4 ++--
web-app/django/VIM/apps/main/views.py | 14 +++++++-------
3 files changed, 11 insertions(+), 17 deletions(-)
diff --git a/web-app/django/VIM/apps/main/forms.py b/web-app/django/VIM/apps/main/forms.py
index 224aa3e..a59f409 100644
--- a/web-app/django/VIM/apps/main/forms.py
+++ b/web-app/django/VIM/apps/main/forms.py
@@ -2,11 +2,5 @@
from django.contrib.auth.forms import AuthenticationForm
class LoginForm(AuthenticationForm):
- username = forms.EmailField(
- widget=forms.TextInput(attrs={'class': 'form-control'}),
- label="Username"
- )
- password = forms.CharField(
- widget=forms.PasswordInput(attrs={'class': 'form-control'}),
- label="Password"
- )
\ No newline at end of file
+ username = forms.EmailField(widget=forms.TextInput(attrs={"class": "form-control"}), label="Username")
+ password = forms.CharField(widget=forms.PasswordInput(attrs={"class": "form-control"}), label="Password")
\ No newline at end of file
diff --git a/web-app/django/VIM/apps/main/urls.py b/web-app/django/VIM/apps/main/urls.py
index 4b41cfb..2623ddd 100644
--- a/web-app/django/VIM/apps/main/urls.py
+++ b/web-app/django/VIM/apps/main/urls.py
@@ -7,6 +7,6 @@
path("", views.home, name="home"),
path("about/", views.about, name="about"),
path("login/", views.login_view, name="login"),
- path('change_password/', views.change_password, name='change_password'),
- path('logout/', views.user_logout, name='logout'),
+ path("change_password/", views.change_password, name="change_password"),
+ path("logout/", views.user_logout, name="logout"),
]
\ No newline at end of file
diff --git a/web-app/django/VIM/apps/main/views.py b/web-app/django/VIM/apps/main/views.py
index cb6cb37..4064702 100644
--- a/web-app/django/VIM/apps/main/views.py
+++ b/web-app/django/VIM/apps/main/views.py
@@ -10,27 +10,27 @@ def about(request):
return render(request, "main/about.html", {"active_tab": "about"})
def login_view(request):
- if request.method == 'POST':
+ if request.method == "POST":
form = LoginForm(request, request.POST)
if form.is_valid():
login(request, form.get_user())
- return redirect('main:home')
+ return redirect("main:home")
else:
form = LoginForm()
- return render(request, 'registration/login.html', {'form': form})
+ return render(request, "registration/login.html", {"form": form})
def user_logout(request):
logout(request)
- return redirect('main:home')
+ return redirect("main:home")
def change_password(request):
- if request.method == 'POST':
+ if request.method == "POST":
form = PasswordChangeForm(request.user, request.POST)
if form.is_valid():
user = form.save()
update_session_auth_hash(request, user) # Important for keeping the user authenticated
- return redirect('main:home')
+ return redirect("main:home")
else:
form = PasswordChangeForm(request.user)
- return render(request, 'registration/change_password.html', {'form': form})
\ No newline at end of file
+ return render(request, "registration/change_password.html", {"form": form})
\ No newline at end of file
From 594bb416ddb649d26982aff323fa0d61add88bf3 Mon Sep 17 00:00:00 2001
From: Karlie Fang <380923800@qq.com>
Date: Mon, 30 Oct 2023 03:54:54 +0800
Subject: [PATCH 03/10] reformat login script
---
web-app/django/VIM/apps/main/forms.py | 8 ++++++--
web-app/django/VIM/apps/main/urls.py | 2 +-
web-app/django/VIM/apps/main/views.py | 10 ++++++++--
3 files changed, 15 insertions(+), 5 deletions(-)
diff --git a/web-app/django/VIM/apps/main/forms.py b/web-app/django/VIM/apps/main/forms.py
index a59f409..4e73c76 100644
--- a/web-app/django/VIM/apps/main/forms.py
+++ b/web-app/django/VIM/apps/main/forms.py
@@ -2,5 +2,9 @@
from django.contrib.auth.forms import AuthenticationForm
class LoginForm(AuthenticationForm):
- username = forms.EmailField(widget=forms.TextInput(attrs={"class": "form-control"}), label="Username")
- password = forms.CharField(widget=forms.PasswordInput(attrs={"class": "form-control"}), label="Password")
\ No newline at end of file
+ username = forms.EmailField(
+ widget=forms.TextInput(attrs={"class": "form-control"}), label="Username"
+ )
+ password = forms.CharField(
+ widget=forms.PasswordInput(attrs={"class": "form-control"}), label="Password"
+ )
diff --git a/web-app/django/VIM/apps/main/urls.py b/web-app/django/VIM/apps/main/urls.py
index 2623ddd..eb8b6eb 100644
--- a/web-app/django/VIM/apps/main/urls.py
+++ b/web-app/django/VIM/apps/main/urls.py
@@ -9,4 +9,4 @@
path("login/", views.login_view, name="login"),
path("change_password/", views.change_password, name="change_password"),
path("logout/", views.user_logout, name="logout"),
-]
\ No newline at end of file
+]
diff --git a/web-app/django/VIM/apps/main/views.py b/web-app/django/VIM/apps/main/views.py
index 4064702..28daf15 100644
--- a/web-app/django/VIM/apps/main/views.py
+++ b/web-app/django/VIM/apps/main/views.py
@@ -6,9 +6,11 @@
def home(request):
return render(request, "main/index.html", {"active_tab": "home"})
+
def about(request):
return render(request, "main/about.html", {"active_tab": "about"})
+
def login_view(request):
if request.method == "POST":
form = LoginForm(request, request.POST)
@@ -20,17 +22,21 @@ def login_view(request):
return render(request, "registration/login.html", {"form": form})
+
def user_logout(request):
logout(request)
return redirect("main:home")
+
def change_password(request):
if request.method == "POST":
form = PasswordChangeForm(request.user, request.POST)
if form.is_valid():
user = form.save()
- update_session_auth_hash(request, user) # Important for keeping the user authenticated
+ update_session_auth_hash(
+ request, user
+ ) # Important for keeping the user authenticated
return redirect("main:home")
else:
form = PasswordChangeForm(request.user)
- return render(request, "registration/change_password.html", {"form": form})
\ No newline at end of file
+ return render(request, "registration/change_password.html", {"form": form})
From 63c06d04851a44e2165c8c40f5a565238c809f7a Mon Sep 17 00:00:00 2001
From: Karlie Fang <380923800@qq.com>
Date: Mon, 30 Oct 2023 03:56:25 +0800
Subject: [PATCH 04/10] reformat login script
---
web-app/django/VIM/apps/main/forms.py | 1 +
web-app/django/VIM/apps/main/views.py | 1 +
2 files changed, 2 insertions(+)
diff --git a/web-app/django/VIM/apps/main/forms.py b/web-app/django/VIM/apps/main/forms.py
index 4e73c76..4e47e06 100644
--- a/web-app/django/VIM/apps/main/forms.py
+++ b/web-app/django/VIM/apps/main/forms.py
@@ -1,6 +1,7 @@
from django import forms
from django.contrib.auth.forms import AuthenticationForm
+
class LoginForm(AuthenticationForm):
username = forms.EmailField(
widget=forms.TextInput(attrs={"class": "form-control"}), label="Username"
diff --git a/web-app/django/VIM/apps/main/views.py b/web-app/django/VIM/apps/main/views.py
index 28daf15..a46feb8 100644
--- a/web-app/django/VIM/apps/main/views.py
+++ b/web-app/django/VIM/apps/main/views.py
@@ -3,6 +3,7 @@
from django.shortcuts import render, redirect
from .forms import LoginForm
+
def home(request):
return render(request, "main/index.html", {"active_tab": "home"})
From e5497486b5a49cf098ef467ee0d35bf513b7eca3 Mon Sep 17 00:00:00 2001
From: Karlie Fang <380923800@qq.com>
Date: Mon, 30 Oct 2023 14:06:36 +0800
Subject: [PATCH 05/10] Fix login function & create a basic register function
---
web-app/django/VIM/apps/main/forms.py | 47 +++++++++++++++++--
.../VIM/apps/main/static/main/css/login.css | 21 +++++++++
.../registration/change_password.html | 11 +----
.../main/templates/registration/login.html | 12 +++--
.../main/templates/registration/register.html | 30 ++++++++++++
web-app/django/VIM/apps/main/urls.py | 3 +-
web-app/django/VIM/apps/main/views.py | 30 ++++++++----
web-app/django/VIM/templates/base.html | 2 +-
8 files changed, 125 insertions(+), 31 deletions(-)
create mode 100644 web-app/django/VIM/apps/main/templates/registration/register.html
diff --git a/web-app/django/VIM/apps/main/forms.py b/web-app/django/VIM/apps/main/forms.py
index 4e47e06..77b9bf2 100644
--- a/web-app/django/VIM/apps/main/forms.py
+++ b/web-app/django/VIM/apps/main/forms.py
@@ -1,11 +1,48 @@
from django import forms
-from django.contrib.auth.forms import AuthenticationForm
+from django.contrib.auth.forms import AuthenticationForm, UserCreationForm, PasswordChangeForm
+from django.contrib.auth.models import User
class LoginForm(AuthenticationForm):
- username = forms.EmailField(
- widget=forms.TextInput(attrs={"class": "form-control"}), label="Username"
+ username = forms.EmailField(label="Email Address")
+ password = forms.CharField(widget=forms.PasswordInput, label="Password")
+
+ class Meta:
+ model = User
+ fields = ("username", "password")
+
+
+class RegistrationForm(UserCreationForm):
+ username = forms.EmailField(label="Email Address", required=True)
+ password1 = forms.CharField(
+ label="Password", widget=forms.PasswordInput, required=True
+ )
+ password2 = forms.CharField(
+ label="Password Confirmation", widget=forms.PasswordInput, required=True
+ )
+
+ class Meta:
+ model = User
+ fields = ("username", "password1", "password2")
+
+
+class CustomPasswordChangeForm(PasswordChangeForm):
+ old_password = forms.CharField(
+ label="Old Password",
+ widget=forms.PasswordInput,
+ strip=False,
)
- password = forms.CharField(
- widget=forms.PasswordInput(attrs={"class": "form-control"}), label="Password"
+ new_password1 = forms.CharField(
+ label="New Password",
+ widget=forms.PasswordInput,
+ strip=False,
)
+ new_password2 = forms.CharField(
+ label="Confirm New Password",
+ widget=forms.PasswordInput,
+ strip=False,
+ )
+
+ class Meta:
+ model = User
+ fields = ("old_password", "new_password1", "new_password2")
diff --git a/web-app/django/VIM/apps/main/static/main/css/login.css b/web-app/django/VIM/apps/main/static/main/css/login.css
index a692702..ebfa293 100644
--- a/web-app/django/VIM/apps/main/static/main/css/login.css
+++ b/web-app/django/VIM/apps/main/static/main/css/login.css
@@ -8,6 +8,7 @@ input {
background-color: #FAF1E4;
padding: 5px;
color: #435334;
+ margin: 0 10px;
}
input:hover {
@@ -34,4 +35,24 @@ input::placeholder {
.btn-primary:hover {
background-color: #9EB384;
border: 1px solid #9EB384;
+}
+
+p {
+ color: #435334;
+}
+
+a {
+ color: #435334;
+ text-decoration: none;
+ font-weight: bold;
+}
+
+a:hover {
+ color: #9EB384;
+ text-decoration: none;
+ font-weight: bold;
+}
+
+.errorlist {
+ color: red;
}
\ No newline at end of file
diff --git a/web-app/django/VIM/apps/main/templates/registration/change_password.html b/web-app/django/VIM/apps/main/templates/registration/change_password.html
index aabdcb6..6076313 100644
--- a/web-app/django/VIM/apps/main/templates/registration/change_password.html
+++ b/web-app/django/VIM/apps/main/templates/registration/change_password.html
@@ -13,17 +13,8 @@
-
- {% if messages %}
-
- {% for message in messages %}
- {{ message }}
- {% endfor %}
-
- {% endif %}
-