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/views.py | |
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/views.py')
-rw-r--r-- | accounts/views.py | 39 |
1 files changed, 33 insertions, 6 deletions
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 |