start on signup post

pull/1/head
nathaniel smith 2016-11-20 23:56:55 -08:00
parent 57d4aa7c1f
commit 99e5c69aa6
3 changed files with 40 additions and 8 deletions

View File

@ -1,15 +1,16 @@
from django.db.models.signals import post_save
from django.dispatch import receiver
from django.contrib.auth.models import User
from django.db.models import TextField, BooleanField
from django.db.models import TextField, BooleanField, CharField
class Townie(User):
"""Both an almost normal Django User as well as an abstraction over a
system user."""
pubkey = TextField(blank=False, null=False)
shell = TextField(max_length=50, default="/bin/bash")
pending = BooleanField(default=True)
shell = CharField(max_length=50, default="/bin/bash")
reviewed = BooleanField(default=False)
displayname = CharField(max_length=100, blank=False, null=False)
@property
def home_path(self):
@ -25,10 +26,6 @@ class Townie(User):
is."""
raise NotImplementedError()
def __init__(self):
self.set_unusable_password()
super().__init__(self)
@receiver(post_save, sender=Townie)
def sync_system_state(sender, instance, created, **kwargs):
if created:

View File

@ -26,7 +26,7 @@
</label>
<label>
public key:
<textarea name="pubkey"></textarea>
<textarea name="pubkey" required="true"></textarea>
</label>
<input type="submit" value="sign up <3" />
</form>

View File

@ -1,8 +1,43 @@
from django.http import HttpResponse
from django.views.generic import TemplateView
from .models import Townie
# TODO validation functions for final request validation and live js validation
# I refuse to duplicate the logic for validation on the front-end and am going
# to accept round-trip validation costs with long-term caching.
class UserSignupView(TemplateView):
template_name = 'ttadmin/signup.html'
def post(self, request):
print(request.POST)
# TODO validate
username = request.POST.get('username')
displayname = request.POST.get('displayname')
if displayname is None:
displayname = username
else:
# TODO validate
pass
# TODO validate
pubkey = request.POST.get('pubkey')
# TODO validate
email = request.POST.get('email')
t = Townie(
username=username,
displayname=displayname,
pubkey=pubkey,
email=email,
)
t.set_unusable_password()
t.save()
return HttpResponse('LOLOLOLOL')