def create_passcode_and_send_email(self, email, kit_id):
        kitids = AG_DATA_ACCESS.getAGKitIDsByEmail(email)
        latlongs = AG_DATA_ACCESS.getMapMarkers()
        tl = text_locale['handlers']
        #if the kit id matches the email generate and send an email
        if kit_id in kitids:
            alphabet = letters + digits
            new_act_code = ''.join([choice(alphabet) for i in range(20)])
            # add new pass to the database
            AG_DATA_ACCESS.ag_set_pass_change_code(email, kit_id, new_act_code)
            MESSAGE = (tl['RESET_PASS_BODY'] % (kit_id, quote(email), kit_id,
                                                quote(new_act_code)))

            #send the user an email and tell them to change their password
            try:
                    send_email(MESSAGE, tl['CHANGE_PASS_SUBJECT'], email)
                    self.render('forgot_password.html', email='', kitid='',
                                result=1, message='',
                                latlongs_db=latlongs, loginerror='')
            except:
                    self.render('forgot_password.html', email='', kitid='',
                                result=2, message=MESSAGE,
                                latlongs_db=latlongs, loginerror='')

        else:
            self.render('forgot_password.html', email='', kitid='',
                        result=3, message='',
                        latlongs_db=latlongs, loginerror='')
 def reset_pass_and_email(self, new_password, confirm_password, email,
                          supplied_kit_id):
     AG_DATA_ACCESS.ag_update_kit_password(supplied_kit_id, new_password)
     latlongs = AG_DATA_ACCESS.getMapMarkers()
     tl = text_locale['handlers']
     MESSAGE = tl['CHANGE_PASS_BODY'] % supplied_kit_id
     try:
         send_email(MESSAGE, tl['CHANGE_PASS_SUBJECT'], email)
         self.render('change_pass_verify.html',
                     email='',
                     kitid='',
                     passocde='',
                     new_password='',
                     confirm_password='',
                     result=4,
                     message='',
                     latlongs_db=latlongs,
                     loginerror='')
     except:
         self.render('change_pass_verify.html',
                     email='',
                     kitid='',
                     passocde='',
                     new_password='',
                     confirm_password='',
                     result=5,
                     message='',
                     latlongs_db=latlongs,
                     loginerror='')
Beispiel #3
0
    def get(self):
        errmsg = self.get_argument('errmsg', "")
        kit_id = self.current_user

        user_info = AG_DATA_ACCESS.get_user_info(kit_id)
        user_name = user_info['name']

        kit_details = AG_DATA_ACCESS.getAGKitDetails(kit_id)
        kit_verified = True if kit_details['kit_verified'] == 'y' else False

        results = AG_DATA_ACCESS.get_barcode_results(kit_id)
        has_results = len(results) != 0

        barcodes = AG_DATA_ACCESS.getBarcodesByKit(kit_id)

        kit_ver_error = False
        verification_textbox = ''

        self.render("portal.html",
                    skid=kit_id,
                    user_name=user_name,
                    errmsg=errmsg,
                    kit_verified=kit_verified,
                    has_results=has_results,
                    results=results,
                    barcodes=barcodes,
                    kit_ver_error=kit_ver_error,
                    verification_textbox=verification_textbox)
    def post(self):
        bc_to_remove = self.get_argument("remove", None)
        if bc_to_remove:
            ag_login_id = AG_DATA_ACCESS.get_user_for_kit(self.current_user)
            AG_DATA_ACCESS.deleteSample(bc_to_remove, ag_login_id)
            self.redirect(media_locale['SITEBASE'] + "/authed/portal/")

        self._sample_overview_renderer()
    def post(self):
        bc_to_remove = self.get_argument("remove", None)
        if bc_to_remove:
            ag_login_id = AG_DATA_ACCESS.get_user_for_kit(self.current_user)
            AG_DATA_ACCESS.deleteSample(bc_to_remove, ag_login_id)
            self.redirect(media_locale['SITEBASE'] + "/authed/portal/")

        self._sample_overview_renderer()
    def post(self):
        tl = text_locale['handlers']
        deceased_parent = self.get_argument("deceased_parent", None)
        participant_name = self.get_argument("participant_name")
        is_juvenile = self.get_argument("is_juvenile", 'off')

        ag_login_id = AG_DATA_ACCESS.get_user_for_kit(self.current_user)
        kit_email = AG_DATA_ACCESS.get_user_info(self.current_user)['email']

        # Get the list of participants attached to that login id
        participants = AG_DATA_ACCESS.getHumanParticipants(ag_login_id)

        # Check if the participant is on the exceptions list
        is_exception = (
            participant_name
            in AG_DATA_ACCESS.getParticipantExceptions(ag_login_id))

        # If the participant already exists, stop them outright
        if participant_name in participants:
            errmsg = tl['PARTICIPANT_EXISTS'] % participant_name
            self.redirect(media_locale['SITEBASE'] + "/authed/portal/?errmsg=%s" % errmsg)

        if is_juvenile == 'off' and is_exception:
            errmsg = ("We are expecting a survey from that juvenile user (%s)"
                      % participant_name)
            self.redirect(media_locale['SITEBASE'] + "/authed/portal/?errmsg=%s" % errmsg)

        if is_juvenile == 'on':
            # If they aren't already an exception, we need to verify them
            if not is_exception:
                juvenile_age = self.get_argument("juvenile_age")
                parent_1_name = self.get_argument("parent_1_name")
                parent_2_name = self.get_argument("parent_2_name")

                alert_message = tl['MINOR_PARENTAL_BODY']

                subject = ("AGJUVENILE: %s (ag_login_id: %s) is a child"
                           % (participant_name, ag_login_id))

                message = MESSAGE_TEMPLATE % (participant_name, juvenile_age,
                                              parent_1_name, parent_2_name,
                                              deceased_parent,
                                              self.current_user, kit_email)

                try:
                    send_email(message, subject, sender=kit_email)
                    alert_message = tl['MESSAGE_SENT']
                except:
                    alert_message = media_locale['EMAIL_ERROR']

                self.redirect(media_locale['SITEBASE'] + "/authed/portal/?errmsg=%s" % alert_message)

        self.redirect(media_locale['SITEBASE'] + "/authed/survey_main/")
