2016-11-30 07:48:02 +00:00
|
|
|
import re
|
2017-04-21 04:18:13 +00:00
|
|
|
import random
|
2016-11-30 07:48:02 +00:00
|
|
|
|
|
|
|
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
|
2017-04-21 04:18:13 +00:00
|
|
|
from django.views.generic import TemplateView, View
|
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'
|
2017-02-22 08:45:31 +00:00
|
|
|
|
|
|
|
class KeyMachineView(TemplateView):
|
|
|
|
template_name = 'users/keymachine.html'
|
2017-04-21 04:18:13 +00:00
|
|
|
|
|
|
|
class RandomView(View):
|
2017-04-21 04:33:14 +00:00
|
|
|
def get(self, request):
|
2017-04-21 04:18:13 +00:00
|
|
|
url = None
|
|
|
|
users = list(Townie.objects.all())
|
|
|
|
random.shuffle(users)
|
|
|
|
for user in users:
|
|
|
|
if user.has_modified_page():
|
|
|
|
url = 'https://tilde.town/~{}'.format(user.username)
|
|
|
|
break
|
|
|
|
if url is None:
|
|
|
|
url = 'https://tilde.town'
|
|
|
|
|
|
|
|
return redirect(url)
|