diff --git a/core/accounts/forms.py b/core/accounts/forms.py new file mode 100644 index 0000000..fb0527e --- /dev/null +++ b/core/accounts/forms.py @@ -0,0 +1,8 @@ +from django import forms +from django.contrib.auth.forms import UserCreationForm +from django.contrib.auth.models import User + +class RegisterForm(UserCreationForm): + class Meta: + model=User + fields = ['username','password1','password2'] \ No newline at end of file diff --git a/core/accounts/templates/accounts/register.html b/core/accounts/templates/accounts/register.html index 19ecacf..f1e6997 100644 --- a/core/accounts/templates/accounts/register.html +++ b/core/accounts/templates/accounts/register.html @@ -1,5 +1,14 @@ {% extends 'accounts/base.html' %} {% block title %}Registrierung{% endblock %} {% block content %} -

Registrierung

+
+

Registrierung

+
+
+
+ {% csrf_token %} +

Sign Up

+ {{ form.as_p }} + +
{% endblock %} \ No newline at end of file diff --git a/core/accounts/views.py b/core/accounts/views.py index cf7bf7c..14f1b2d 100644 --- a/core/accounts/views.py +++ b/core/accounts/views.py @@ -1,10 +1,19 @@ -from django.shortcuts import render +from django.shortcuts import render, redirect from django.contrib.auth.decorators import login_required +from .forms import RegisterForm # Create your views here. @login_required def home(request): return render(request, 'accounts/home.html') -def register(request): - return render(request, 'accounts/register.html') \ No newline at end of file +def register(response): + if response.method == "POST": + form = RegisterForm(response.POST) + if form.is_valid(): + form.save() + return redirect("home") + else: + form = RegisterForm() + + return render(response, "accounts/register.html", {"form":form}) \ No newline at end of file