Ejemplo n.º 1
0
    def get(self):
        open_humans = self.get_secure_cookie('open-humans')

        # If the user isn't authenticated render the page to allow them to
        # authenticate
        if not open_humans:
            ag_login_id = ag_data.get_user_for_kit(self.current_user)
            human_participants = ag_data.getHumanParticipants(ag_login_id)

            survey_ids = {}

            for participant_name in human_participants:
                survey_id = ag_data.get_survey_id(ag_login_id,
                                                  participant_name)

                if survey_id:
                    survey_ids[participant_name] = survey_id

            self.render('open-humans.html',
                        skid=self.current_user,
                        survey_ids=survey_ids,
                        access_token=None,
                        origin=self.coerce_origin(),
                        open_humans_home_url=self._HOME_URL,
                        open_humans_research_url=self._RESEARCH_URL,
                        open_humans_api_url=self._API_URL)

            return

        open_humans = escape.json_decode(open_humans)

        self.open_humans_request(
            '/american-gut/user-data/',
            self._on_user_data_cb,
            access_token=open_humans['access_token'])
Ejemplo n.º 2
0
    def get(self):
        open_humans = self.get_secure_cookie('open-humans')

        # If the user isn't authenticated render the page to allow them to
        # authenticate
        if not open_humans:
            ag_login_id = ag_data.get_user_for_kit(self.current_user)
            human_participants = ag_data.getHumanParticipants(ag_login_id)

            survey_ids = {}

            for participant_name in human_participants:
                # Get survey ID 1, the main human survey
                survey_id = ag_data.get_survey_ids(ag_login_id,
                                                   participant_name)[1]

                if survey_id:
                    survey_ids[participant_name] = survey_id

            self.render('open-humans.html',
                        skid=self.current_user,
                        survey_ids=survey_ids,
                        access_token=None,
                        origin=self.coerce_origin(),
                        open_humans_home_url=self._HOME_URL,
                        open_humans_research_url=self._RESEARCH_URL,
                        open_humans_api_url=self._API_URL)

            return

        open_humans = escape.json_decode(open_humans)

        self.open_humans_request('/american-gut/user-data/',
                                 self._on_user_data_cb,
                                 access_token=open_humans['access_token'])
Ejemplo n.º 3
0
    def on_message(self, msg):
        tl = text_locale['handlers']
        skid = self.current_user
        participant_name = msg

        ag_login_id = ag_data.get_user_for_kit(skid)
        human_participants = ag_data.getHumanParticipants(ag_login_id)
        animal_participants = ag_data.getAnimalParticipants(ag_login_id)

        if participant_name in (human_participants + animal_participants):
            # if the participant already exists in the system, fail nicely
            output_message = (tl['PARTICIPANT_EXISTS'] % participant_name)
        else:
            # otherwise, success!
            output_message = 'success'

        self.write_message(output_message)
Ejemplo n.º 4
0
    def on_message(self, msg):
        tl = text_locale['handlers']
        skid = self.current_user
        participant_name = msg

        ag_login_id = ag_data.get_user_for_kit(skid)
        human_participants = ag_data.getHumanParticipants(ag_login_id)
        animal_participants = ag_data.getAnimalParticipants(ag_login_id)

        if participant_name in (human_participants + animal_participants):
            # if the participant already exists in the system, fail nicely
            output_message = (tl['PARTICIPANT_EXISTS'] % participant_name)
        else:
            # otherwise, success!
            output_message = 'success'

        self.write_message(output_message)
Ejemplo n.º 5
0
    def _on_user_data_cb(self, user_data):
        open_humans = escape.json_decode(self.get_secure_cookie('open-humans'))

        try:
            link_survey_id = escape.json_decode(
                base64.b64decode(self.get_cookie('link-survey-id')))
        except (AttributeError, ValueError, TypeError):
            link_survey_id = None

        if link_survey_id:
            self.open_humans_request(
                '/american-gut/user-data/',
                self._on_post_user_data_cb,
                method='PATCH',
                body={'data': {
                    'surveyIds': link_survey_id
                }},
                access_token=open_humans['access_token'])

            return

        survey_ids = {}

        ag_login_id = ag_data.get_user_for_kit(self.current_user)
        human_participants = ag_data.getHumanParticipants(ag_login_id)

        for participant_name in human_participants:
            # Get survey ID 1, the main human survey
            survey_id = ag_data.get_survey_ids(ag_login_id,
                                               participant_name)[1]

            if survey_id:
                survey_ids[participant_name] = survey_id

        self.render('open-humans.html',
                    skid=self.current_user,
                    survey_ids=survey_ids,
                    access_token=open_humans['access_token'],
                    origin=self.coerce_origin(),
                    open_humans_home_url=self._HOME_URL,
                    open_humans_research_url=self._RESEARCH_URL,
                    open_humans_api_url=self._API_URL)
Ejemplo n.º 6
0
    def _on_user_data_cb(self, user_data):
        open_humans = escape.json_decode(self.get_secure_cookie('open-humans'))

        try:
            link_survey_id = escape.json_decode(
                base64.b64decode(self.get_cookie('link-survey-id')))
        except (AttributeError, ValueError, TypeError):
            link_survey_id = None

        if link_survey_id:
            self.open_humans_request(
                '/american-gut/user-data/',
                self._on_post_user_data_cb,
                method='PATCH',
                body={'data': {'surveyIds': link_survey_id}},
                access_token=open_humans['access_token'])

            return

        survey_ids = {}

        ag_login_id = ag_data.get_user_for_kit(self.current_user)
        human_participants = ag_data.getHumanParticipants(ag_login_id)

        for participant_name in human_participants:
            # Get survey ID 1, the main human survey
            survey_id = ag_data.get_survey_ids(ag_login_id,
                                               participant_name)[1]

            if survey_id:
                survey_ids[participant_name] = survey_id

        self.render('open-humans.html',
                    skid=self.current_user,
                    survey_ids=survey_ids,
                    access_token=open_humans['access_token'],
                    origin=self.coerce_origin(),
                    open_humans_home_url=self._HOME_URL,
                    open_humans_research_url=self._RESEARCH_URL,
                    open_humans_api_url=self._API_URL)