diff --git a/stadlbauer/forms.py b/stadlbauer/forms.py new file mode 100644 index 0000000..5bf0711 --- /dev/null +++ b/stadlbauer/forms.py @@ -0,0 +1,7 @@ +from django.contrib.auth.forms import UserCreationForm +from django.contrib.auth.models import User + +class SignupForm(UserCreationForm): + class Meta: + model = User + fields = ('username', 'password1', 'password2', 'first_name', 'last_name') diff --git a/stadlbauer/settings.py b/stadlbauer/settings.py index 44f6aef..da8f6ab 100644 --- a/stadlbauer/settings.py +++ b/stadlbauer/settings.py @@ -11,6 +11,7 @@ https://docs.djangoproject.com/en/4.1/ref/settings/ """ from pathlib import Path +import os # Build paths inside the project like this: BASE_DIR / 'subdir'. BASE_DIR = Path(__file__).resolve().parent.parent @@ -54,7 +55,7 @@ ROOT_URLCONF = 'stadlbauer.urls' TEMPLATES = [ { 'BACKEND': 'django.template.backends.django.DjangoTemplates', - 'DIRS': [], + 'DIRS': [os.path.join(BASE_DIR, 'templates')], 'APP_DIRS': True, 'OPTIONS': { 'context_processors': [ diff --git a/stadlbauer/urls.py b/stadlbauer/urls.py index 440e147..4074b78 100644 --- a/stadlbauer/urls.py +++ b/stadlbauer/urls.py @@ -14,8 +14,11 @@ 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 path, include +from . import views urlpatterns = [ path('admin/', admin.site.urls), + path('accounts/new-user/', views.new_user, name='new-user'), + path('accounts/', include('django.contrib.auth.urls')), ] diff --git a/stadlbauer/views.py b/stadlbauer/views.py new file mode 100644 index 0000000..8a9fa3e --- /dev/null +++ b/stadlbauer/views.py @@ -0,0 +1,16 @@ +from .forms import SignupForm +from django.shortcuts import render +from django.urls import reverse +from django.http.response import HttpResponseRedirect + +def new_user(request): + if request.method == 'POST': + form = SignupForm(request.POST) + + if form.is_valid(): + form.save(commit=True) + return HttpResponseRedirect(reverse('login')) + else: + form = SignupForm() + + return render(request, 'registration/new-user.html', {'form': form}) diff --git a/templates/base.html b/templates/base.html new file mode 100644 index 0000000..7269a4f --- /dev/null +++ b/templates/base.html @@ -0,0 +1,17 @@ + + + +
+ + + + {% load static %} + {% block head %}{% endblock %} +Username and password do not match. Please try again.
+You are not authorized to access this site. Please inform Benjamin to get the corresponding authorization.
+ {% else %} +Please log in to view this site.
+ {% endif %} +