Wednesday, April 29, 2020

Can anyone please help?

Can anyone please help me to resolve this issue?

https://stackoverflow.com/q/61514512/1316060

My url path in project's url.py is defined as follows:

path('endpoint/', views.Endpoint.as_view(), name='get_endpoint'),

The views.py include the following class to handle this routing:

@method_decorator(csrf_exempt, name='dispatch')   class Endpoint(View):      def get(self, request, *args, **kwargs):          ############ Here I can see the User Session ##########          if not request.user.is_authenticated:              return redirect('authentication_router')            return redirect(              'https://app.globus.org/file-manager?method=POST&action=%s&cancelurl=%s&folderlimit=1&filelimit=0&label=%s'              % (              request.build_absolute_uri(), "/", "To Transfer your Files Select the Folder first!")          )        def post(self, request, *args, **kwargs):  # On return from OAuth Page          ############ Here, User Session return nothing so user is AnonymousUser ##########          if request.POST.get('folder[0]'):  # A Endpoint folder was selected              endpoint_path = os.path.join(request.POST.get('path'), request.POST.get('folder[0]'))          else:              endpoint_path = request.POST.get('path')                 profile = request.user.userprofile # request.user does not has userprofile          profile.endpoint_path = endpoint_path          profile.save()            return HttpResponseRedirect(reverse('authentication_router'))

The problem is when the get is called it finds the request.user value as authenticated user but once the redirect from OAUTH page with POST hits the class it loss all request user session and gives error at this line:

profile = request.user.userprofile

As, request.user seems loss its session and has value of AnonymousUser even though till GET method it is preserving the user's login session values.

My settings.py file includes:

INSTALLED_APPS = [      'django.contrib.admin',      'django.contrib.auth',      'django.contrib.contenttypes',      **'django.contrib.sessions',**      'django.contrib.messages',      'django.contrib.staticfiles',      'django.contrib.sites',      'myapp',  ]    MIDDLEWARE = [      'django.middleware.security.SecurityMiddleware',      'django.contrib.sessions.middleware.SessionMiddleware',      'django.middleware.common.CommonMiddleware',      'django.middleware.csrf.CsrfViewMiddleware',      **'django.contrib.auth.middleware.AuthenticationMiddleware',**      'django.contrib.messages.middleware.MessageMiddleware',      'django.middleware.clickjacking.XFrameOptionsMiddleware',  ]

I am testing it in localhost:8000 .Please let me know what I am missing this code. Same code is perfectly working in Django 1.8 and Python 2.7. Recently, I am trying to upgrade it to work with Django 3 and Python 3. Only difference I can see is in settings.py in Django 1.8 version includes: 'django.contrib.auth.middleware.SessionAuthenticationMiddleware',in MIDDLEWARE_CLASSES which is removed in latest version of Django.


--
Thank you,

Milson

Virus-free. www.avg.com

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CAP1qhGui2o%3DDJD57Rq7GaiVO-s9wOgSdw1G-bNLPSYCL9Wkeuw%40mail.gmail.com.

No comments:

Post a Comment