Beispiel #7
0
    def get(self):
        kit_id = self.current_user
        ag_login_id = AG_DATA_ACCESS.get_user_for_kit(kit_id)
        kit_barcodes = AG_DATA_ACCESS.getAvailableBarcodes(ag_login_id)
        participant_name = self.get_argument('participant_name',
                                             'environmetal')

        form = LogSample()
        form.barcode.choices = [(v, v) for v in kit_barcodes]
        form.sample_site.choices = self._get_sample_sites()

        self.render('add_sample.html', skid=kit_id,
                    kit_barcodes=kit_barcodes,
                    participant_name=participant_name,
                    form=form)
Beispiel #8
0
 def reset_pass_and_email(self, new_password, confirm_password, email,
                          supplied_kit_id):
     tl = text_locale['handlers']
     AG_DATA_ACCESS.ag_update_kit_password(supplied_kit_id, new_password)
     MESSAGE = tl['CHANGE_PASS_BODY'] % supplied_kit_id
     try:
         send_email(MESSAGE, tl['CHANGE_PASS_SUBJECT'], email)
         self.render('change_password.html', email='',
                     skid=self.current_user,
                     new_password='', confirm_password='', result=4,
                     message='')
     except:
         self.render('change_password.html', email='',
                     skid=self.current_user,
                     new_password='', confirm_password='', result=5,
                     message='')
Beispiel #9
0
    def post(self):
        email = self.get_argument('email')
        tl = text_locale['handlers']
        if email:
            kitids = AG_DATA_ACCESS.getAGKitIDsByEmail(email)
        try:
            if len(kitids) > 0:
                MESSAGE = tl['KIT_IDS_BODY'] % ", ".join(kitids)
                try:
                    send_email(MESSAGE, tl['KIT_IDS_SUBJECT'], email)
                    self.render('retrieve_kitid.html',
                                message='',
                                output='success',
                                loginerror='')
                except:
                    self.render('retrieve_kitid.html',
                                message=MESSAGE,
                                output='noemail',
                                loginerror='')
            else:
                self.render('retrieve_kitid.html',
                            message='nokit',
                            output='form',
                            loginerror='')

        except:
            self.render('retrieve_kitid.html',
                        message='',
                        output='exception',
                        loginerror='')
