Exemplo n.º 1
0
    def dispatch(self, request, *args, **kwargs):
        self.room_name = kwargs['room']
        try:
            room = ROOM_DICT[self.room_name]
        except KeyError:
            return HttpResponseNotFound('Invalid room specified in url')

        self.uses_pin = room.has_pin_code()

        label = self.request.GET.get('participant_label', '')

        if room.has_participant_labels():
            if not label:
                if not room.use_secure_urls:
                    return render_to_response("otree/RoomInputLabel.html")

            if not label in room.get_participant_labels():
                return HttpResponseNotFound(_('Invalid participant label.'))

            if room.use_secure_urls:
                hash = self.request.GET.get('hash')
                if hash != make_hash(label):
                    return HttpResponseNotFound('Invalid hash parameter.')

        if self.uses_pin:
            pin_code = self.request.GET.get('pin')
            if not pin_code:
                return super(AssignVisitorToRoom, self).get(args, kwargs)

            if pin_code != room.get_pin_code():
                return HttpResponseNotFound('The given pin code is incorrect.')

        session = room.session
        if session is None:
            self.tab_unique_id = otree.common_internal.random_chars_10()
            self._socket_url_params = ','.join([
                self.room_name,
                label,
                # random chars in case the participant has multiple tabs open
                self.tab_unique_id,
            ])
            return render_to_response(
                "otree/WaitPageRoom.html", {
                    'view': self,
                    'title_text': _('Please wait'),
                    'body_text': _('Waiting for your session to begin')
                })

        if label:
            cookies = None
        else:
            cookies = request.session

        # 2017-08-02: changing the behavior so that even in a room without
        # participant_label_file, 2 requests for the same start URL with same label
        # will return the same participant. Not sure if the previous behavior
        # (assigning to 2 different participants) was intentional or bug.
        return participant_start_page_or_404(session,
                                             label=label,
                                             cookies=cookies)
Exemplo n.º 2
0
    def get(self, *args, **kwargs):

        room_name = self.request.GET.get(
            'room'
        )
        try:
            room = ROOM_DICT[room_name]
        except KeyError:
            return HttpResponseNotFound('Invalid room specified in url')

        participant_label = self.request.GET.get(
            'participant_label'
        )
        if room.has_participant_labels():
            if not participant_label:
                if not room.use_secure_urls:
                    return super(AssignVisitorToRoom, self).get(args, kwargs)

            if participant_label not in room.get_participant_labels():
                return HttpResponseNotFound(
                    'Participant is not expected in this room. '
                    'Please contact the session supervisor.')
            if room.use_secure_urls:
                hash = self.request.GET.get('hash')
                if hash != make_hash(participant_label):
                    return HttpResponseNotFound('Invalid hash parameter.')

        session = room.session
        if session is None:
            return HttpResponse('No session in room. Refresh the page.')

        assign_new = not room.has_participant_labels()
        if not assign_new:
            try:
                participant = Participant.objects.get(
                    session=session,
                    label=participant_label
                )
            except Participant.DoesNotExist:
                assign_new = True

        if assign_new:
            with lock_on_this_code_path():
                try:
                    participant = (
                        Participant.objects.filter(
                            session=session,
                            visited=False)
                    ).order_by('start_order')[0]
                except IndexError:
                    return HttpResponseNotFound(NO_PARTICIPANTS_LEFT_MSG)

                participant.label = participant_label
                # 2014-10-17: needs to be here even if it's also set in
                # the next view to prevent race conditions
                participant.visited = True
                participant.save()

        return HttpResponseRedirect(participant._start_url())
Exemplo n.º 3
0
    def dispatch(self, request, *args, **kwargs):
        self.room_name = kwargs['room']
        try:
            room = ROOM_DICT[self.room_name]
        except KeyError:
            return HttpResponseNotFound('Invalid room specified in url')

        label = self.request.GET.get('participant_label', '')

        if room.has_participant_labels():
            if label:
                missing_label = False
                invalid_label = label not in room.get_participant_labels()
            else:
                missing_label = True
                invalid_label = False

            # needs to be easy to re-enter label, in case we are in kiosk
            # mode
            if missing_label or invalid_label and not room.use_secure_urls:
                return render_to_response("otree/RoomInputLabel.html",
                                          {'invalid_label': invalid_label})

            if room.use_secure_urls:
                hash = self.request.GET.get('hash')
                if hash != make_hash(label):
                    return HttpResponseNotFound(
                        'Invalid hash parameter. use_secure_urls is True, '
                        'so you must use the participant-specific URL.')

        session = room.get_session()
        if session is None:
            self.tab_unique_id = otree.common_internal.random_chars_10()
            self._socket_url = channel_utils.room_participant_path(
                self.room_name,
                label,
                # random chars in case the participant has multiple tabs open
                self.tab_unique_id)
            return render_to_response(
                "otree/WaitPageRoom.html", {
                    'view': self,
                    'title_text': _('Please wait'),
                    'body_text': _('Waiting for your session to begin')
                })

        if label:
            cookies = None
        else:
            cookies = request.session

        # 2017-08-02: changing the behavior so that even in a room without
        # participant_label_file, 2 requests for the same start URL with same label
        # will return the same participant. Not sure if the previous behavior
        # (assigning to 2 different participants) was intentional or bug.
        return participant_start_page_or_404(session,
                                             label=label,
                                             cookies=cookies)
