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")), ]