From c3a3d67752e1733b6fd151dbd76de480239b3bf2 Mon Sep 17 00:00:00 2001 From: Kristofers Solo Date: Mon, 27 Mar 2023 20:25:32 +0300 Subject: [PATCH 01/11] Created user registration form --- FOSSDB_web/apps/account/__init__.py | 0 FOSSDB_web/apps/account/admin.py | 3 +++ FOSSDB_web/apps/account/apps.py | 6 ++++++ FOSSDB_web/apps/account/forms.py | 11 +++++++++++ FOSSDB_web/apps/account/tests.py | 3 +++ FOSSDB_web/apps/account/urls.py | 9 +++++++++ FOSSDB_web/apps/account/views.py | 20 ++++++++++++++++++++ FOSSDB_web/settings.py | 2 +- FOSSDB_web/urls.py | 4 +++- 9 files changed, 56 insertions(+), 2 deletions(-) create mode 100644 FOSSDB_web/apps/account/__init__.py create mode 100644 FOSSDB_web/apps/account/admin.py create mode 100644 FOSSDB_web/apps/account/apps.py create mode 100644 FOSSDB_web/apps/account/forms.py create mode 100644 FOSSDB_web/apps/account/tests.py create mode 100644 FOSSDB_web/apps/account/urls.py create mode 100644 FOSSDB_web/apps/account/views.py diff --git a/FOSSDB_web/apps/account/__init__.py b/FOSSDB_web/apps/account/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/FOSSDB_web/apps/account/admin.py b/FOSSDB_web/apps/account/admin.py new file mode 100644 index 0000000..8c38f3f --- /dev/null +++ b/FOSSDB_web/apps/account/admin.py @@ -0,0 +1,3 @@ +from django.contrib import admin + +# Register your models here. diff --git a/FOSSDB_web/apps/account/apps.py b/FOSSDB_web/apps/account/apps.py new file mode 100644 index 0000000..2c684a9 --- /dev/null +++ b/FOSSDB_web/apps/account/apps.py @@ -0,0 +1,6 @@ +from django.apps import AppConfig + + +class AccountConfig(AppConfig): + default_auto_field = "django.db.models.BigAutoField" + name = "account" diff --git a/FOSSDB_web/apps/account/forms.py b/FOSSDB_web/apps/account/forms.py new file mode 100644 index 0000000..1b47e64 --- /dev/null +++ b/FOSSDB_web/apps/account/forms.py @@ -0,0 +1,11 @@ +from django import forms +from django.contrib.auth.forms import UserCreationForm +from django.contrib.auth.models import User + + +class RegisterForm(UserCreationForm): + email = forms.EmailField(required=True) + + class Meta: + model = User + fields = ["username", "email", "password1", "password2"] diff --git a/FOSSDB_web/apps/account/tests.py b/FOSSDB_web/apps/account/tests.py new file mode 100644 index 0000000..7ce503c --- /dev/null +++ b/FOSSDB_web/apps/account/tests.py @@ -0,0 +1,3 @@ +from django.test import TestCase + +# Create your tests here. diff --git a/FOSSDB_web/apps/account/urls.py b/FOSSDB_web/apps/account/urls.py new file mode 100644 index 0000000..8fa14e8 --- /dev/null +++ b/FOSSDB_web/apps/account/urls.py @@ -0,0 +1,9 @@ +from django.urls import path + +from . import views + +urlpatterns = [ + path("", views.sign_up, name="singup"), + path("signup", views.sign_up, name="signup"), + path("login", views.login_, name="login"), +] diff --git a/FOSSDB_web/apps/account/views.py b/FOSSDB_web/apps/account/views.py new file mode 100644 index 0000000..db7ddd5 --- /dev/null +++ b/FOSSDB_web/apps/account/views.py @@ -0,0 +1,20 @@ +from django.contrib.auth import login +from django.shortcuts import redirect, render + +from .forms import RegisterForm + + +def sign_up(request): + if request.method == "POST": + form = RegisterForm(request.POST) + if form.is_valid(): + user = form.save() + login(request, user) + return redirect("/") + else: + form = RegisterForm() + return render(request, "registration/sign_up.html", {"form": form}) + + +def login_(request): + return render(request, "registration/login.html") diff --git a/FOSSDB_web/settings.py b/FOSSDB_web/settings.py index 34fb5ca..cd26433 100644 --- a/FOSSDB_web/settings.py +++ b/FOSSDB_web/settings.py @@ -24,7 +24,6 @@ DEBUG = BASE_PATH.joinpath("debug").is_file() # Quick-start development settings - unsuitable for production # See https://docs.djangoproject.com/en/4.0/howto/deployment/checklist/ - with open(BASE_PATH.joinpath("config.json"), "r", encoding="UTF-8") as config_file: config = json.load(config_file) @@ -37,6 +36,7 @@ ALLOWED_HOSTS = config["ALLOWED_HOSTS"] # Application definition INSTALLED_APPS = [ + "account", "django.contrib.admin", "django.contrib.auth", "django.contrib.contenttypes", diff --git a/FOSSDB_web/urls.py b/FOSSDB_web/urls.py index 3d97689..4e84863 100644 --- a/FOSSDB_web/urls.py +++ b/FOSSDB_web/urls.py @@ -14,8 +14,10 @@ Including another URLconf 2. Add a URL to urlpatterns: path("blog/", include("blog.urls")) """ from django.contrib import admin -from django.urls import path +from django.urls import include, path urlpatterns = [ path("admin/", admin.site.urls), + path("", include("django.contrib.auth.urls")), + path("account/", include("account.urls")), ] From be727ce4ebfe2d63da6f63bbdb750e9ad4e6c990 Mon Sep 17 00:00:00 2001 From: Kristofers Solo Date: Mon, 27 Mar 2023 20:26:05 +0300 Subject: [PATCH 02/11] Changed default timezone --- FOSSDB_web/settings.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/FOSSDB_web/settings.py b/FOSSDB_web/settings.py index cd26433..ace8085 100644 --- a/FOSSDB_web/settings.py +++ b/FOSSDB_web/settings.py @@ -115,7 +115,7 @@ AUTH_PASSWORD_VALIDATORS = [ LANGUAGE_CODE = "en-us" -TIME_ZONE = "Europe/Riga" +TIME_ZONE = "UTC" USE_I18N = True From 5448d0e624dbda5f2ce1fb128cdec71ec36a643e Mon Sep 17 00:00:00 2001 From: Kristofers Solo Date: Mon, 27 Mar 2023 20:26:19 +0300 Subject: [PATCH 03/11] Set login/logout redirect --- FOSSDB_web/settings.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/FOSSDB_web/settings.py b/FOSSDB_web/settings.py index ace8085..e18612d 100644 --- a/FOSSDB_web/settings.py +++ b/FOSSDB_web/settings.py @@ -133,3 +133,5 @@ MEDIA_ROOT = BASE_PATH.joinpath("media") # https://docs.djangoproject.com/en/4.0/ref/settings/#default-auto-field DEFAULT_AUTO_FIELD = "django.db.models.BigAutoField" +LOGIN_REDIRECT_URL = "" +LOGOUT_REDIRECT_URL = "" From 4351d5ca6d5467561244f6507e2664ad6075af5e Mon Sep 17 00:00:00 2001 From: Kristofers Solo Date: Mon, 27 Mar 2023 21:42:41 +0300 Subject: [PATCH 04/11] Fixed redirect urls --- FOSSDB_web/apps/account/views.py | 2 +- FOSSDB_web/apps/fossdb/views.py | 2 +- FOSSDB_web/settings.py | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/FOSSDB_web/apps/account/views.py b/FOSSDB_web/apps/account/views.py index db7ddd5..b78fd14 100644 --- a/FOSSDB_web/apps/account/views.py +++ b/FOSSDB_web/apps/account/views.py @@ -10,7 +10,7 @@ def sign_up(request): if form.is_valid(): user = form.save() login(request, user) - return redirect("/") + return redirect("") else: form = RegisterForm() return render(request, "registration/sign_up.html", {"form": form}) diff --git a/FOSSDB_web/apps/fossdb/views.py b/FOSSDB_web/apps/fossdb/views.py index 35c3d5a..42f5ff8 100644 --- a/FOSSDB_web/apps/fossdb/views.py +++ b/FOSSDB_web/apps/fossdb/views.py @@ -19,7 +19,7 @@ def add_project(request): post = project.save(commit=False) post.author = request.user post.save() - return redirect("") + return redirect("/") else: project = ProjectForm() return render(request, "main/create_project.html", {"title": "Add project", "form": project}) diff --git a/FOSSDB_web/settings.py b/FOSSDB_web/settings.py index c9ddb15..e4d3655 100644 --- a/FOSSDB_web/settings.py +++ b/FOSSDB_web/settings.py @@ -134,5 +134,5 @@ MEDIA_ROOT = BASE_PATH.joinpath("media") # https://docs.djangoproject.com/en/4.0/ref/settings/#default-auto-field DEFAULT_AUTO_FIELD = "django.db.models.BigAutoField" -LOGIN_REDIRECT_URL = "" -LOGOUT_REDIRECT_URL = "" +LOGIN_REDIRECT_URL = "/" +LOGOUT_REDIRECT_URL = "/" From 8d8677218258fd5f0173b7b589a9b0d295f63842 Mon Sep 17 00:00:00 2001 From: Kristofers Solo Date: Mon, 27 Mar 2023 21:43:01 +0300 Subject: [PATCH 05/11] Added title --- FOSSDB_web/apps/account/views.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/FOSSDB_web/apps/account/views.py b/FOSSDB_web/apps/account/views.py index b78fd14..4bf3238 100644 --- a/FOSSDB_web/apps/account/views.py +++ b/FOSSDB_web/apps/account/views.py @@ -13,8 +13,8 @@ def sign_up(request): return redirect("") else: form = RegisterForm() - return render(request, "registration/sign_up.html", {"form": form}) + return render(request, "registration/sign_up.html", {"title": "Sign Up", "form": form}) def login_(request): - return render(request, "registration/login.html") + return render(request, "registration/login.html", {"title": "Login"}) From 6236d25ab423c6cf7ae059bc9afd65b95c1dd8e0 Mon Sep 17 00:00:00 2001 From: Kristofers Solo Date: Mon, 27 Mar 2023 21:43:56 +0300 Subject: [PATCH 06/11] Rename variable --- FOSSDB_web/apps/fossdb/views.py | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/FOSSDB_web/apps/fossdb/views.py b/FOSSDB_web/apps/fossdb/views.py index 42f5ff8..3b3a3a8 100644 --- a/FOSSDB_web/apps/fossdb/views.py +++ b/FOSSDB_web/apps/fossdb/views.py @@ -10,16 +10,16 @@ def index(request): return render(request, "fossdb/index.html", {"title": "FOSSDB", "projects": projects}) -@login_required(login_url="account/login/") -@permission_required("fossdb.add_post)", login_url="account/login/", raise_exception=True) +@login_required(login_url="login/") +@permission_required("fossdb.add_post)", login_url="login/", raise_exception=True) def add_project(request): if request.method == "POST": - project = ProjectForm(request.POST) - if project.is_valid(): - post = project.save(commit=False) + form = ProjectForm(request.POST) + if form.is_valid(): + post = form.save(commit=False) post.author = request.user post.save() return redirect("/") else: - project = ProjectForm() - return render(request, "main/create_project.html", {"title": "Add project", "form": project}) + form = ProjectForm() + return render(request, "fossdb/add_project.html", {"title": "Add project", "form": form}) From 88701203ecec42a56884976752f631ff543095ea Mon Sep 17 00:00:00 2001 From: Kristofers Solo Date: Mon, 27 Mar 2023 21:44:12 +0300 Subject: [PATCH 07/11] Created `add_project.html` file --- templates/fossdb/add_project.html | 10 ++++++++++ 1 file changed, 10 insertions(+) create mode 100644 templates/fossdb/add_project.html diff --git a/templates/fossdb/add_project.html b/templates/fossdb/add_project.html new file mode 100644 index 0000000..52b018a --- /dev/null +++ b/templates/fossdb/add_project.html @@ -0,0 +1,10 @@ +{% extends "layout.html" %} +{% load static %} +{% block title %}{{ title }}{% endblock %} +{% block meta %}{% endblock %} +{% block content %} +
+ {% csrf_token %}{{ form }} + +
+{% endblock %} From dcf849257e7b2e7d20e6740eee2b1ba6aebaa548 Mon Sep 17 00:00:00 2001 From: Kristofers Solo Date: Mon, 27 Mar 2023 21:44:30 +0300 Subject: [PATCH 08/11] Added `login` file --- templates/registration/login.html | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100644 templates/registration/login.html diff --git a/templates/registration/login.html b/templates/registration/login.html new file mode 100644 index 0000000..e1ca078 --- /dev/null +++ b/templates/registration/login.html @@ -0,0 +1,13 @@ +{% extends "layout.html" %} +{% load static %} +{% block title %}{{ title }}{% endblock %} +{% block meta %}{% endblock %} +{% block content %} +
+ {% csrf_token %}{{ form }} +

