diff options
author | Andrea Lepori <alepori@student.ethz.ch> | 2020-07-28 21:17:18 +0200 |
---|---|---|
committer | Andrea Lepori <alepori@student.ethz.ch> | 2020-07-28 21:17:18 +0200 |
commit | 68cc1657fbe11b8ffbcd4d3d517f71c4404497c3 (patch) | |
tree | 37fd17cb370bca5bb0a5779295256b141cf0295b /accounts | |
parent | local font feching, list for non interactive items (diff) | |
download | scout-subs-68cc1657fbe11b8ffbcd4d3d517f71c4404497c3.tar.gz scout-subs-68cc1657fbe11b8ffbcd4d3d517f71c4404497c3.zip |
accept terms on account creation
Diffstat (limited to 'accounts')
-rw-r--r-- | accounts/templates/accounts/signup.html | 14 | ||||
-rw-r--r-- | accounts/templates/accounts/terms.html | 27 | ||||
-rw-r--r-- | accounts/urls.py | 3 | ||||
-rw-r--r-- | accounts/views.py | 39 |
4 files changed, 76 insertions, 7 deletions
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 }} <br> + <label> + <input name="terms_accept" type="checkbox" class="filled-in"/> + <span style="color:black">Accetto i <a href="{% url 'terms' %}">Termini e condizioni generali</a></span> + </label> + <br> + <br> <button class="btn waves-effect waves-light" type="submit">Invia</button> </form> </div> </div> </div> </div> +{% 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%} + <a style="margin-left: 10px;" href="{% url 'index' %}" class="breadcrumb">Home</a> + <a href="!#" class="breadcrumb hide-on-med-and-down">Termini e condizioni</a> +{% endblock%} + +{% block content %} + <div class="row"> + <div class="col l4 offset-l4 m8 offset-m2 s12"> + <div class="card"> + <div class="card-content"> + <h5>Termini e condizioni</h5> + <blockquote> + Termine 1 ecc...... + Cose + </blockquote> + </div> + </div> + </div> + </div> +{% 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 |