Now loads user data to database and user id to session on login
This commit is contained in:
parent
ba0d572cb1
commit
327052322a
@ -6,6 +6,7 @@ from django.http import HttpResponseRedirect
|
|||||||
import requests
|
import requests
|
||||||
import hashlib
|
import hashlib
|
||||||
import json
|
import json
|
||||||
|
from .models import User
|
||||||
|
|
||||||
# Create your views here.
|
# Create your views here.
|
||||||
# Redirect url should point to this view
|
# Redirect url should point to this view
|
||||||
@ -41,6 +42,21 @@ class LoginRedirect(View):
|
|||||||
r.status = 500
|
r.status = 500
|
||||||
return r
|
return r
|
||||||
else:
|
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']
|
req.session['token'] = resp_json['access_token']
|
||||||
return HttpResponseRedirect('/')
|
return HttpResponseRedirect('/')
|
||||||
else:
|
else:
|
||||||
|
Reference in New Issue
Block a user