Beispiel #10
0
    def post(self):
        # Required vars
        barcode = self.get_argument('barcode')
        sample_date = self.get_argument('sample_date')
        sample_time = self.get_argument('sample_time')
        notes = self.get_argument('notes')
        participant_name = self.get_argument('participant_name', '')
        sample_site = self.get_argument('sample_site', '')
        env_sampled = self.get_argument('environment_sampled', '')

        AG_DATA_ACCESS.logParticipantSample(barcode, sample_site,
                                            env_sampled, sample_date,
                                            sample_time, participant_name,
                                            notes)

        self.redirect(media_locale['SITEBASE'] + '/authed/portal/')
 def get(self):
     email = self.get_argument('email', None)
     kitid = self.get_argument('kitid', None)
     latlongs = AG_DATA_ACCESS.getMapMarkers()
     self.render('forgot_password.html', email=email, kitid=kitid,
                 result=None, messaage='',
                 latlongs_db=latlongs, loginerror='')
Beispiel #12
0
    def on_message(self, msg):
        tl = text_locale['handlers']
        skid = self.current_user
        participant_name = msg

        ag_login_id = AG_DATA_ACCESS.get_user_for_kit(skid)
        human_participants = AG_DATA_ACCESS.getHumanParticipants(ag_login_id)
        animal_participants = AG_DATA_ACCESS.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)
 def reset_pass_and_email(self, new_password, confirm_password, email,
                          supplied_kit_id):
     AG_DATA_ACCESS.ag_update_kit_password(supplied_kit_id, new_password)
     latlongs = AG_DATA_ACCESS.getMapMarkers()
     tl = text_locale['handlers']
     MESSAGE = tl['CHANGE_PASS_BODY'] % supplied_kit_id
     try:
         send_email(MESSAGE, tl['CHANGE_PASS_SUBJECT'], email)
         self.render('change_pass_verify.html', email='', kitid='',
                     passocde='', new_password='',
                     confirm_password='', result=4, message='',
                     latlongs_db=latlongs, loginerror='')
     except:
         self.render('change_pass_verify.html', email='', kitid='',
                     passocde='', new_password='',
                     confirm_password='', result=5, message='',
                     latlongs_db=latlongs, loginerror='')
    def post(self, participant_name):
        skid = self.current_user
        ag_login_id = AG_DATA_ACCESS.get_user_for_kit(skid)

        # Check if we have to remove the participant
        participant_to_remove = self.get_argument("remove", None)
        if participant_to_remove:
            barcodes = AG_DATA_ACCESS.getParticipantSamples(
                ag_login_id, participant_to_remove)
            # Remove all the samples attached to the participant
            for bc in barcodes:
                AG_DATA_ACCESS.deleteSample(bc['barcode'], ag_login_id)
            # Remove the participant
            AG_DATA_ACCESS.deleteAGParticipant(
                ag_login_id, participant_to_remove)
            # Redirect to portal
            self.redirect(media_locale['SITEBASE'] + "/authed/portal/")

        participant_type = self.get_argument('participant_type')

        try:
            survey_details = AG_DATA_ACCESS.getAGSurveyDetails(
                ag_login_id, participant_name)
        except:
            raise HTTPError(404, "Could not retrieve survey details for "
                            "participant '%s'" % participant_name)

        # The defaults must be added to the page as hidden form inputs, in
        # case the user clicks edit survey
        defaults = {}
        for k, v in sorted(survey_details.items()):
            suffix = '_default'
            # do NOT suffix these fields
            if k in ('consent', 'parent_1_name', 'parent_2_name',
                     'deceased_parent', 'participant_email',
                     'participant_name', 'ag_login_id'):
                defaults[k] = v

            # if the name of the field ends in a number, it's a multiple, and
            # should be written out differently UNLESS it's migraine_factor_#
            # or mainfactor_other_# don't like to special-case like this, but
            # there's no other way to tell what's a multiple and what's not
            if k[-1] in map(str, range(10)) \
                    and not k.startswith('migraine_factor_') \
                    and not k.startswith('mainfactor_other_'):
                k = k.rsplit('_', 1)[0]
                defaults[k+'_default[]'] = v

        # Get the list of samples for this participant
        samples = AG_DATA_ACCESS.getParticipantSamples(ag_login_id,
                                                       participant_name)

        self.render('participant_overview.html', defaults=defaults, skid=skid,
                    participant_name=participant_name,
                    participant_type=participant_type, samples=samples)
