2016-11-30 07:48:02 +00:00
|
|
|
import re
|
|
|
|
|
|
|
|
from django.core.exceptions import ValidationError
|
2017-01-14 06:17:23 +00:00
|
|
|
from django.db import transaction
|
2016-11-30 07:48:02 +00:00
|
|
|
from django.forms import Form, CharField, EmailField, Textarea, ChoiceField, BooleanField
|
2016-11-20 05:34:38 +00:00
|
|
|
from django.http import HttpResponse
|
2016-11-30 07:48:02 +00:00
|
|
|
from django.shortcuts import redirect
|
2016-11-20 05:34:38 +00:00
|
|
|
from django.views.generic import TemplateView
|
2016-11-30 07:48:02 +00:00
|
|
|
from django.views.generic.edit import FormView
|
2016-11-20 05:34:38 +00:00
|
|
|
|
2016-11-30 07:48:02 +00:00
|
|
|
from .forms import TownieForm
|
2017-01-14 06:17:23 +00:00
|
|
|
from .models import Townie, Pubkey
|
2016-11-21 07:56:55 +00:00
|
|
|
|
2016-11-30 07:48:02 +00:00
|
|
|
class SignupView(FormView):
|
|
|
|
form_class = TownieForm
|
|
|
|
template_name = 'users/signup.html'
|
2016-11-21 07:56:55 +00:00
|
|
|
|
2017-01-14 06:17:23 +00:00
|
|
|
@transaction.atomic
|
2016-11-30 07:48:02 +00:00
|
|
|
def form_valid(self, form):
|
2016-12-01 06:49:06 +00:00
|
|
|
del form.cleaned_data['captcha']
|
|
|
|
del form.cleaned_data['aup']
|
2017-01-14 06:17:23 +00:00
|
|
|
pubkey = Pubkey(key=form.cleaned_data.pop('pubkey'),
|
|
|
|
key_type=form.cleaned_data.pop('pubkey_type'))
|
2016-12-01 06:49:06 +00:00
|
|
|
|
|
|
|
t = Townie(**form.cleaned_data)
|
2017-01-17 06:10:55 +00:00
|
|
|
if not getattr(t, 'displayname'):
|
|
|
|
t.displayname = t.username
|
2016-12-01 06:49:06 +00:00
|
|
|
t.set_unusable_password()
|
|
|
|
t.save()
|
2017-01-14 06:17:23 +00:00
|
|
|
pubkey.townie = t
|
|
|
|
pubkey.save()
|
2016-11-30 08:29:39 +00:00
|
|
|
return redirect('users:thanks')
|
2016-11-21 07:56:55 +00:00
|
|
|
|
|
|
|
|
2016-11-30 07:48:02 +00:00
|
|
|
class ThanksView(TemplateView):
|
|
|
|
template_name = 'users/thanks.html'
|