64 lines
2.0 KiB
Python
64 lines
2.0 KiB
Python
import requests
|
|
from django.conf import settings
|
|
from django.contrib.auth.mixins import LoginRequiredMixin
|
|
from django.http.response import HttpResponse
|
|
from django.shortcuts import render
|
|
from django.views.decorators.csrf import ensure_csrf_cookie
|
|
from django.views.generic import TemplateView
|
|
from graphene_django.views import GraphQLView
|
|
|
|
from core import hep_client
|
|
from core.hep_client import HepClient
|
|
from core.models import AdminData
|
|
from core.oauth import oauth
|
|
|
|
|
|
class PrivateGraphQLView(LoginRequiredMixin, GraphQLView):
|
|
pass
|
|
|
|
|
|
@ensure_csrf_cookie
|
|
def home(request):
|
|
if settings.SERVE_VIA_WEBPACK:
|
|
try:
|
|
res = requests.get('http://localhost:8080/{}'.format(request.get_full_path()))
|
|
headers = res.headers
|
|
content_type = headers.get('content-type', 'text/html')
|
|
return HttpResponse(res.text, content_type=content_type)
|
|
except Exception as e:
|
|
print('Can not connect to dev server at http://localhost:8080:', e)
|
|
|
|
return render(request, 'index.html', {})
|
|
|
|
|
|
class ConfirmationKeyDisplayView(TemplateView):
|
|
template_name = 'confirmation_key.html'
|
|
|
|
def get_context_data(self, *args, **kwargs):
|
|
|
|
email = self.request.GET.get('email', '')
|
|
|
|
hep_client = HepClient()
|
|
admin_token = AdminData.objects.get_admin_token()
|
|
hep_user = hep_client.customers_search(admin_token, email)
|
|
|
|
context = super().get_context_data(**kwargs)
|
|
context['confirmation_key'] = hep_user['confirmation']
|
|
context['hep_id'] = hep_user['id']
|
|
return context
|
|
|
|
|
|
def login(request):
|
|
hep_oauth_client = oauth.create_client('hep')
|
|
redirect_uri = settings.OAUTH_REDIRECT_URI
|
|
return hep_oauth_client.authorize_redirect(request, redirect_uri)
|
|
|
|
|
|
def authorize(request):
|
|
token = oauth.hep.authorize_access_token(request)
|
|
profile = hep_client.user_details(token)
|
|
print(profile)
|
|
# user, status_msg = handle_user_and_verify_products(user_data)
|
|
# do something with the token and profile
|
|
return '...'
|