Beispiel #15
0
 def get(self):
     email = self.get_argument('email', None)
     kitid = self.get_argument('kitid', None)
     latlongs = AG_DATA_ACCESS.getMapMarkers()
     self.render('forgot_password.html',
                 email=email,
                 kitid=kitid,
                 result=None,
                 messaage='',
                 latlongs_db=latlongs,
                 loginerror='')
    def post(self):
        skid = self.current_user
        tl=text_locale['handlers']
        info = {}
        for info_column in ("email", "participantname", "address", "city",
                            "state", "zip", "country"):
            # Make sure that all fields were entered
            info[info_column] = self.get_argument(info_column, None)

        # create the user if needed
        ag_login_id = AG_DATA_ACCESS.addAGLogin(
            info['email'], info['participantname'], info['address'],
            info['city'], info['state'], info['zip'], info['country'])
        # Create the kit and add the kit to the user
        kitinfo = AG_DATA_ACCESS.getAGHandoutKitDetails(skid)
        printresults = AG_DATA_ACCESS.checkPrintResults(skid)
        if printresults is None:
            printresults = 'n'
        success = AG_DATA_ACCESS.addAGKit(
            ag_login_id, skid, kitinfo['password'],
            kitinfo['swabs_per_kit'], kitinfo['verification_code'],
            printresults)
        if success == -1:
            self.redirect(media_locale['SITEBASE'] + '/db_error/?err=regkit')
            return

        # Add the barcodes
        kitinfo = AG_DATA_ACCESS.getAGKitDetails(skid)
        ag_kit_id = kitinfo['ag_kit_id']
        results = AG_DATA_ACCESS.get_barcodes_from_handout_kit(skid)
        for row in results:
            barcode = row[0]
            success = AG_DATA_ACCESS.addAGBarcode(ag_kit_id, barcode)
            if success == -1:
                self.redirect(media_locale['SITEBASE'] + '/db_error/?err=regbarcode')
                return

        # Email the verification code
        subject = tl['AUTH_SUBJECT']
        addendum = ''
        if skid.startswith('PGP_'):
            addendum = tl['AUTH_REGISTER_PGP']

        body = tl['AUTH_REGISTER_BODY'].format(
            kitinfo['kit_verification_code'], addendum)

        result = tl['KIT_REG_SUCCESS']
        try:
            send_email(body, subject, recipient=info['email'],
                       sender=media_locale['HELP_EMAIL'])
        except:
            result = media_locale['EMAIL_ERROR']

            self.render('help_request.html', skid=skid, result=result)

        self.redirect(media_locale['SITEBASE'] + '/authed/portal/')
Beispiel #17
0
    def post(self):
        kit_id = self.current_user
        errmsg = self.get_argument('errmsg', "")
        user_code = self.get_argument('user_verification_code')
        kit_details = AG_DATA_ACCESS.getAGKitDetails(kit_id)
        barcodes = AG_DATA_ACCESS.getBarcodesByKit(kit_id)
        user_info = AG_DATA_ACCESS.get_user_info(kit_id)
        user_name = user_info['name']
        results = AG_DATA_ACCESS.get_barcode_results(kit_id)
        has_results = len(results) != 0

        kit_verified = True if kit_details['kit_verified'] == 'y' else False

        if kit_details['kit_verification_code'] == user_code:
            AG_DATA_ACCESS.verifyKit(kit_id)
            kit_ver_error = False
            verification_textbox = ''
        else:
            kit_ver_error = True
            verification_textbox = ' highlight'

        self.render("portal.html", skid=kit_id, user_name=user_name,
                    errmsg=errmsg, kit_verified=kit_verified,
                    has_results=has_results, results=results,
                    barcodes=barcodes,
                    verification_textbox=verification_textbox,
                    kit_ver_error=kit_ver_error)
Beispiel #18
0
    def post(self):
        kit_id = self.current_user
        errmsg = self.get_argument('errmsg', "")
        user_code = self.get_argument('user_verification_code')
        kit_details = AG_DATA_ACCESS.getAGKitDetails(kit_id)
        barcodes = AG_DATA_ACCESS.getBarcodesByKit(kit_id)
        user_info = AG_DATA_ACCESS.get_user_info(kit_id)
        user_name = user_info['name']
        results = AG_DATA_ACCESS.get_barcode_results(kit_id)
        has_results = len(results) != 0

        kit_verified = True if kit_details['kit_verified'] == 'y' else False

        if kit_details['kit_verification_code'] == user_code:
            AG_DATA_ACCESS.verifyKit(kit_id)
            kit_ver_error = False
            verification_textbox = ''
        else:
            kit_ver_error = True
            verification_textbox = ' highlight'

        self.render("portal.html",
                    skid=kit_id,
                    user_name=user_name,
                    errmsg=errmsg,
                    kit_verified=kit_verified,
                    has_results=has_results,
                    results=results,
                    barcodes=barcodes,
                    verification_textbox=verification_textbox,
                    kit_ver_error=kit_ver_error)
