diff --git a/Main/urls.py b/Main/urls.py index 7c0570f..26e710f 100644 --- a/Main/urls.py +++ b/Main/urls.py @@ -1,9 +1,7 @@ from django.urls import path -from .views import index_view, login_view, signUp_view +from .views import index_view, signup_view urlpatterns = [ path('', index_view, name='index'), - path('login/', login_view, name='login'), - path('signup/', signUp_view, name='signUp'), - + path('signup/', signup_view, name='signup'), ] diff --git a/Main/views.py b/Main/views.py index c2ef23f..e57d972 100644 --- a/Main/views.py +++ b/Main/views.py @@ -1,4 +1,6 @@ -from django.shortcuts import render +from django.shortcuts import render, redirect +from django.contrib.auth import login, authenticate +from django.contrib.auth.forms import UserCreationForm from django.http import HttpResponse # Create your views here. @@ -8,9 +10,24 @@ def index_view(request): return render(request, 'Index.html') return HttpResponse(405) -def signUp_view(request): - return HttpResponse(405) +def signup_view(request): + if request.method == 'GET': + form = UserCreationForm() + return render(request, '../templates/Main/signup.html', {'form': form}) + + elif request.method == 'POST': + form = UserCreationForm(request.POST) + + if form.is_valid(): + form.save() + username = form.cleaned_data.get('username') + raw_password = form.cleaned_data.get('password1') + user = authenticate(username=username, password=raw_password) -def login_view(request): - return HttpResponse(405) + login(request, user) + return render(request, '../templates/Main/success.html') + else: + return HttpResponse(405) + else: + return HttpResponse(405) \ No newline at end of file diff --git a/templates/Main/signup.html b/templates/Main/signup.html new file mode 100644 index 0000000..f3434c6 --- /dev/null +++ b/templates/Main/signup.html @@ -0,0 +1,19 @@ +{% block content %} +

Django ToDo Sign up

+
+ {% csrf_token %} + {% for field in form %} +

+ {{ field.label_tag }}
+ {{ field }} + {% if field.help_text %} + {{ field.help_text }} + {% endif %} + {% for error in field.errors %} +

{{ error }}

+ {% endfor %} +

+ {% endfor %} + +
+{% endblock %} \ No newline at end of file diff --git a/templates/Main/success.html b/templates/Main/success.html new file mode 100644 index 0000000..3231237 --- /dev/null +++ b/templates/Main/success.html @@ -0,0 +1 @@ +Success! \ No newline at end of file