Commit 4a95d159 authored by David Haynes's avatar David Haynes 🙆

Outline of API in place

parent d490f3bc
......@@ -36,4 +36,3 @@ services:
- SUPERUSER=dhaynes3
......@@ -8,7 +8,7 @@ export GO_SECRET_KEY
GO_SECRET_KEY=$(dd if=/dev/urandom count=100 | tr -dc "A-Za-z0-9" | fold -w 60 | head -n1 2>/dev/null)
GO_CREATE_SUPERUSER="from django.contrib.auth import get_user_model; User = get_user_model(); me = User.objects.get(username='$SUPERUSER'); me.first_name = 'David'; me.last_name = 'Haynes';; "
GO_CREATE_SUPERUSER="from django.contrib.auth import get_user_model; User = get_user_model(); me = User.objects.get(username='admin'); me.first_name = 'mr'; me.last_name = 'admin';; "
python go/ makemigrations
python go/ makemigrations go
......@@ -16,3 +16,4 @@ python go/ migrate
python go/ createsuperuser --noinput --username="$SUPERUSER" --email="$SUPERUSER$GO_EMAIL_DOMAIN"
echo "$GO_CREATE_SUPERUSER" | python go/ shell
python go/ runserver
\ No newline at end of file
......@@ -77,36 +77,29 @@ def create_user(tree: list):
Create a django user based off of the peoplefinder info we parsed earlier.
print("Parsing CAS information.")
username = tree[0][0].text
user, user_created = User.objects.get_or_create(username=username)
except Exception as ex:
print("CAS callback unsuccessful:", ex)
# error handling in pfinfo function
info_name = pfinfo(username)
if user_created:
print("Created user object %s." % username)
# set and save the user's email
email_str = "%s%s" % (username, settings.EMAIL_DOMAIN) = email_str
user, user_created = User.objects.get_or_create(
# Password is a required User object field, though doesn't matter for our
# purposes because all user auth is handled through CAS, not Django's login.
print("Added user's email, %s." % email_str)
user.first_name = info_name[0]
user.last_name = info_name[1]
print("Added user's name, %s %s." % (info_name[0], info_name[1]))
print("User object creation process completed.")
if user_created:
print("Created user object %s." % username)
print("User object already exists.")
print("CAS callback successful.")
except Exception as ex:
print("Unhandled user creation error:", ex)
print("CAS callback unsuccessful:", ex)
......@@ -90,7 +90,7 @@ def handle_reguser_creation(sender, instance, created, **kwargs):
is called to create an associated RegisteredUser.
if created:
RegisteredUser.objects.create(user=instance, full_name=instance.get_full_name())
@receiver(post_save, sender=settings.AUTH_USER_MODEL)
def create_auth_token(sender, instance=None, created=False, **kwargs):
......@@ -3,16 +3,27 @@ go/
Define how data is translated from the database to json/API representation.
# Django Imports
from django.contrib.auth.models import User, Group
# App Imports
from .models import URL, RegisteredUser
# Third Party Imports
from rest_framework import serializers
class UserSerializer(serializers.HyperlinkedModelSerializer):
class Meta:
model = User
fields = ('url', 'username', 'email', 'groups')
fields = ('url', 'username', 'email', 'first_name',
'last_name', 'is_staff')
class RegisteredUserSerializer(serializers.HyperlinkedModelSerializer):
class Meta:
model = RegisteredUser
fields = '__all__'
class GroupSerializer(serializers.HyperlinkedModelSerializer):
class URLSerializer(serializers.HyperlinkedModelSerializer):
class Meta:
model = Group
fields = ('url', 'name')
model = URL
fields = '__all__'
This diff is collapsed.
......@@ -19,7 +19,6 @@ from rest_framework import routers
router = routers.DefaultRouter()
router.register(r'users', views.UserViewSet)
router.register(r'groups', views.GroupViewSet)
router.register(r'my', views.URLViewSet, base_name="my")
router.register(r'registereduser', views.RegisteredUserViewSet)
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment