diff --git a/ttadmin/manage.py b/ttadmin/manage.py index 6954924..7646e46 100755 --- a/ttadmin/manage.py +++ b/ttadmin/manage.py @@ -3,7 +3,7 @@ import os import sys if __name__ == "__main__": - os.environ.setdefault("DJANGO_SETTINGS_MODULE", "ttadmin.settings") + os.environ.setdefault("DJANGO_SETTINGS_MODULE", "settings") try: from django.core.management import execute_from_command_line except ImportError: diff --git a/ttadmin/ttadmin/settings.py b/ttadmin/settings.py similarity index 95% rename from ttadmin/ttadmin/settings.py rename to ttadmin/settings.py index 159bc13..863e9fc 100644 --- a/ttadmin/ttadmin/settings.py +++ b/ttadmin/settings.py @@ -10,6 +10,8 @@ For the full list of settings and their values, see https://docs.djangoproject.com/en/1.10/ref/settings/ """ +# Local settings for dev + import os # Build paths inside the project like this: os.path.join(BASE_DIR, ...) @@ -37,6 +39,7 @@ INSTALLED_APPS = [ 'django.contrib.sessions', 'django.contrib.messages', 'django.contrib.staticfiles', + 'users' ] MIDDLEWARE = [ @@ -49,12 +52,12 @@ MIDDLEWARE = [ 'django.middleware.clickjacking.XFrameOptionsMiddleware', ] -ROOT_URLCONF = 'ttadmin.urls' +ROOT_URLCONF = 'urls' TEMPLATES = [ { 'BACKEND': 'django.template.backends.django.DjangoTemplates', - 'DIRS': [], + 'DIRS': ['users/templates'], 'APP_DIRS': True, 'OPTIONS': { 'context_processors': [ @@ -67,7 +70,7 @@ TEMPLATES = [ }, ] -WSGI_APPLICATION = 'ttadmin.wsgi.application' +WSGI_APPLICATION = 'wsgi.application' # Database diff --git a/ttadmin/ttadmin/urls.py b/ttadmin/ttadmin/urls.py deleted file mode 100644 index b9c0539..0000000 --- a/ttadmin/ttadmin/urls.py +++ /dev/null @@ -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), -] diff --git a/ttadmin/urls.py b/ttadmin/urls.py new file mode 100644 index 0000000..e05c4d7 --- /dev/null +++ b/ttadmin/urls.py @@ -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), +] diff --git a/ttadmin/ttadmin/__init__.py b/ttadmin/users/__init__.py similarity index 100% rename from ttadmin/ttadmin/__init__.py rename to ttadmin/users/__init__.py diff --git a/ttadmin/users/admin.py b/ttadmin/users/admin.py new file mode 100644 index 0000000..bbde176 --- /dev/null +++ b/ttadmin/users/admin.py @@ -0,0 +1,6 @@ +from django.contrib import admin +from .models import Townie + +@admin.register(Townie) +class TownieAdmin(admin.ModelAdmin): + pass diff --git a/ttadmin/users/apps.py b/ttadmin/users/apps.py new file mode 100644 index 0000000..4ce1fab --- /dev/null +++ b/ttadmin/users/apps.py @@ -0,0 +1,5 @@ +from django.apps import AppConfig + + +class UsersConfig(AppConfig): + name = 'users' diff --git a/ttadmin/users/migrations/0001_initial.py b/ttadmin/users/migrations/0001_initial.py new file mode 100644 index 0000000..6cb20ed --- /dev/null +++ b/ttadmin/users/migrations/0001_initial.py @@ -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()), + ], + ), + ] diff --git a/ttadmin/users/migrations/__init__.py b/ttadmin/users/migrations/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/ttadmin/users/models.py b/ttadmin/users/models.py new file mode 100644 index 0000000..2826e63 --- /dev/null +++ b/ttadmin/users/models.py @@ -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 diff --git a/ttadmin/users/templates/ttadmin/signup.html b/ttadmin/users/templates/ttadmin/signup.html new file mode 100644 index 0000000..ebeda0e --- /dev/null +++ b/ttadmin/users/templates/ttadmin/signup.html @@ -0,0 +1,34 @@ + + + + tilde.town signup page + + +

sign up for a tilde.town account

+ + {% if error_message %}

{{ error_message }}

{% endif %} + +
+ {% csrf_token %} + + + + + + + +
+ + diff --git a/ttadmin/users/tests.py b/ttadmin/users/tests.py new file mode 100644 index 0000000..7ce503c --- /dev/null +++ b/ttadmin/users/tests.py @@ -0,0 +1,3 @@ +from django.test import TestCase + +# Create your tests here. diff --git a/ttadmin/users/urls.py b/ttadmin/users/urls.py new file mode 100644 index 0000000..9e4f7ba --- /dev/null +++ b/ttadmin/users/urls.py @@ -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'), + +] diff --git a/ttadmin/users/views.py b/ttadmin/users/views.py new file mode 100644 index 0000000..f3dc413 --- /dev/null +++ b/ttadmin/users/views.py @@ -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') diff --git a/ttadmin/ttadmin/wsgi.py b/ttadmin/wsgi.py similarity index 82% rename from ttadmin/ttadmin/wsgi.py rename to ttadmin/wsgi.py index 613050b..dd61023 100644 --- a/ttadmin/ttadmin/wsgi.py +++ b/ttadmin/wsgi.py @@ -11,6 +11,6 @@ import os 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()