Now loads user data to database and user id to session on login

This commit is contained in:
Taizo 'Tsa6' Simpson 2017-09-22 17:48:39 -04:00
parent ba0d572cb1
commit 327052322a

View File

@ -6,6 +6,7 @@ from django.http import HttpResponseRedirect
import requests
import hashlib
import json
from .models import User
# Create your views here.
# Redirect url should point to this view
@ -41,6 +42,21 @@ class LoginRedirect(View):
r.status = 500
return r
else:
user_info = requests.get(
settings.AUTH_TOKEN_ENDPOINT+"user",
headers = {
'Authorization': 'Bearer ' + resp_json['access_token']
}
).json()
req.session['user_id'] = user_info['uuid']
matches = User.objects.filter(user_id=user_info['uuid'])
if not len(matches):
user = User(
user_id = user_info['uuid'],
email = user_info['email'],
display_name = user_info['display_name']
)
user.save()
req.session['token'] = resp_json['access_token']
return HttpResponseRedirect('/')
else: