tildetown-admin/ttadmin/users/views.py

49 lines
1.2 KiB
Python
Raw Normal View History

2016-11-20 05:34:38 +00:00
from django.http import HttpResponse
from django.views.generic import TemplateView
2016-11-22 05:14:47 +00:00
from .models import Townie, SSH_TYPE_CHOICES
2016-11-21 07:56:55 +00:00
# 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.
2016-11-20 05:34:38 +00:00
class UserSignupView(TemplateView):
template_name = 'ttadmin/signup.html'
2016-11-22 05:14:47 +00:00
def get_context_data(self):
ctx = super().get_context_data()
ctx['ssh_type_choices'] = SSH_TYPE_CHOICES
return ctx
2016-11-20 05:34:38 +00:00
def post(self, request):
2016-11-21 07:56:55 +00:00
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()
2016-11-20 05:34:38 +00:00
return HttpResponse('LOLOLOLOL')