Beispiel #19
0
    def create_passcode_and_send_email(self, email, kit_id):
        kitids = AG_DATA_ACCESS.getAGKitIDsByEmail(email)
        latlongs = AG_DATA_ACCESS.getMapMarkers()
        tl = text_locale['handlers']
        #if the kit id matches the email generate and send an email
        if kit_id in kitids:
            alphabet = letters + digits
            new_act_code = ''.join([choice(alphabet) for i in range(20)])
            # add new pass to the database
            AG_DATA_ACCESS.ag_set_pass_change_code(email, kit_id, new_act_code)
            MESSAGE = (tl['RESET_PASS_BODY'] %
                       (kit_id, quote(email), kit_id, quote(new_act_code)))

            #send the user an email and tell them to change their password
            try:
                send_email(MESSAGE, tl['CHANGE_PASS_SUBJECT'], email)
                self.render('forgot_password.html',
                            email='',
                            kitid='',
                            result=1,
                            message='',
                            latlongs_db=latlongs,
                            loginerror='')
            except:
                self.render('forgot_password.html',
                            email='',
                            kitid='',
                            result=2,
                            message=MESSAGE,
                            latlongs_db=latlongs,
                            loginerror='')

        else:
            self.render('forgot_password.html',
                        email='',
                        kitid='',
                        result=3,
                        message='',
                        latlongs_db=latlongs,
                        loginerror='')