+ Don't have an account? Create one Here! +

+ +
+{% endblock %} From 27a70f6b5c5c919ef29d857d2485689fdfd86083 Mon Sep 17 00:00:00 2001 From: Kristofers Solo Date: Mon, 27 Mar 2023 21:44:41 +0300 Subject: [PATCH 09/11] Added `signup` file --- templates/registration/sign_up.html | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100644 templates/registration/sign_up.html diff --git a/templates/registration/sign_up.html b/templates/registration/sign_up.html new file mode 100644 index 0000000..40b7bad --- /dev/null +++ b/templates/registration/sign_up.html @@ -0,0 +1,11 @@ +{% extends "layout.html" %} +{% block title %}Sign Up{% endblock %} +{% block content %} +
+ {% csrf_token %}{{ form }} +

+ Have an account? Login Here! +

+ +
+{% endblock %} From b103f9a56eb519c8a0707203e684c8561e73be93 Mon Sep 17 00:00:00 2001 From: Kristofers Solo Date: Mon, 27 Mar 2023 21:44:57 +0300 Subject: [PATCH 10/11] Changed account path --- FOSSDB_web/urls.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/FOSSDB_web/urls.py b/FOSSDB_web/urls.py index 9aa8c44..a68021a 100644 --- a/FOSSDB_web/urls.py +++ b/FOSSDB_web/urls.py @@ -20,9 +20,9 @@ from django.urls import include, path urlpatterns = [ path("", include("fossdb.urls")), + path("", include("account.urls")), path("admin/", admin.site.urls), path("", include("django.contrib.auth.urls")), - path("account/", include("account.urls")), ] urlpatterns += static(settings.STATIC_URL, document_root=settings.STATIC_ROOT) From 3fcef9d5cb2866f3494fc1a776a32d598cc5f1e7 Mon Sep 17 00:00:00 2001 From: Kristofers Solo Date: Mon, 27 Mar 2023 21:47:55 +0300 Subject: [PATCH 11/11] Removed redundant code --- FOSSDB_web/apps/account/admin.py | 3 --- FOSSDB_web/apps/account/tests.py | 3 --- 2 files changed, 6 deletions(-) diff --git a/FOSSDB_web/apps/account/admin.py b/FOSSDB_web/apps/account/admin.py index 8c38f3f..e69de29 100644 --- a/FOSSDB_web/apps/account/admin.py +++ b/FOSSDB_web/apps/account/admin.py @@ -1,3 +0,0 @@ -from django.contrib import admin - -# Register your models here. diff --git a/FOSSDB_web/apps/account/tests.py b/FOSSDB_web/apps/account/tests.py index 7ce503c..e69de29 100644 --- a/FOSSDB_web/apps/account/tests.py +++ b/FOSSDB_web/apps/account/tests.py @@ -1,3 +0,0 @@ -from django.test import TestCase - -# Create your tests here.