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..e69de29 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..e69de29 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..4bf3238 --- /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", {"title": "Sign Up", "form": form}) + + +def login_(request): + return render(request, "registration/login.html", {"title": "Login"}) diff --git a/FOSSDB_web/apps/fossdb/views.py b/FOSSDB_web/apps/fossdb/views.py index 35c3d5a..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("") + 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}) diff --git a/FOSSDB_web/settings.py b/FOSSDB_web/settings.py index cc0962b..e4d3655 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) @@ -38,6 +37,7 @@ ALLOWED_HOSTS = config["ALLOWED_HOSTS"] INSTALLED_APPS = [ "fossdb", + "account", "django.contrib.admin", "django.contrib.auth", "django.contrib.contenttypes", @@ -116,7 +116,7 @@ AUTH_PASSWORD_VALIDATORS = [ LANGUAGE_CODE = "en-us" -TIME_ZONE = "Europe/Riga" +TIME_ZONE = "UTC" USE_I18N = True @@ -134,3 +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 = "/" diff --git a/FOSSDB_web/urls.py b/FOSSDB_web/urls.py index b4a15ab..a68021a 100644 --- a/FOSSDB_web/urls.py +++ b/FOSSDB_web/urls.py @@ -20,8 +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")), ] urlpatterns += static(settings.STATIC_URL, document_root=settings.STATIC_ROOT) 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 %} 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 %} 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 %}