actually create users from form, now

pull/1/head
nathaniel smith 2016-11-30 22:49:06 -08:00
parent 31749726fc
commit 44939e6268
3 changed files with 14 additions and 11 deletions

View File

@ -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:

View File

@ -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."""

View File

@ -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'