Пример #1
0
    def post(self, request, *args, **kwargs):
        try:
            data = json.loads(request.body.decode('utf-8'))
        except ValueError:
            return HttpResponseBadRequest()

        if not data or not isinstance(data, dict):
            return HttpResponseBadRequest()

        session_id = data.get('sessionId', None)
        if not session_id:
            return HttpResponseBadRequest()

        session = get_session(session_id)
        user = get_django_user_from_session(session)
        if user:
            couch_user = CouchUser.get_by_username(user.username)
            if not couch_user:
                raise Http404
        else:
            raise Http404

        domain = data.get('domain')
        if domain and DISABLE_WEB_APPS.enabled(domain):
            return HttpResponse('Service Temporarily Unavailable',
                                content_type='text/plain',
                                status=503)

        # reset the session's expiry if there's some formplayer activity
        secure_session = session.get('secure_session')
        TimeoutMiddleware.update_secure_session(session,
                                                secure_session,
                                                couch_user,
                                                domain=data.get('domain'))
        session.save()

        domains = set()
        for domain in couch_user.domains:
            domains.add(domain)
            mirror_domains = DomainPermissionsMirror.mirror_domains(domain)
            domains.update(mirror_domains)

        return JsonResponse({
            'username': user.username,
            'djangoUserId': user.pk,
            'superUser': user.is_superuser,
            'authToken': None,
            'domains': list(domains),
            'anonymous': False
        })
Пример #2
0
    def post(self, request, *args, **kwargs):
        try:
            data = json.loads(request.body.decode('utf-8'))
        except ValueError:
            return HttpResponseBadRequest()

        if not data or not isinstance(data, dict):
            return HttpResponseBadRequest()

        session_id = data.get('sessionId', None)
        if not session_id:
            return HttpResponseBadRequest()

        session = get_session(session_id)
        user = get_django_user_from_session(session)
        if user:
            couch_user = CouchUser.get_by_username(user.username)
            if not couch_user:
                raise Http404
        else:
            raise Http404

        # reset the session's expiry if there's some formplayer activity
        secure_session = session.get('secure_session')
        if secure_session:
            timeout = settings.SECURE_TIMEOUT
            domain = data.get('domain')
            if domain:
                domain_obj = Domain.get_by_name(domain)
                if domain_obj:
                    timeout = domain_obj.secure_timeout or timeout
        else:
            timeout = settings.INACTIVITY_TIMEOUT

        session.set_expiry(timeout * 60)
        session.save()

        return JsonResponse({
            'username': user.username,
            'djangoUserId': user.pk,
            'superUser': user.is_superuser,
            'authToken': None,
            'domains': couch_user.domains,
            'anonymous': False
        })
Пример #3
0
    def post(self, request, *args, **kwargs):
        try:
            data = json.loads(request.body)
        except ValueError:
            return HttpResponseBadRequest()

        if not data or not isinstance(data, dict):
            return HttpResponseBadRequest()

        session_id = data.get('sessionId', None)
        if not session_id:
            return HttpResponseBadRequest()

        session = get_session(session_id)
        user = get_django_user_from_session(session)
        if user:
            couch_user = CouchUser.get_by_username(user.username)
            if not couch_user:
                raise Http404
        else:
            raise Http404

        # reset the session's expiry if there's some formplayer activity
        secure_session = session.get('secure_session')
        timeout = settings.SECURE_TIMEOUT if secure_session else settings.INACTIVITY_TIMEOUT
        session.set_expiry(timeout * 60)
        session.save()

        return JsonResponse({
            'username': user.username,
            'djangoUserId': user.pk,
            'superUser': user.is_superuser,
            'authToken': None,
            'domains': couch_user.domains,
            'anonymous': False
        })