fix structure

pull/1/head
nathaniel smith 2016-11-19 21:34:38 -08:00
parent e721da031f
commit 9f5f47cd46
15 changed files with 157 additions and 26 deletions

View File

@ -3,7 +3,7 @@ import os
import sys import sys
if __name__ == "__main__": if __name__ == "__main__":
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "ttadmin.settings") os.environ.setdefault("DJANGO_SETTINGS_MODULE", "settings")
try: try:
from django.core.management import execute_from_command_line from django.core.management import execute_from_command_line
except ImportError: except ImportError:

View File

@ -10,6 +10,8 @@ For the full list of settings and their values, see
https://docs.djangoproject.com/en/1.10/ref/settings/ https://docs.djangoproject.com/en/1.10/ref/settings/
""" """
# Local settings for dev
import os import os
# Build paths inside the project like this: os.path.join(BASE_DIR, ...) # Build paths inside the project like this: os.path.join(BASE_DIR, ...)
@ -37,6 +39,7 @@ INSTALLED_APPS = [
'django.contrib.sessions', 'django.contrib.sessions',
'django.contrib.messages', 'django.contrib.messages',
'django.contrib.staticfiles', 'django.contrib.staticfiles',
'users'
] ]
MIDDLEWARE = [ MIDDLEWARE = [
@ -49,12 +52,12 @@ MIDDLEWARE = [
'django.middleware.clickjacking.XFrameOptionsMiddleware', 'django.middleware.clickjacking.XFrameOptionsMiddleware',
] ]
ROOT_URLCONF = 'ttadmin.urls' ROOT_URLCONF = 'urls'
TEMPLATES = [ TEMPLATES = [
{ {
'BACKEND': 'django.template.backends.django.DjangoTemplates', 'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [], 'DIRS': ['users/templates'],
'APP_DIRS': True, 'APP_DIRS': True,
'OPTIONS': { 'OPTIONS': {
'context_processors': [ 'context_processors': [
@ -67,7 +70,7 @@ TEMPLATES = [
}, },
] ]
WSGI_APPLICATION = 'ttadmin.wsgi.application' WSGI_APPLICATION = 'wsgi.application'
# Database # Database

View File

@ -1,21 +0,0 @@
"""ttadmin URL Configuration
The `urlpatterns` list routes URLs to views. For more information please see:
https://docs.djangoproject.com/en/1.10/topics/http/urls/
Examples:
Function views
1. Add an import: from my_app import views
2. Add a URL to urlpatterns: url(r'^$', views.home, name='home')
Class-based views
1. Add an import: from other_app.views import Home
2. Add a URL to urlpatterns: url(r'^$', Home.as_view(), name='home')
Including another URLconf
1. Import the include() function: from django.conf.urls import url, include
2. Add a URL to urlpatterns: url(r'^blog/', include('blog.urls'))
"""
from django.conf.urls import url
from django.contrib import admin
urlpatterns = [
url(r'^admin/', admin.site.urls),
]

7
ttadmin/urls.py 100644
View File

@ -0,0 +1,7 @@
from django.conf.urls import url, include
from django.contrib import admin
urlpatterns = [
url(r'^users/', include('users.urls')),
url(r'^admin/', admin.site.urls),
]

View File

@ -0,0 +1,6 @@
from django.contrib import admin
from .models import Townie
@admin.register(Townie)
class TownieAdmin(admin.ModelAdmin):
pass

View File

@ -0,0 +1,5 @@
from django.apps import AppConfig
class UsersConfig(AppConfig):
name = 'users'

View File

@ -0,0 +1,38 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.10.2 on 2016-11-19 02:48
from __future__ import unicode_literals
from django.conf import settings
import django.contrib.auth.models
from django.db import migrations, models
import django.db.models.deletion
class Migration(migrations.Migration):
initial = True
dependencies = [
('auth', '0008_alter_user_username_max_length'),
]
operations = [
migrations.CreateModel(
name='Townie',
fields=[
('user_ptr', models.OneToOneField(auto_created=True, on_delete=django.db.models.deletion.CASCADE, parent_link=True, primary_key=True, serialize=False, to=settings.AUTH_USER_MODEL)),
('pubkey', models.TextField()),
('shell', models.TextField(default='/bin/bash', max_length=50)),
('pending', models.BooleanField(default=True)),
],
options={
'verbose_name': 'user',
'verbose_name_plural': 'users',
'abstract': False,
},
bases=('auth.user',),
managers=[
('objects', django.contrib.auth.models.UserManager()),
],
),
]

View File

@ -0,0 +1,39 @@
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
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)
@property
def home_path(self):
return "/home/{}".format(self.username)
def accept(self):
"""Sets self.pending to False. Indicates the user has been signed up
after review."""
self.pending = False
def ensure_shell(self):
"""Runs chsh for the user to set their shell to whatever self.shell
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:
print('TODO would create new user on system')
else:
print('TODO would update existing user on system')
return

View File

@ -0,0 +1,34 @@
<!DOCTYPE html>
<html>
<head>
<title>tilde.town signup page</title>
</head>
<body>
<h1>sign up for a tilde.town account</h1>
{% if error_message %}<p><strong>{{ error_message }}</strong></p>{% endif %}
<form action="{% url 'users:signup' %}" method="post">
{% csrf_token %}
<!-- TODO captcha of some kind -->
<!-- TODO help text. how best to do? could throw this all in a table :3 -->
<label>
desired username:
<input type="text" required="true" name="username">
</label>
<label>
email address:
<input name="email" type="email" required="true">
</label>
<label>
display name:
<input name="displayname" type="text">
</label>
<label>
public key:
<textarea name="pubkey"></textarea>
</label>
<input type="submit" value="sign up <3" />
</form>
</body>
</html>

View File

@ -0,0 +1,3 @@
from django.test import TestCase
# Create your tests here.

View File

@ -0,0 +1,9 @@
from django.conf.urls import url
from .views import UserSignupView
app_name = 'users'
urlpatterns = [
url(r'^signup/?$', UserSignupView.as_view(), name='signup'),
]

View File

@ -0,0 +1,8 @@
from django.http import HttpResponse
from django.views.generic import TemplateView
class UserSignupView(TemplateView):
template_name = 'ttadmin/signup.html'
def post(self, request):
return HttpResponse('LOLOLOLOL')

View File

@ -11,6 +11,6 @@ import os
from django.core.wsgi import get_wsgi_application from django.core.wsgi import get_wsgi_application
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "ttadmin.settings") os.environ.setdefault("DJANGO_SETTINGS_MODULE", "settings")
application = get_wsgi_application() application = get_wsgi_application()