Exemplo n.º 4
0
    def dispatch(self, request, *args, **kwargs):
        self.room_name = kwargs['room']
        try:
            room = ROOM_DICT[self.room_name]
        except KeyError:
            return HttpResponseNotFound('Invalid room specified in url')

        label = self.request.GET.get(
            'participant_label', ''
        )

        if room.has_participant_labels():
            if not label:
                if not room.use_secure_urls:
                    return render_to_response("otree/RoomInputLabel.html")

            if not label in room.get_participant_labels():
                return HttpResponseNotFound(
                    _('Invalid participant label.')
                )

            if room.use_secure_urls:
                hash = self.request.GET.get('hash')
                if hash != make_hash(label):
                    return HttpResponseNotFound('Invalid hash parameter.')

        session = room.session
        if session is None:
            self.tab_unique_id = otree.common_internal.random_chars_10()
            self._socket_url = channel_utils.room_participant_path(
                self.room_name,
                label,
                # random chars in case the participant has multiple tabs open
                self.tab_unique_id
            )
            return render_to_response(
                "otree/WaitPageRoom.html",
                {
                    'view': self, 'title_text': _('Please wait'),
                    'body_text': _('Waiting for your session to begin')
                }
            )

        if label:
            cookies = None
        else:
            cookies = request.session


        # 2017-08-02: changing the behavior so that even in a room without
        # participant_label_file, 2 requests for the same start URL with same label
        # will return the same participant. Not sure if the previous behavior
        # (assigning to 2 different participants) was intentional or bug.
        return participant_start_page_or_404(session, label=label, cookies=cookies)
Exemplo n.º 5
0
    def get(self, *args, **kwargs):

        room_name = self.request.GET.get('room')
        try:
            room = ROOM_DICT[room_name]
        except KeyError:
            return HttpResponseNotFound('Invalid room specified in url')

        participant_label = self.request.GET.get('participant_label')
        if room.has_participant_labels():
            if not participant_label:
                if not room.use_secure_urls:
                    return super(AssignVisitorToRoom, self).get(args, kwargs)

            if participant_label not in room.get_participant_labels():
                return HttpResponseNotFound(
                    'Participant is not expected in this room. Please contact the session supervisor.'
                )

            if room.use_secure_urls:
                hash = self.request.GET.get('hash')
                if hash != make_hash(participant_label):
                    return HttpResponseNotFound('Invalid hash parameter.')

        session = room.session
        if session is None:
            return HttpResponse('No session in room. Refresh the page.')

        assign_new = not room.has_participant_labels()
        if not assign_new:
            try:
                participant = Participant.objects.get(session=session,
                                                      label=participant_label)
            except Participant.DoesNotExist:
                assign_new = True

        if assign_new:
            with lock_on_this_code_path():
                try:
                    participant = (Participant.objects.filter(
                        session=session,
                        visited=False)).order_by('start_order')[0]
                except IndexError:
                    return HttpResponseNotFound(NO_PARTICIPANTS_LEFT_MSG)

                participant.label = participant_label
                # 2014-10-17: needs to be here even if it's also set in
                # the next view to prevent race conditions
                participant.visited = True
                participant.save()

        return HttpResponseRedirect(participant._start_url())
Exemplo n.º 6
0
    def get_participant_urls(self, request):
        participant_urls = []
        room_base_url = reverse('AssignVisitorToRoom', args=(self.name, ))
        room_base_url = request.build_absolute_uri(room_base_url)

        if self.has_participant_labels():
            for label in self.get_participant_labels():
                params = {'participant_label': label}
                if self.use_secure_urls:
                    params['hash'] = make_hash(label)
                participant_url = add_params_to_url(room_base_url, params)
                participant_urls.append(participant_url)

        return participant_urls
Exemplo n.º 7
0
    def get_participant_links(self):
        participant_urls = []
        room_base_url = add_params_to_url(reverse('assign_visitor_to_room'), {'room': self.name})
        if self.has_participant_labels():
            for label in self.get_participant_labels():
                params = {'participant_label': label}
                if self.use_secure_urls:
                    params['hash'] = make_hash(label)
                participant_url = add_params_to_url(room_base_url, params)
                participant_urls.append(participant_url)
        else:
            participant_urls = [room_base_url]

        return participant_urls
Exemplo n.º 8
0
    def get_participant_urls(self, request):
        participant_urls = []
        room_base_url = reverse('AssignVisitorToRoom', args=(self.name,))
        room_base_url = request.build_absolute_uri(room_base_url)

        if self.has_participant_labels():
            for label in self.get_participant_labels():
                params = {'participant_label': label}
                if self.use_secure_urls:
                    params['hash'] = make_hash(label)
                participant_url = add_params_to_url(room_base_url, params)
                participant_urls.append(participant_url)

        return participant_urls