Beispiel #20
0
    def get(self):
        errmsg = self.get_argument('errmsg', "")
        kit_id = self.current_user

        user_info = AG_DATA_ACCESS.get_user_info(kit_id)
        user_name = user_info['name']

        kit_details = AG_DATA_ACCESS.getAGKitDetails(kit_id)
        kit_verified = True if kit_details['kit_verified'] == 'y' else False

        results = AG_DATA_ACCESS.get_barcode_results(kit_id)
        has_results = len(results) != 0

        barcodes = AG_DATA_ACCESS.getBarcodesByKit(kit_id)

        kit_ver_error = False
        verification_textbox = ''

        self.render("portal.html", skid=kit_id, user_name=user_name,
                    errmsg=errmsg, kit_verified=kit_verified,
                    has_results=has_results, results=results,
                    barcodes=barcodes, kit_ver_error=kit_ver_error,
                    verification_textbox=verification_textbox)
 def post(self):
     skid = self.get_argument("skid", "").strip()
     password = self.get_argument("password", "")
     tl = text_locale['handlers']
     login = AG_DATA_ACCESS.authenticateWebAppUser(skid, password)
     if login:
         # everything good so log in
         self.set_current_user(skid)
         self.redirect(media_locale['SITEBASE'] + "/authed/portal/")
         return
     else:
         is_handout = AG_DATA_ACCESS.handoutCheck(skid, password)
         if is_handout == 'y':
             # login user but have them register themselves
             self.set_current_user(skid)
             self.redirect(media_locale['SITEBASE'] + '/auth/register/')
             return
         else:
             msg = tl['INVALID_KITID']
             latlongs_db = AG_DATA_ACCESS.getMapMarkers()
             self.render("index.html", user=None, loginerror=msg,
                         latlongs_db=latlongs_db)
             return
    def _sample_overview_renderer(self):
        barcode = self.get_argument('barcode')

        sample_data = AG_DATA_ACCESS.getAGBarcodeDetails(barcode)

        barcode_pdf = _format_data_path('pdfs', barcode, 'pdf')
        barcode_txt = _format_data_path('taxa-summaries', barcode, 'txt')

        if not os.path.exists(barcode_pdf):
            barcode_pdf = None
        if not os.path.exists(barcode_txt):
            barcode_txt = None

        sample_time = sample_data['sample_time']
        sample_date = sample_data['sample_date']

        status = sample_data['status']
        if status is None:
            bgcolor = '#FFF'
            status = 'Submitted'
        elif status == 'Received':
            bgcolor = '#AFA'
        else:
            bgcolor = '#FFF'

        sample_origin = sample_data['site_sampled']
        if sample_origin is None:
            sample_origin = sample_data['environment_sampled']

        notes = sample_data['notes']
        if notes is None:
            notes = ''

        self.render('sample_overview.html',
                    skid=self.current_user,
                    barcode_pdf=barcode_pdf,
                    barcode_txt=barcode_txt,
                    bgcolor=bgcolor,
                    status=status,
                    barcode=barcode,
                    sample_origin=sample_origin,
                    sample_date=sample_date,
                    sample_time=sample_time,
                    notes=notes)
    def get(self):
        email = self.get_argument('email', None)
        if email is not None:
            email = unquote(email)
        kitid = self.get_argument('kitid', None)
        passcode = self.get_argument('passcode', None)
        new_password = self.get_argument('new_password', None)
        confirm_password = self.get_argument('confirm_password', None)

        if self.is_valid(email, kitid, passcode):
            result = 'valid'
        else:
            result = 'notvalid'
        latlongs = AG_DATA_ACCESS.getMapMarkers()
        self.render('change_pass_verify.html', email=email, kitid=kitid,
                    passcode=passcode, new_password=new_password,
                    confirm_password=confirm_password,
                    result=result, message=None, latlongs_db=latlongs,
                    loginerror='')
    def post(self):
        email = self.get_argument('email')
        tl = text_locale['handlers']
        if email:
            kitids = AG_DATA_ACCESS.getAGKitIDsByEmail(email)
        try:
            if len(kitids) > 0:
                MESSAGE = tl['KIT_IDS_BODY'] % ", ".join(kitids)
                try:
                    send_email(MESSAGE, tl['KIT_IDS_SUBJECT'], email)
                    self.render('retrieve_kitid.html', message='',
                                output='success', loginerror='')
                except:
                    self.render('retrieve_kitid.html', message=MESSAGE,
                                output='noemail', loginerror='')
            else:
                self.render('retrieve_kitid.html', message='nokit',
                            output='form', loginerror='')

        except:
            self.render('retrieve_kitid.html', message='', output='exception',
                        loginerror='')
    def _sample_overview_renderer(self):
        barcode = self.get_argument('barcode')

        sample_data = AG_DATA_ACCESS.getAGBarcodeDetails(barcode)

        barcode_pdf = _format_data_path('pdfs', barcode, 'pdf')
        barcode_txt = _format_data_path('taxa-summaries', barcode, 'txt')

        if not os.path.exists(barcode_pdf):
            barcode_pdf = None
        if not os.path.exists(barcode_txt):
            barcode_txt = None

        sample_time = sample_data['sample_time']
        sample_date = sample_data['sample_date']

        status = sample_data['status']
        if status is None:
            bgcolor = '#FFF'
            status = 'Submitted'
        elif status == 'Received':
            bgcolor = '#AFA'
        else:
            bgcolor = '#FFF'

        sample_origin = sample_data['site_sampled']
        if sample_origin is None:
            sample_origin = sample_data['environment_sampled']

        notes = sample_data['notes']
        if notes is None:
            notes = ''

        self.render('sample_overview.html', skid=self.current_user,
                    barcode_pdf=barcode_pdf, barcode_txt=barcode_txt,
                    bgcolor=bgcolor, status=status, barcode=barcode,
                    sample_origin=sample_origin, sample_date=sample_date,
                    sample_time=sample_time, notes=notes)
    def get(self):
        email = self.get_argument('email', None)
        if email is not None:
            email = unquote(email)
        kitid = self.get_argument('kitid', None)
        passcode = self.get_argument('passcode', None)
        new_password = self.get_argument('new_password', None)
        confirm_password = self.get_argument('confirm_password', None)

        if self.is_valid(email, kitid, passcode):
            result = 'valid'
        else:
            result = 'notvalid'
        latlongs = AG_DATA_ACCESS.getMapMarkers()
        self.render('change_pass_verify.html',
                    email=email,
                    kitid=kitid,
                    passcode=passcode,
                    new_password=new_password,
                    confirm_password=confirm_password,
                    result=result,
                    message=None,
                    latlongs_db=latlongs,
                    loginerror='')
 def get(self):
     latlong_db = AG_DATA_ACCESS.getMapMarkers()
     self.render("register_user.html", skid=self.current_user,
                 latlongs_db=latlong_db, loginerror='')
    def post(self):
        tl = text_locale['handlers']
        deceased_parent = self.get_argument("deceased_parent", None)
        participant_name = self.get_argument("participant_name")
        participant_email = self.get_argument("participant_email")
        is_juvenile = self.get_argument("is_juvenile", 'off')
        parent_1_name = self.get_argument("parent_1_name", None)
        parent_2_name = self.get_argument("parent_2_name", None)

        ag_login_id = AG_DATA_ACCESS.get_user_for_kit(self.current_user)
        kit_email = AG_DATA_ACCESS.get_user_info(self.current_user)['email']

        # Check if the participant is on the exceptions list
        is_exception = (
            participant_name
            in AG_DATA_ACCESS.getParticipantExceptions(ag_login_id))

        # If the participant already exists, stop them outright
        if AG_DATA_ACCESS.check_if_consent_exists(ag_login_id, participant_name):
            errmsg = url_escape(tl['PARTICIPANT_EXISTS'] % participant_name)
            self.redirect(media_locale['SITEBASE'] + "/authed/portal/?errmsg=%s" % errmsg)

        if is_juvenile == 'off' and is_exception:
            errmsg = url_escape(tl["JUVENILE_CONSENT_EXPECTED"] %
                                participant_name)
            self.redirect(media_locale['SITEBASE'] + "/authed/portal/?errmsg=%s" % errmsg)

        if is_juvenile == 'on':
            # If they aren't already an exception, we need to verify them
            if not is_exception:
                alert_message = tl['MINOR_PARENTAL_BODY']

                subject = ("AGJUVENILE: %s (ag_login_id: %s) is a child"
                           % (participant_name, ag_login_id))

                message = MESSAGE_TEMPLATE % (participant_name,
                                              parent_1_name, parent_2_name,
                                              deceased_parent,
                                              self.current_user, kit_email)

                try:
                    send_email(message, subject, sender=kit_email)
                    alert_message = tl['MESSAGE_SENT']
                except:
                    alert_message = media_locale['EMAIL_ERROR']

                self.redirect(media_locale['SITEBASE'] + "/authed/portal/?errmsg=%s" % alert_message)

        human_survey_id = binascii.hexlify(os.urandom(8))
        consent= {'participant_name': participant_name,
                  'participant_email': participant_email,
                  'parent_1_name': parent_1_name,
                  'parent_2_name': parent_2_name,
                  'is_juvenile': True if is_juvenile == 'on' else False,
                  'deceased_parent': deceased_parent,
                  'login_id': ag_login_id,
                  'survey_id': human_survey_id}

        r_server.hset(human_survey_id, 'consent', dumps(consent))
        r_server.expire(human_survey_id, 86400)

        self.set_secure_cookie('human_survey_id', human_survey_id)
        self.redirect(media_locale['SITEBASE'] + "/authed/survey_main/")
 def is_valid(self, email, kitid, passcode):
     return AG_DATA_ACCESS.ag_verify_kit_password_change_code(email, kitid,
                                                              passcode)
