From 11966e71cdc9e8d89eb58a2e742c69aba5fc386e Mon Sep 17 00:00:00 2001 From: c0de Date: Thu, 8 Mar 2018 22:54:14 -0600 Subject: [PATCH] Adding the Account app --- account/__init__.py | 0 account/admin.py | 6 ++++ account/apps.py | 8 +++++ account/migrations/0001_initial.py | 29 ++++++++++++++++++ account/migrations/__init__.py | 0 account/models.py | 42 +++++++++++++++++++++++++ account/tests.py | 6 ++++ account/urls.py | 15 +++++++++ account/views.py | 49 ++++++++++++++++++++++++++++++ gallery/settings.py | 1 + gallery/urls.py | 3 +- gallery/wsgi.py | 2 ++ run.sh | 1 + 13 files changed, 161 insertions(+), 1 deletion(-) create mode 100644 account/__init__.py create mode 100644 account/admin.py create mode 100644 account/apps.py create mode 100644 account/migrations/0001_initial.py create mode 100644 account/migrations/__init__.py create mode 100644 account/models.py create mode 100644 account/tests.py create mode 100644 account/urls.py create mode 100644 account/views.py diff --git a/account/__init__.py b/account/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/account/admin.py b/account/admin.py new file mode 100644 index 0000000..13be29d --- /dev/null +++ b/account/admin.py @@ -0,0 +1,6 @@ +# -*- coding: utf-8 -*- +from __future__ import unicode_literals + +from django.contrib import admin + +# Register your models here. diff --git a/account/apps.py b/account/apps.py new file mode 100644 index 0000000..aa89c9a --- /dev/null +++ b/account/apps.py @@ -0,0 +1,8 @@ +# -*- coding: utf-8 -*- +from __future__ import unicode_literals + +from django.apps import AppConfig + + +class AccountConfig(AppConfig): + name = 'account' diff --git a/account/migrations/0001_initial.py b/account/migrations/0001_initial.py new file mode 100644 index 0000000..aae0480 --- /dev/null +++ b/account/migrations/0001_initial.py @@ -0,0 +1,29 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.11.4 on 2018-03-09 04:52 +from __future__ import unicode_literals + +from django.conf import settings +from django.db import migrations, models +import django.db.models.deletion +import uuid + + +class Migration(migrations.Migration): + + initial = True + + dependencies = [ + migrations.swappable_dependency(settings.AUTH_USER_MODEL), + ] + + operations = [ + migrations.CreateModel( + name='Account', + fields=[ + ('id', models.UUIDField(default=uuid.uuid4, editable=False, primary_key=True, serialize=False)), + ('first_login', models.BooleanField(default=True)), + ('accepted_terms', models.DateTimeField(blank=True, null=True)), + ('user', models.OneToOneField(on_delete=django.db.models.deletion.PROTECT, to=settings.AUTH_USER_MODEL)), + ], + ), + ] diff --git a/account/migrations/__init__.py b/account/migrations/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/account/models.py b/account/models.py new file mode 100644 index 0000000..c130ac6 --- /dev/null +++ b/account/models.py @@ -0,0 +1,42 @@ +# -*- coding: utf-8 -*- +from __future__ import unicode_literals + +from django.contrib.auth.models import User +from django.core.signing import Signer +from django.utils import timezone +from django.conf import settings +from django.db import models + +import uuid + +# Foreign key to logged-in users +AUTH_USER_MODEL = getattr(settings, 'AUTH_USER_MODEL', 'auth.User') + +class Account(models.Model): + id = models.UUIDField(primary_key=True, + default=uuid.uuid4, + editable=False) + user = models.OneToOneField(AUTH_USER_MODEL, + on_delete=models.PROTECT) + first_login = models.BooleanField(default=True) + accepted_terms = models.DateTimeField(auto_now=False, + auto_now_add=False, + blank=True, + null=True) + + def __str__(self): + return "<%s:%s>" % (self.id, self.user.username) + + def create_user(self, username, first_name, last_name, email, password): + # Create a user + usr_obj = User.objects.get_or_create(username=username, + first_name=first_name, + last_name=last_name, + email=email) + usr_obj.set_password(password) + usr_obj.save() + + self.user = usr_obj + self.save() + + return self diff --git a/account/tests.py b/account/tests.py new file mode 100644 index 0000000..5982e6b --- /dev/null +++ b/account/tests.py @@ -0,0 +1,6 @@ +# -*- coding: utf-8 -*- +from __future__ import unicode_literals + +from django.test import TestCase + +# Create your tests here. diff --git a/account/urls.py b/account/urls.py new file mode 100644 index 0000000..6b5ad3f --- /dev/null +++ b/account/urls.py @@ -0,0 +1,15 @@ +# -*- coding: utf-8 -*- +from __future__ import unicode_literals + +from django.conf.urls import url +from . import views + +urlpatterns = [ + url(r'^$', views.index, name='index'), + url(r'^login$', views.login, name='login'), + url(r'^logout$', views.logout, name='logout'), + url(r'^terms$', views.terms, name='terms'), + url(r'^reset/(?P[a-zA-Z0-9:_-]*)$', views.reset, name='reset'), + url(r'^firstlogin/(?P[a-zA-Z0-9:_-]*)$', views.firstlogin, name='firstlogin'), + url(r'^create$', views.create, name='reset'), +] diff --git a/account/views.py b/account/views.py new file mode 100644 index 0000000..869d200 --- /dev/null +++ b/account/views.py @@ -0,0 +1,49 @@ +# -*- coding: utf-8 -*- +from __future__ import unicode_literals + +from django.shortcuts import render +from gallery.utility import _ResponseTemplate, _ForceLogout +from django.conf import settings +from django.contrib import auth + +from django.views.decorators.csrf import csrf_exempt +from django.http import HttpResponse, HttpResponseRedirect, HttpResponseNotFound, HttpResponseNotAllowed +from django.utils import timezone, dateparse +from rest_framework import views, response, status +from rest_framework.renderers import JSONRenderer +from django.core.exceptions import ObjectDoesNotExist + +import json + +from .models import * + +def _resetPassword(key, password): + signer = Signer(salt="portalpwreset") + key = signer.unsign(key) + user = auth.models.User.objects.get(pk=key) + user.set_password(password) + user.save() + return user + +def index(request): + # if not request.user.is_authenticated(): + # return _ForceLogout(request, 'Please sign in') + pass + +def login(request): + pass + +def logout(request): + pass + +def terms(request): + pass + +def reset(request): + pass + +def firstlogin(request): + pass + +def create(request): + pass diff --git a/gallery/settings.py b/gallery/settings.py index a0a7627..e1abe3d 100644 --- a/gallery/settings.py +++ b/gallery/settings.py @@ -41,6 +41,7 @@ EMAIL_HOST_PASSWORD = '' # Application definition INSTALLED_APPS = [ + 'account.apps.AccountConfig', 'django.contrib.admin', 'django.contrib.auth', 'django.contrib.contenttypes', diff --git a/gallery/urls.py b/gallery/urls.py index a40b5fb..3a28c82 100644 --- a/gallery/urls.py +++ b/gallery/urls.py @@ -13,9 +13,10 @@ 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.conf.urls import include, url from django.contrib import admin urlpatterns = [ + url(r'^account/', include('account.urls')), url(r'^admin/', admin.site.urls), ] diff --git a/gallery/wsgi.py b/gallery/wsgi.py index 28e817f..fca1906 100644 --- a/gallery/wsgi.py +++ b/gallery/wsgi.py @@ -8,9 +8,11 @@ https://docs.djangoproject.com/en/1.11/howto/deployment/wsgi/ """ import os +import gallery.gzip from django.core.wsgi import get_wsgi_application os.environ.setdefault("DJANGO_SETTINGS_MODULE", "gallery.settings") application = get_wsgi_application() +application = gallery.gzip.UnzipRequestMiddleware(application) diff --git a/run.sh b/run.sh index 0f21171..0a2a783 100755 --- a/run.sh +++ b/run.sh @@ -2,5 +2,6 @@ cd /portal #cp msmtprc /etc sleep 1 # Hopefully enough for the database to start accepting connections +python manage.py makemigrations python manage.py migrate python manage.py runserver 0.0.0.0:8000