From 44939e626812e6d74da51656cfd6b4d67dfd68e0 Mon Sep 17 00:00:00 2001 From: nathaniel smith Date: Wed, 30 Nov 2016 22:49:06 -0800 Subject: [PATCH] actually create users from form, now --- ttadmin/users/forms.py | 6 +++++- ttadmin/users/models.py | 3 +++ ttadmin/users/views.py | 16 ++++++---------- 3 files changed, 14 insertions(+), 11 deletions(-) diff --git a/ttadmin/users/forms.py b/ttadmin/users/forms.py index 2a632b4..0bfcbc4 100644 --- a/ttadmin/users/forms.py +++ b/ttadmin/users/forms.py @@ -5,7 +5,7 @@ from django.core.exceptions import ValidationError from django.forms import Form, CharField, EmailField, Textarea, ChoiceField, BooleanField import sshpubkeys as ssh -from .models import SSH_TYPE_CHOICES +from .models import Townie, SSH_TYPE_CHOICES USERNAME_RE = re.compile(r'[a-z][a-z0-9_]+') USERNAME_MIN_LENGTH = 4 @@ -31,6 +31,10 @@ def validate_username(username): raise ValidationError('Username too short.') if not USERNAME_RE.match(username): raise ValidationError('Username must be all lowercase, start with a letter, and only use the _ special charcter') + duplicate = Townie.objects.filter(username=username).count() + if duplicate > 0: + raise ValidationError('Username already in use :(') + def validate_displayname(display_name): if len(display_name) < DISPLAY_MIN_LENGTH: diff --git a/ttadmin/users/models.py b/ttadmin/users/models.py index 20d234e..3613f9d 100644 --- a/ttadmin/users/models.py +++ b/ttadmin/users/models.py @@ -34,6 +34,9 @@ class Townie(User): after review.""" self.pending = False + # TODO consider a generic ensure method that syncs this model with the + # system. there will likely be things besides shell that we want to keep + # track of in the DB. def ensure_shell(self): """Runs chsh for the user to set their shell to whatever self.shell is.""" diff --git a/ttadmin/users/views.py b/ttadmin/users/views.py index 51dcc3e..a0218e5 100644 --- a/ttadmin/users/views.py +++ b/ttadmin/users/views.py @@ -16,19 +16,15 @@ class SignupView(FormView): def form_valid(self, form): - # TODO - #t = Townie( - # username=username, - # displayname=displayname, - # pubkey=pubkey, - # email=email, - #) + del form.cleaned_data['captcha'] + del form.cleaned_data['aup'] - #t.set_unusable_password() - #t.save() + t = Townie(**form.cleaned_data) + + t.set_unusable_password() + t.save() return redirect('users:thanks') -# TODO actually fill in this template class ThanksView(TemplateView): template_name = 'users/thanks.html'