from django.contrib.auth.decorators import login_required from django.shortcuts import render from django.utils.decorators import method_decorator from django.views.generic import TemplateView from django.contrib.sessions.backends.db import SessionStore from django.contrib.sessions.models import Session from rest_framework import mixins from rest_framework.permissions import AllowAny from rest_framework.response import Response from rest_framework.views import APIView from rest_framework.viewsets import GenericViewSet from apps.core.decorators import service_availability from apps.core.models import Config from apps.core.serializers import ConfigSerializer from apps.gooyal_oauth2.rest_framework import IsAuthenticatedOrTokenMatchesOASRequirements # @method_decorator(login_required, name='dispatch') class HomeView(TemplateView): template_name = 'core/home.html' # def get(self, request, *args, **kwargs): # session = request.session # print(type(session)) # print(session.session_key) # return super(HomeView, self).get(request, *args, **kwargs) class TestIpView(TemplateView): template_name = 'core/home.html' def get(self, request, *args, **kwargs): print(request.headers) headers_data = {'Host': 'accounts.gooyal.ir', 'X-Real-Ip': '212.23.216.131', 'X-Forwarded-For': '5.216.121.72, 212.23.216.131', 'X-Forwarded-Proto': 'http', 'Connection': 'close', 'User-Agent': 'Mozilla/5.0 (X11; Linux x86_64; rv:128.0) Gecko/20100101 Firefox/128.0', 'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8', 'Accept-Language': 'en,en-US;q=0.7,fa;q=0.3', 'Accept-Encoding': 'gzip, deflate, br, zstd', 'Cookie': 'csrftoken=xor4RVhDDuhQ5l4hf44iI3o2I0FJU8kJ; sessionid=3c0kju13bswh6ufu3mdnl1u38wi7d4b3', 'Upgrade-Insecure-Requests': '1', 'Sec-Fetch-Dest': 'document', 'Sec-Fetch-Mode': 'navigate', 'Sec-Fetch-Site': 'none', 'Sec-Fetch-User': '?1', 'Priority': 'u=0, i'} return super(TestIpView, self).get(request, *args, **kwargs) class ConfigViewSet(mixins.ListModelMixin, GenericViewSet): queryset = Config.objects.all() serializer_class = ConfigSerializer permission_classes = [AllowAny] class StatusView(APIView): permission_classes = [IsAuthenticatedOrTokenMatchesOASRequirements] required_alternate_scopes = { "GET": [["accounts.status:get"]], } @service_availability('status') def get(self, request, format=None): data = { "status": "ok", } return Response(data) class HealthcheckView(APIView): permission_classes = [AllowAny] def get(self, request, format=None): data = { "is_healthy": True } return Response(data)