From 68cc1657fbe11b8ffbcd4d3d517f71c4404497c3 Mon Sep 17 00:00:00 2001 From: Andrea Lepori Date: Tue, 28 Jul 2020 21:17:18 +0200 Subject: accept terms on account creation --- accounts/templates/accounts/signup.html | 14 ++++++++++++ accounts/templates/accounts/terms.html | 27 +++++++++++++++++++++++ accounts/urls.py | 3 ++- accounts/views.py | 39 ++++++++++++++++++++++++++++----- 4 files changed, 76 insertions(+), 7 deletions(-) create mode 100644 accounts/templates/accounts/terms.html (limited to 'accounts') diff --git a/accounts/templates/accounts/signup.html b/accounts/templates/accounts/signup.html index a8a517c..56b5a4c 100644 --- a/accounts/templates/accounts/signup.html +++ b/accounts/templates/accounts/signup.html @@ -12,10 +12,24 @@ {% csrf_token %} {{ form.as_p }}
+ +
+
+{% endblock %} + +{% block script %} +{% if error %} +document.addEventListener('DOMContentLoaded', function() { + M.toast({html: '{{ error_text }}', classes: 'orange'}) +}); +{% endif %} {% endblock %} \ No newline at end of file diff --git a/accounts/templates/accounts/terms.html b/accounts/templates/accounts/terms.html new file mode 100644 index 0000000..c72e006 --- /dev/null +++ b/accounts/templates/accounts/terms.html @@ -0,0 +1,27 @@ +{% extends 'registration/base_client.html' %} + +{% block title %}About{% endblock %} + +{%block nav%} + Home + Termini e condizioni +{% endblock%} + +{% block content %} +
+
+
+
+
Termini e condizioni
+
+ Termine 1 ecc...... + Cose +
+
+
+
+
+{% endblock %} + +{% block script %} +{% endblock %} \ No newline at end of file diff --git a/accounts/urls.py b/accounts/urls.py index a2d8541..6a44457 100644 --- a/accounts/urls.py +++ b/accounts/urls.py @@ -3,6 +3,7 @@ from django.urls import path, include from . import views urlpatterns = [ - path('signup/', views.SignUp.as_view(), name='signup'), + path('signup/', views.signup, name='signup'), path('personal/', views.personal, name='personal'), + path('terms/', views.terms, name='terms'), ] diff --git a/accounts/views.py b/accounts/views.py index 23f4212..31786b1 100644 --- a/accounts/views.py +++ b/accounts/views.py @@ -1,11 +1,13 @@ from django.shortcuts import render from django.contrib.auth.forms import UserCreationForm -from django.urls import reverse_lazy +from django.contrib.auth import login, authenticate from django.views import generic from django.contrib.auth.models import Group from django.core.files.storage import FileSystemStorage from django.http import FileResponse from django.contrib.auth.decorators import login_required +from django.views.decorators.debug import sensitive_variables +from django.http import HttpResponseRedirect from client.models import UserCode @@ -14,10 +16,31 @@ from io import BytesIO from PIL import Image, UnidentifiedImageError -class SignUp(generic.CreateView): - form_class = UserCreationForm - success_url = reverse_lazy('login') - template_name = 'accounts/signup.html' +@sensitive_variables("raw_passsword") +def signup(request): + if request.method == 'POST': + if "terms_accept" not in request.POST: + form = UserCreationForm() + context = { + "form": form, + "error": True, + "error_text": "Accettare i termini e condizioni prego" + } + return render(request, 'accounts/signup.html', context) + 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) + login(request, user) + return HttpResponseRedirect('/') + else: + form = UserCreationForm() + context = { + "form": form, + } + return render(request, 'accounts/signup.html', context) @login_required @@ -218,4 +241,8 @@ def personal(request): 'error_text': error_text, } - return render(request, 'accounts/index.html', context) \ No newline at end of file + return render(request, 'accounts/index.html', context) + +def terms(request): + context = {} + return render(request, 'accounts/terms.html', context) \ No newline at end of file -- cgit v1.2.1