Adding the Account app

This commit is contained in:
c0de 2018-03-08 22:54:14 -06:00
parent 51a117ca5f
commit 11966e71cd
13 changed files with 161 additions and 1 deletions

0
account/__init__.py Normal file
View File

6
account/admin.py Normal file
View File

@ -0,0 +1,6 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.contrib import admin
# Register your models here.

8
account/apps.py Normal file
View File

@ -0,0 +1,8 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.apps import AppConfig
class AccountConfig(AppConfig):
name = 'account'

View File

@ -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)),
],
),
]

View File

42
account/models.py Normal file
View File

@ -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

6
account/tests.py Normal file
View File

@ -0,0 +1,6 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.test import TestCase
# Create your tests here.

15
account/urls.py Normal file
View File

@ -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<key>[a-zA-Z0-9:_-]*)$', views.reset, name='reset'),
url(r'^firstlogin/(?P<key>[a-zA-Z0-9:_-]*)$', views.firstlogin, name='firstlogin'),
url(r'^create$', views.create, name='reset'),
]

49
account/views.py Normal file
View File

@ -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

View File

@ -41,6 +41,7 @@ EMAIL_HOST_PASSWORD = ''
# Application definition
INSTALLED_APPS = [
'account.apps.AccountConfig',
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',

View File

@ -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),
]

View File

@ -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)

1
run.sh
View File

@ -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