Beispiel #30
0
    def post(self):
        tl = text_locale['handlers']
        deceased_parent = self.get_argument("deceased_parent", None)
        participant_name = self.get_argument("participant_name")
        participant_email = self.get_argument("participant_email")
        is_juvenile = self.get_argument("is_juvenile", 'off')
        parent_1_name = self.get_argument("parent_1_name", None)
        parent_2_name = self.get_argument("parent_2_name", None)

        ag_login_id = AG_DATA_ACCESS.get_user_for_kit(self.current_user)
        kit_email = AG_DATA_ACCESS.get_user_info(self.current_user)['email']

        # Check if the participant is on the exceptions list
        is_exception = (
            participant_name
            in AG_DATA_ACCESS.getParticipantExceptions(ag_login_id))

        # If the participant already exists, stop them outright
        if AG_DATA_ACCESS.check_if_consent_exists(ag_login_id,
                                                  participant_name):
            errmsg = url_escape(tl['PARTICIPANT_EXISTS'] % participant_name)
            self.redirect(media_locale['SITEBASE'] +
                          "/authed/portal/?errmsg=%s" % errmsg)

        if is_juvenile == 'off' and is_exception:
            errmsg = url_escape(tl["JUVENILE_CONSENT_EXPECTED"] %
                                participant_name)
            self.redirect(media_locale['SITEBASE'] +
                          "/authed/portal/?errmsg=%s" % errmsg)

        if is_juvenile == 'on':
            # If they aren't already an exception, we need to verify them
            if not is_exception:
                alert_message = tl['MINOR_PARENTAL_BODY']

                subject = ("AGJUVENILE: %s (ag_login_id: %s) is a child" %
                           (participant_name, ag_login_id))

                message = MESSAGE_TEMPLATE % (participant_name, parent_1_name,
                                              parent_2_name, deceased_parent,
                                              self.current_user, kit_email)

                try:
                    send_email(message, subject, sender=kit_email)
                    alert_message = tl['MESSAGE_SENT']
                except:
                    alert_message = media_locale['EMAIL_ERROR']

                self.redirect(media_locale['SITEBASE'] +
                              "/authed/portal/?errmsg=%s" % alert_message)

        human_survey_id = binascii.hexlify(os.urandom(8))
        consent = {
            'participant_name': participant_name,
            'participant_email': participant_email,
            'parent_1_name': parent_1_name,
            'parent_2_name': parent_2_name,
            'is_juvenile': True if is_juvenile == 'on' else False,
            'deceased_parent': deceased_parent,
            'login_id': ag_login_id,
            'survey_id': human_survey_id
        }

        r_server.hset(human_survey_id, 'consent', dumps(consent))
        r_server.expire(human_survey_id, 86400)

        self.set_secure_cookie('human_survey_id', human_survey_id)
        self.redirect(media_locale['SITEBASE'] + "/authed/survey_main/")
 def get(self):
     latlong_db = AG_DATA_ACCESS.getMapMarkers()
     self.render("index.html", latlongs_db=latlong_db, loginerror="")
 def is_valid(self, email, kitid, passcode):
     return AG_DATA_ACCESS.ag_verify_kit_password_change_code(
         email, kitid, passcode)
 def get(self):
     latlong_db = AG_DATA_ACCESS.getMapMarkers()
     self.render("index.html", latlongs_db=latlong_db, loginerror="")
    def post(self):
        skid = self.current_user
        tl = text_locale['handlers']
        participant_name = self.get_argument('animal_name')

        # Add values to tables
        singles = {}
        singles['type'] = self.get_argument('type', default=None)
        singles['origin'] = self.get_argument('origin', default=None)
        singles['age'] = self.get_argument('age', default=None)
        singles['gender'] = self.get_argument('gender', default=None)
        singles['setting'] = self.get_argument('setting', default=None)
        singles['weight'] = self.get_argument('weight', default=None)
        singles['diet'] = self.get_argument('diet', default=None)
        singles['food_source_store'] = self.get_argument('food_source_store',
                                              default=None)
        singles['food_source_human'] = self.get_argument('food_source_human',
                                              default=None)
        singles['food_source_wild'] = self.get_argument('food_source_wild', default=None)
        singles['food_type'] = self.get_argument('food_type', default=None)
        singles['organic_food'] = self.get_argument('organic_food',
                                                    default=None)
        singles['grain_free_food'] = self.get_argument('grain_free_food',
                                                       default=None)
        singles['living_status'] = self.get_argument('living_status',
                                                     default=None)
        singles['outside_time'] = self.get_argument('outside_time',
                                                    default=None)
        singles['toilet'] = self.get_argument('toilet', default=None)
        singles['coprophage'] = self.get_argument('coprophage', default=None)
        singles['comments'] = self.get_argument('comments', default=None)

        multiples = {k: v[0] for k, v in self.request.body_arguments.items()
                     if k.startswith('human_') or k.startswith('pet_')}

        ag_login_id = AG_DATA_ACCESS.get_user_for_kit(skid)
        AG_DATA_ACCESS.deleteAGParticipant(ag_login_id, participant_name)

        for sample in AG_DATA_ACCESS.getParticipantSamples(ag_login_id,
                participant_name):
            AG_DATA_ACCESS.deleteSample(sample['barcode'], ag_login_id)

        # Create the new participant if it doesn't exist (merges)
        AG_DATA_ACCESS.addAGAnimalParticipant(ag_login_id, participant_name)

        for field, value in singles.items():
            if value is None:
                continue

            AG_DATA_ACCESS.addAGGeneralValue(ag_login_id, participant_name,
                                             field, value)
            AG_DATA_ACCESS.addAGSingle(ag_login_id, participant_name,
                                       field, value, 'ag_animal_survey')

        for field, value in multiples.items():
            if value is None:
                continue

            AG_DATA_ACCESS.addAGGeneralValue(ag_login_id, participant_name,
                                             field, value)
            AG_DATA_ACCESS.insertAGMultiple(ag_login_id, participant_name,
                                            field, value)

        message = urlencode([('errmsg', tl['SUCCESSFULLY_ADDED'] %
                              participant_name)])
        self.redirect(media_locale['SITEBASE'] + '/authed/portal/?%s' % message)
Beispiel #35
0
 def get(self):
     user_info = AG_DATA_ACCESS.get_user_info(self.current_user)
     self.render('change_password.html', email=user_info['email'],
                 skid=self.current_user, new_password=None,
                 confirm_password=None, result='valid', message=None)