aboutsummaryrefslogtreecommitdiffstats
path: root/accounts/views.py
diff options
context:
space:
mode:
authorAndrea Lepori <alepori@student.ethz.ch>2022-01-02 18:31:34 +0100
committerAndrea Lepori <alepori@student.ethz.ch>2022-01-02 18:31:56 +0100
commit655957935a2c2daec3f5f1640754915d1bf26d6f (patch)
tree1398499d626691f55d81c323dacaa81957a96a7f /accounts/views.py
parentadd account data validation (diff)
downloadscout-subs-655957935a2c2daec3f5f1640754915d1bf26d6f.tar.gz
scout-subs-655957935a2c2daec3f5f1640754915d1bf26d6f.zip
pof of oauth2
Diffstat (limited to '')
-rw-r--r--accounts/views.py26
1 files changed, 25 insertions, 1 deletions
diff --git a/accounts/views.py b/accounts/views.py
index c73ecfd..ef2d6c1 100644
--- a/accounts/views.py
+++ b/accounts/views.py
@@ -1,4 +1,7 @@
from django.shortcuts import render
+from django.urls import reverse
+from django.conf import settings
+from django.contrib.auth.views import LoginView
from django.contrib.auth.forms import UserCreationForm
from django.contrib.auth import login, authenticate
from django.http import FileResponse
@@ -8,8 +11,11 @@ from django.http import HttpResponseRedirect
from client.models import UserCode
+from authlib.integrations.django_client import OAuth
+
import dateparser
import os
+import requests
from io import BytesIO
from PIL import Image, UnidentifiedImageError
from pdf2image import convert_from_bytes
@@ -18,6 +24,9 @@ from pdf2image.exceptions import (
PDFSyntaxError
)
+oauth = OAuth()
+hitobito = oauth.register(name="hitobito")
+
# override to remove help text
class RegisterForm(UserCreationForm):
def __init__(self, *args, **kwargs):
@@ -26,6 +35,22 @@ class RegisterForm(UserCreationForm):
for fieldname in ['username', 'password1', 'password2']:
self.fields[fieldname].help_text = None
+def oauth_login(request):
+ redirect_uri = request.build_absolute_uri(reverse('auth'))
+ return hitobito.authorize_redirect(request, redirect_uri)
+
+def auth(request):
+ token = hitobito.authorize_access_token(request)
+ print(token)
+ headers = {
+ "Authorization" : "Bearer " + token["access_token"],
+ "X-Scope": "with_roles",
+ }
+ resp = requests.get("https://demo.hitobito.com/oauth/profile", headers=headers)
+ print(resp)
+ print(resp.text)
+ return HttpResponseRedirect('/')
+
@sensitive_variables("raw_passsword")
def signup(request):
out_errors = []
@@ -76,7 +101,6 @@ def signup(request):
}
return render(request, 'accounts/signup.html', context)
-
@login_required
def personal(request):
context = {}