Exemplo n.º 9
0
    def get_participant_links(self):
        participant_urls = []
        room_base_url = add_params_to_url(reverse('assign_visitor_to_room'),
                                          {'room': self.name})
        if self.has_participant_labels():
            for label in self.get_participant_labels():
                params = {'participant_label': label}
                if self.use_secure_urls:
                    params['hash'] = make_hash(label)
                participant_url = add_params_to_url(room_base_url, params)
                participant_urls.append(participant_url)
        else:
            participant_urls = [room_base_url]

        return participant_urls
Exemplo n.º 10
0
    def dispatch(self, request, *args, **kwargs):
        self.room_name = kwargs['room']
        try:
            room = ROOM_DICT[self.room_name]
        except KeyError:
            return HttpResponseNotFound('Invalid room specified in url')

        self.uses_pin = room.has_pin_code()

        participant_label = self.request.GET.get('participant_label', '')

        if room.has_participant_labels():
            if not participant_label:
                if not room.use_secure_urls:
                    return super(AssignVisitorToRoom, self).get(args, kwargs)

            if participant_label not in room.get_participant_labels():
                return HttpResponseNotFound(_('Invalid participant label.'))

            if room.use_secure_urls:
                hash = self.request.GET.get('hash')
                if hash != make_hash(participant_label):
                    return HttpResponseNotFound('Invalid hash parameter.')

        if self.uses_pin:
            pin_code = self.request.GET.get('pin')
            if not pin_code:
                return super(AssignVisitorToRoom, self).get(args, kwargs)

            if pin_code != room.get_pin_code():
                return HttpResponseNotFound('The given pin code is incorrect.')

        session = room.session
        if session is None:
            self.tab_unique_id = otree.common_internal.random_chars_10()
            self._socket_url_params = ','.join([
                self.room_name,
                participant_label,
                # random chars in case the participant has multiple tabs open
                self.tab_unique_id,
            ])
            return render_to_response(
                "otree/WaitPageRoom.html", {
                    'view': self,
                    'title_text': _('Please wait'),
                    'body_text': _('Waiting for your session to begin')
                })

        assign_new = not room.has_participant_labels()
        if not assign_new:
            try:
                participant = session.get_participants().get(
                    label=participant_label)
            except Participant.DoesNotExist:
                assign_new = True

        if assign_new:
            with global_lock():
                try:
                    participant = session.get_participants().filter(
                        visited=False).order_by('start_order')[0]
                except IndexError:
                    return HttpResponseNotFound(NO_PARTICIPANTS_LEFT_MSG)

                participant.label = participant_label
                # 2014-10-17: needs to be here even if it's also set in
                # the next view to prevent race conditions
                participant.visited = True
                participant.save()

        return HttpResponseRedirect(participant._start_url())
Exemplo n.º 11
0
    def dispatch(self, request, *args, **kwargs):
        self.room_name = kwargs["room"]
        try:
            room = ROOM_DICT[self.room_name]
        except KeyError:
            return HttpResponseNotFound("Invalid room specified in url")

        self.uses_pin = room.has_pin_code()

        participant_label = self.request.GET.get("participant_label", "")

        if room.has_participant_labels():
            if not participant_label:
                if not room.use_secure_urls:
                    return super(AssignVisitorToRoom, self).get(args, kwargs)

            if participant_label not in room.get_participant_labels():
                return HttpResponseNotFound(_("Invalid participant label."))

            if room.use_secure_urls:
                hash = self.request.GET.get("hash")
                if hash != make_hash(participant_label):
                    return HttpResponseNotFound("Invalid hash parameter.")

        if self.uses_pin:
            pin_code = self.request.GET.get("pin")
            if not pin_code:
                return super(AssignVisitorToRoom, self).get(args, kwargs)

            if pin_code != room.get_pin_code():
                return HttpResponseNotFound("The given pin code is incorrect.")

        session = room.session
        if session is None:
            self.tab_unique_id = otree.common_internal.random_chars_10()
            self._socket_url_params = ",".join(
                [
                    self.room_name,
                    participant_label,
                    # random chars in case the participant has multiple tabs open
                    self.tab_unique_id,
                ]
            )
            return render_to_response(
                "otree/WaitPageRoom.html",
                {"view": self, "title_text": _("Please wait"), "body_text": _("Waiting for your session to begin")},
            )

        assign_new = not room.has_participant_labels()
        if not assign_new:
            try:
                participant = session.get_participants().get(label=participant_label)
            except Participant.DoesNotExist:
                assign_new = True

        if assign_new:
            with global_lock():
                try:
                    participant = session.get_participants().filter(visited=False).order_by("start_order")[0]
                except IndexError:
                    return HttpResponseNotFound(NO_PARTICIPANTS_LEFT_MSG)

                participant.label = participant_label
                # 2014-10-17: needs to be here even if it's also set in
                # the next view to prevent race conditions
                participant.visited = True
                participant.save()

        return HttpResponseRedirect(participant._start_url())