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

Outline of API in place

parent d490f3bc
...@@ -36,4 +36,3 @@ services: ...@@ -36,4 +36,3 @@ services:
- GO_EMAIL_HOST_PASSWORD= - GO_EMAIL_HOST_PASSWORD=
- GO_EMAIL_FROM= - GO_EMAIL_FROM=
- GO_EMAIL_TO= - GO_EMAIL_TO=
- SUPERUSER=dhaynes3
...@@ -8,7 +8,7 @@ export GO_SECRET_KEY ...@@ -8,7 +8,7 @@ export GO_SECRET_KEY
export GO_CREATE_SUPERUSER export GO_CREATE_SUPERUSER
GO_SECRET_KEY=$(dd if=/dev/urandom count=100 | tr -dc "A-Za-z0-9" | fold -w 60 | head -n1 2>/dev/null) 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'; me.save(); " 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'; me.save(); "
python go/manage.py makemigrations python go/manage.py makemigrations
python go/manage.py makemigrations go python go/manage.py makemigrations go
...@@ -16,3 +16,4 @@ python go/manage.py migrate ...@@ -16,3 +16,4 @@ python go/manage.py migrate
python go/manage.py createsuperuser --noinput --username="$SUPERUSER" --email="$SUPERUSER$GO_EMAIL_DOMAIN" python go/manage.py createsuperuser --noinput --username="$SUPERUSER" --email="$SUPERUSER$GO_EMAIL_DOMAIN"
echo "$GO_CREATE_SUPERUSER" | python go/manage.py shell echo "$GO_CREATE_SUPERUSER" | python go/manage.py shell
python go/manage.py runserver 0.0.0.0:8000 python go/manage.py runserver 0.0.0.0:8000
\ No newline at end of file
...@@ -77,36 +77,29 @@ def create_user(tree: list): ...@@ -77,36 +77,29 @@ def create_user(tree: list):
Create a django user based off of the peoplefinder info we parsed earlier. Create a django user based off of the peoplefinder info we parsed earlier.
""" """
print("Parsing CAS information.") print("Parsing CAS information.")
try: try:
username = tree[0][0].text username = tree[0][0].text
user, user_created = User.objects.get_or_create(username=username) # error handling in pfinfo function
except Exception as ex: info_name = pfinfo(username)
print("CAS callback unsuccessful:", ex) # set and save the user's email
email_str = "%s%s" % (username, settings.EMAIL_DOMAIN)
# error handling in pfinfo function user, user_created = User.objects.get_or_create(
info_name = pfinfo(username) username=username,
email=email_str,
first_name=info_name[0],
last_name=info_name[1]
)
# 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.
user.set_password('cas_used_instead')
user.save()
try:
if user_created: if user_created:
print("Created user object %s." % username) print("Created user object %s." % username)
# set and save the user's email
email_str = "%s%s" % (username, settings.EMAIL_DOMAIN)
user.email = email_str
# 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.
user.set_password('cas_used_instead')
user.save()
print("Added user's email, %s." % email_str)
user.first_name = info_name[0]
user.last_name = info_name[1]
user.save()
print("Added user's name, %s %s." % (info_name[0], info_name[1]))
print("User object creation process completed.")
else: else:
print("User object already exists.") print("User object already exists.")
print("CAS callback successful.")
except Exception as ex: 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): ...@@ -90,7 +90,7 @@ def handle_reguser_creation(sender, instance, created, **kwargs):
is called to create an associated RegisteredUser. is called to create an associated RegisteredUser.
""" """
if created: if created:
RegisteredUser.objects.create(user=instance) RegisteredUser.objects.create(user=instance, full_name=instance.get_full_name())
@receiver(post_save, sender=settings.AUTH_USER_MODEL) @receiver(post_save, sender=settings.AUTH_USER_MODEL)
def create_auth_token(sender, instance=None, created=False, **kwargs): def create_auth_token(sender, instance=None, created=False, **kwargs):
......
...@@ -3,16 +3,27 @@ go/serializers.py ...@@ -3,16 +3,27 @@ go/serializers.py
Define how data is translated from the database to json/API representation. Define how data is translated from the database to json/API representation.
""" """
# Django Imports
from django.contrib.auth.models import User, Group from django.contrib.auth.models import User, Group
# App Imports
from .models import URL, RegisteredUser
# Third Party Imports
from rest_framework import serializers from rest_framework import serializers
class UserSerializer(serializers.HyperlinkedModelSerializer): class UserSerializer(serializers.HyperlinkedModelSerializer):
class Meta: class Meta:
model = User 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: class Meta:
model = Group model = URL
fields = ('url', 'name') fields = '__all__'
This diff is collapsed.
...@@ -19,7 +19,6 @@ from rest_framework import routers ...@@ -19,7 +19,6 @@ from rest_framework import routers
router = routers.DefaultRouter() router = routers.DefaultRouter()
router.register(r'users', views.UserViewSet) router.register(r'users', views.UserViewSet)
router.register(r'groups', views.GroupViewSet)
router.register(r'my', views.URLViewSet, base_name="my") router.register(r'my', views.URLViewSet, base_name="my")
router.register(r'registereduser', views.RegisteredUserViewSet) 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