From 28533e030088f6822ee7967ed10d4fb114bc944b Mon Sep 17 00:00:00 2001 From: Tanner Collin Date: Fri, 14 Sep 2018 20:09:48 -0600 Subject: [PATCH] Perform auth against the Protospace member portal --- authserver/authserver/api/views.py | 13 +++++++------ authserver/authserver/settings.py | 2 ++ authserver/requirements.txt | 5 +++++ 3 files changed, 14 insertions(+), 6 deletions(-) diff --git a/authserver/authserver/api/views.py b/authserver/authserver/api/views.py index 5d0aca6..4cf99a9 100644 --- a/authserver/authserver/api/views.py +++ b/authserver/authserver/api/views.py @@ -1,3 +1,5 @@ +import requests + from django.contrib.auth.models import User from rest_framework import mixins, permissions, status, viewsets @@ -6,6 +8,7 @@ from rest_framework.decorators import api_view from rest_framework.response import Response from . import models, serializers +from authserver.settings import PROTOSPACE_LOGIN_PAGE class IsLockoutAdmin(permissions.BasePermission): def has_permission(self, request, view): @@ -56,12 +59,10 @@ def login(request): return Response({'error': 'Please provide both username and password'}, status=status.HTTP_400_BAD_REQUEST) - - # perform hacky auth... - #user = authenticate(username=username, password=password) - #if not user: - # return Response({'error': 'Invalid Credentials'}, status=status.HTTP_404_NOT_FOUND) - + post_data = {'user_name': username, 'web_pw': password, 'SubmitButton': 'Login'} + res = requests.post(PROTOSPACE_LOGIN_PAGE, post_data, allow_redirects=False) + if res.status_code == requests.codes.ok: + return Response({'error': 'Invalid Credentials'}, status=status.HTTP_404_NOT_FOUND) user, created = User.objects.get_or_create(username=username) user.set_password(password) # not validated diff --git a/authserver/authserver/settings.py b/authserver/authserver/settings.py index e2b575f..2fa18eb 100644 --- a/authserver/authserver/settings.py +++ b/authserver/authserver/settings.py @@ -119,3 +119,5 @@ STATIC_URL = '/static/' MEDIA_ROOT = os.path.join(BASE_DIR, 'media') MEDIA_URL = '/media/' + +PROTOSPACE_LOGIN_PAGE = 'https://my.protospace.ca/login' diff --git a/authserver/requirements.txt b/authserver/requirements.txt index e2778a6..81d5fab 100644 --- a/authserver/requirements.txt +++ b/authserver/requirements.txt @@ -1,4 +1,9 @@ +certifi==2018.8.24 +chardet==3.0.4 Django==2.1.1 djangorestframework==3.8.2 +idna==2.7 Pillow==5.2.0 pytz==2018.5 +requests==2.19.1 +urllib3==1.23