From d7dbc437fa15bdc4422fdff86cb436373e12169d Mon Sep 17 00:00:00 2001 From: Niko Abeler Date: Thu, 22 Jun 2023 20:35:43 +0200 Subject: [PATCH] register --- guild/templates/auth/user_form.html | 9 +++++++++ guild/urls.py | 2 +- guild/views/__init__.py | 12 +++++++++++- templates/base.html | 3 +++ templates/registration/login.html | 1 + 5 files changed, 25 insertions(+), 2 deletions(-) create mode 100644 guild/templates/auth/user_form.html diff --git a/guild/templates/auth/user_form.html b/guild/templates/auth/user_form.html new file mode 100644 index 0000000..c7a87ef --- /dev/null +++ b/guild/templates/auth/user_form.html @@ -0,0 +1,9 @@ +{% extends 'base.html' %} + +{% block content %} +
+ {% csrf_token %} + {{ form.as_p }} + +
+{% endblock content %} \ No newline at end of file diff --git a/guild/urls.py b/guild/urls.py index 94cc7d2..7a05c54 100644 --- a/guild/urls.py +++ b/guild/urls.py @@ -18,7 +18,7 @@ urlpatterns = [ ), name="logout", ), - # path("players/", views.PlayerListView.as_view(), name="player_list"), + path("accounts/register/", views.RegisterView.as_view(), name="register"), path( "players/create/", player_views.CreatePlayerView.as_view(), name="create_player" ), diff --git a/guild/views/__init__.py b/guild/views/__init__.py index 72fa1ea..bffea01 100644 --- a/guild/views/__init__.py +++ b/guild/views/__init__.py @@ -1,8 +1,10 @@ from datetime import date +from django.urls import reverse from django.views.generic import TemplateView, ListView, DetailView from django.views.generic.edit import CreateView from django.contrib.auth.mixins import LoginRequiredMixin - +from django.contrib.auth.models import User +from django.contrib.auth.forms import UserCreationForm from guild.models import Adventure, Character, Player, Reward @@ -31,3 +33,11 @@ class HomeView(LoginRequiredMixin, TemplateView): context["resources"][reward.resource.name] = 0 context["resources"][reward.resource.name] += reward.amount return context + + +class RegisterView(CreateView): + model = User + form_class = UserCreationForm + + def get_success_url(self): + return reverse("guild:login") diff --git a/templates/base.html b/templates/base.html index 3f41471..7a79384 100644 --- a/templates/base.html +++ b/templates/base.html @@ -76,6 +76,9 @@ + {% endif %} diff --git a/templates/registration/login.html b/templates/registration/login.html index 46fffff..79fe859 100644 --- a/templates/registration/login.html +++ b/templates/registration/login.html @@ -19,6 +19,7 @@ {% csrf_token %} {{form}} +Register