Example #1
0
    def write_error(self, status_code, **kwargs):
        """Overrides the error page created by Tornado"""
        from traceback import format_exception
        user = self.current_user
        # render error page BEFORE handling the error
        if user:
            self.render('error.html', skid=user)
        else:
            self.render('no_auth_error.html', loginerror="")

        logging.exception(kwargs["exc_info"])
        exc_info = kwargs["exc_info"]
        trace_info = ''.join(format_exception(*exc_info))
        request_info = ''.join([
            "%s:   %s\n" % (k, self.request.__dict__[k])
            for k in self.request.__dict__
        ])
        error = exc_info[1]
        formatted_email = (">SKID\n%s\n\n>Error\n%s\n\n>Traceback\n%s\n\n"
                           ">Request Info\n%s\n\n" %
                           (user, error.message, trace_info, request_info))
        if not AMGUT_CONFIG.test_environment:
            send_email(formatted_email,
                       "SERVER ERROR!",
                       recipient=AMGUT_CONFIG.error_email)
        else:
            print(formatted_email)
    def create_passcode_and_send_email(self, email, kit_id):
        kitids = ag_data.getAGKitIDsByEmail(email)
        latlongs = ag_data.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.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='')
Example #3
0
    def post(self):
        email_address = self.get_argument('email_address')
        skid = self.current_user[-2:]  # last two letters of kit id
        first_name = self.get_argument('first_name')
        last_name = self.get_argument('last_name')
        message = self.get_argument('message_body')

        if email_address:
            SUBJECT = """AGHELP: %s %s %s""" % (first_name, last_name, skid)

            MESSAGE = """Contact: %s %s
            Reply to: %s
            --------------------------------------------------------------------------------
            Message:
            %s
            --------------------------------------------------------------------------------
            """ % (first_name, last_name, email_address, message)

            try:
                send_email(MESSAGE, SUBJECT, sender=email_address)
                result = media_locale["EMAIL_SENT"]
            except BaseException:
                result = media_locale['EMAIL_ERROR']

            self.render('help_request.html', skid=self.current_user,
                        result=result)
 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='')
Example #5
0
    def post(self):
        email_address = self.get_argument('email_address')
        skid = self.current_user[-2:]  # last two letters of kit id
        first_name = self.get_argument('first_name')
        last_name = self.get_argument('last_name')
        message = self.get_argument('message_body')

        if email_address:
            SUBJECT = """AGHELP: %s %s %s""" % (first_name, last_name, skid)

            MESSAGE = """Contact: %s %s
            Reply to: %s
            --------------------------------------------------------------------------------
            Message:
            %s
            --------------------------------------------------------------------------------
            """ % (first_name, last_name, email_address, message)

            try:
                send_email(MESSAGE, SUBJECT, sender=email_address)
                result = media_locale["EMAIL_SENT"]
            except BaseException:
                result = media_locale['EMAIL_ERROR']

            self.render('help_request.html',
                        skid=self.current_user,
                        result=result)
    def write_error(self, status_code, **kwargs):
        """Overrides the error page created by Tornado"""
        from traceback import format_exception
        user = self.current_user
        # render error page BEFORE handling the error
        if user:
            self.render('error.html', skid=user)
        else:
            self.render('no_auth_error.html', loginerror="")

        logging.exception(kwargs["exc_info"])
        exc_info = kwargs["exc_info"]
        trace_info = ''.join(format_exception(*exc_info))
        request_info = ''.join(["%s:   %s\n" %
                               (k, self.request.__dict__[k]) for k in
                                self.request.__dict__])
        error = exc_info[1]
        formatted_email = (">SKID\n%s\n\n>Error\n%s\n\n>Traceback\n%s\n\n"
                           ">Request Info\n%s\n\n" %
                           (user, error, trace_info, request_info))
        if not AMGUT_CONFIG.test_environment:
            send_email(formatted_email, "SERVER ERROR!",
                       recipient=AMGUT_CONFIG.error_email)
        else:
            print(formatted_email)
    def post(self):
        kit_counts = ag_data.getMapMarkers()
        email = self.get_argument('email')
        tl = text_locale['handlers']
        if email:
            kitids = ag_data.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='',
                                kit_counts=kit_counts)
                except BaseException:
                    self.render('retrieve_kitid.html', message=MESSAGE,
                                output='noemail', loginerror='',
                                kit_counts=kit_counts)
            else:
                self.render('retrieve_kitid.html', message='nokit',
                            output='form', loginerror='',
                            kit_counts=kit_counts)

        except BaseException:
            self.render('retrieve_kitid.html', message='', output='exception',
                        loginerror='', kit_counts=kit_counts)
Example #8
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='')
    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/')
    def post(self):
        # Check handout
        skid = self.get_argument("kit_id").strip()
        password = self.get_argument("password")
        is_handout = ag_data.handoutCheck(skid, password)
        if not is_handout:
            tl = text_locale['handlers']
            self.redirect(media_locale['SITEBASE'] + "/?loginerror=" +
                          url_escape(tl['INVALID_KITID']))
            return

        # Register handout
        tl = text_locale['handlers']
        info = {
            "email": self.get_argument("email"),
            "participantname": self.get_argument("participantname")
        }
        for info_column in ("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.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
        success = ag_data.registerHandoutKit(ag_login_id, skid)
        if not success:
            self.redirect(media_locale['SITEBASE'] + '/db_error/?err=regkit')
            return

        # log user in since registered successfully
        self.set_current_user(skid)
        self.redirect(media_locale['SITEBASE'] + "/authed/portal/")

        kitinfo = ag_data.getAGKitDetails(skid)

        # Email the verification code
        # send email after redirect since it takes so long
        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)
        try:
            send_email(body,
                       subject,
                       recipient=info['email'],
                       sender=media_locale['HELP_EMAIL'])
        except:
            logging.exception('Error on skid %s:' % skid)
Example #11
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.getAGKitDetails(kit_id)
        barcodes = ag_data.getBarcodesByKit(kit_id)
        user_info = ag_data.get_user_info(kit_id)
        user_name = user_info['name']
        results = ag_data.get_barcode_results(kit_id)
        has_results = len(results) != 0
        unconsented = ag_data.get_nonconsented_scanned_barcodes(kit_id)

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

        if not kit_verified and user_code == "":
            # Resend kit verification code
            tl = text_locale['handlers']
            subject = tl['AUTH_SUBJECT']
            addendum = ''
            if self.current_user.startswith('PGP_'):
                addendum = tl['AUTH_REGISTER_PGP']

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

            kit_ver_error = False
            verification_textbox = ''
            try:
                send_email(body,
                           subject,
                           recipient=user_info['email'],
                           sender=media_locale['HELP_EMAIL'])
            except BaseException:
                errmsg = media_locale['EMAIL_ERROR']
        else:
            # Verify the given kit verification code
            if kit_details['kit_verification_code'] == user_code:
                ag_data.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,
                    unconsented=unconsented)
    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/")
    def post(self):
        # Check handout
        skid = self.get_argument("kit_id").strip()
        password = self.get_argument("password")
        is_handout = ag_data.handoutCheck(skid, password)
        if not is_handout:
            tl = text_locale['handlers']
            self.redirect(media_locale['SITEBASE'] +
                          "/?loginerror=" + url_escape(tl['INVALID_KITID']))
            return

        # Register handout
        tl = text_locale['handlers']
        info = {
            "email": self.get_argument("email"),
            "participantname": self.get_argument("participantname")
        }
        for info_column in ("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.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
        success = ag_data.registerHandoutKit(ag_login_id, skid)
        if not success:
            self.redirect(media_locale['SITEBASE'] + '/db_error/?err=regkit')
            return

        # log user in since registered successfully
        self.set_current_user(skid)
        self.redirect(media_locale['SITEBASE'] + "/authed/portal/")

        kitinfo = ag_data.getAGKitDetails(skid)

        # Email the verification code
        # send email after redirect since it takes so long
        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)
        try:
            send_email(body, subject, recipient=info['email'],
                       sender=media_locale['HELP_EMAIL'])
        except:
            logging.exception('Error on skid %s:' % skid)
Example #14
0
 def write_error(self, status_code, **kwargs):
     '''Overrides the error page created by Tornado'''
     from traceback import format_exception
     logging.exception(kwargs["exc_info"])
     exc_info = kwargs["exc_info"]
     trace_info = ''.join(format_exception(*exc_info))
     request_info = ''.join(["%s:   %s\n" %
                            (k, self.request.__dict__[k]) for k in
                             self.request.__dict__])
     error = exc_info[1]
     formatted_email = (">SKID\n%s\n\n>Error\n%s\n\n>Traceback\n%s\n\n"
                        ">Request Info\n%s\n\n" %
                        (self.current_user, error, trace_info, request_info))
     send_email(formatted_email, "SERVER ERROR!")
     self.render('error.html', skid=self.current_user)
    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.getAGKitDetails(kit_id)
        barcodes = ag_data.getBarcodesByKit(kit_id)
        user_info = ag_data.get_user_info(kit_id)
        user_name = user_info['name']
        results = ag_data.get_barcode_results(kit_id)
        has_results = len(results) != 0
        unconsented = ag_data.get_nonconsented_scanned_barcodes(kit_id)

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

        if not kit_verified and user_code == "":
            # Resend kit verification code
            tl = text_locale['handlers']
            subject = tl['AUTH_SUBJECT']
            addendum = ''
            if self.current_user.startswith('PGP_'):
                addendum = tl['AUTH_REGISTER_PGP']

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

            kit_ver_error = False
            verification_textbox = ''
            try:
                send_email(body, subject, recipient=user_info['email'],
                           sender=media_locale['HELP_EMAIL'])
            except:
                errmsg = media_locale['EMAIL_ERROR']
        else:
            # Verify the given kit verification code
            if kit_details['kit_verification_code'] == user_code:
                ag_data.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, unconsented=unconsented)
 def reset_pass_and_email(self, new_password, confirm_password, email,
                          supplied_kit_id):
     tl = text_locale['handlers']
     ag_data.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 BaseException:
         self.render('change_password.html', email='',
                     skid=self.current_user,
                     new_password='', confirm_password='', result=5,
                     message='')
Example #17
0
 def reset_pass_and_email(self, new_password, confirm_password, email,
                          supplied_kit_id):
     tl = text_locale['handlers']
     ag_data.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='')
 def reset_pass_and_email(self, new_password, confirm_password, email,
                          supplied_kit_id):
     ag_data.ag_update_kit_password(supplied_kit_id, new_password)
     latlongs = ag_data.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='')
Example #19
0
 def write_error(self, status_code, **kwargs):
     '''Overrides the error page created by Tornado'''
     from traceback import format_exception
     logging.exception(kwargs["exc_info"])
     exc_info = kwargs["exc_info"]
     trace_info = ''.join(format_exception(*exc_info))
     request_info = ''.join([
         "%s:   %s\n" % (k, self.request.__dict__[k])
         for k in self.request.__dict__
     ])
     error = exc_info[1]
     formatted_email = (
         ">SKID\n%s\n\n>Error\n%s\n\n>Traceback\n%s\n\n"
         ">Request Info\n%s\n\n" %
         (self.current_user, error, trace_info, request_info))
     send_email(formatted_email, "SERVER ERROR!")
     self.render('error.html', skid=self.current_user)
 def reset_pass_and_email(self, new_password, confirm_password, email,
                          supplied_kit_id):
     ag_data.ag_update_kit_password(supplied_kit_id, new_password)
     kit_counts = ag_data.getMapMarkers()
     tl = text_locale['handlers']
     MESSAGE = tl['CHANGE_PASS_BODY'] % supplied_kit_id
     try:
         send_email(MESSAGE, tl['CHANGE_PASS_SUBJECT'], email)
         # result=4 is for showing message in if statement of
         # change_pass_verify.html
         self.render('change_pass_verify.html', email='', kitid='',
                     passocde='', new_password='',
                     confirm_password='', result=4, message='',
                     kit_counts=kit_counts, loginerror='')
     except:
         # result=5 is for showing message in if statement of
         # change_pass_verify.html
         self.render('change_pass_verify.html', email='', kitid='',
                     passocde='', new_password='',
                     confirm_password='', result=5, message='',
                     kit_counts=kit_counts, loginerror='')
 def reset_pass_and_email(self, new_password, confirm_password, email,
                          supplied_kit_id):
     ag_data.ag_update_kit_password(supplied_kit_id, new_password)
     kit_counts = ag_data.getMapMarkers()
     tl = text_locale['handlers']
     MESSAGE = tl['CHANGE_PASS_BODY'] % supplied_kit_id
     try:
         send_email(MESSAGE, tl['CHANGE_PASS_SUBJECT'], email)
         # result=4 is for showing message in if statement of
         # change_pass_verify.html
         self.render('change_pass_verify.html', email='', kitid='',
                     passocde='', new_password='',
                     confirm_password='', result=4, message='',
                     kit_counts=kit_counts, loginerror='')
     except BaseException:
         # result=5 is for showing message in if statement of
         # change_pass_verify.html
         self.render('change_pass_verify.html', email='', kitid='',
                     passocde='', new_password='',
                     confirm_password='', result=5, message='',
                     kit_counts=kit_counts, loginerror='')
Example #22
0
    def create_passcode_and_send_email(self, email, kit_id):
        kitids = ag_data.getAGKitIDsByEmail(email)
        kit_counts = ag_data.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.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='',
                            kit_counts=kit_counts,
                            loginerror='')
            except BaseException:
                self.render('forgot_password.html',
                            email='',
                            kitid='',
                            result=2,
                            message=MESSAGE,
                            kit_counts=kit_counts,
                            loginerror='')

        else:
            self.render('forgot_password.html',
                        email='',
                        kitid='',
                        result=3,
                        message='',
                        kit_counts=kit_counts,
                        loginerror='')
    def post(self):
        kit_counts = ag_data.getMapMarkers()
        email = self.get_argument("email")
        tl = text_locale["handlers"]
        if email:
            kitids = ag_data.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="", kit_counts=kit_counts
                    )
                except:
                    self.render(
                        "retrieve_kitid.html", message=MESSAGE, output="noemail", loginerror="", kit_counts=kit_counts
                    )
            else:
                self.render("retrieve_kitid.html", message="nokit", output="form", loginerror="", kit_counts=kit_counts)

        except:
            self.render("retrieve_kitid.html", message="", output="exception", loginerror="", kit_counts=kit_counts)
Example #24
0
    def post(self):
        # see if we're coming from an edit
        human_survey_id = self.get_argument('survey_id', None)
        page_number = int(self.get_argument('page_number'))
        sitebase = media_locale['SITEBASE']

        if human_survey_id is None:
            # we came from consent
            human_survey_id = self.get_secure_cookie('human_survey_id')
            if human_survey_id is None:
                err_msg = url_escape("There was an unexpected error.")
                self.redirect(sitebase + "/authed/portal/?errmsg=%s" % err_msg)
                return
        else:
            # we came from participant_overview
            consent = ag_data.getConsent(human_survey_id)
            # make sure is string so can be serialized
            consent['date_signed'] = str(consent['date_signed'])
            self.set_secure_cookie('human_survey_id', human_survey_id)
            data = primary_human_survey.fetch_survey(human_survey_id)
            redis.hset(human_survey_id, 'consent', dumps(consent))
            redis.hset(human_survey_id, 'existing', dumps(data))
            redis.expire(human_survey_id, 86400)

        next_page_number = page_number + 1

        if page_number >= 0:
            form_data = surveys[page_number]()
            form_data.process(data=self.request.arguments)
            data = {'questions': form_data.data}

            redis.hset(human_survey_id, page_number, dumps(data))

        progress = int(100.0 * (page_number + 2) / (len(phs_groups) + 1))

        # if this is not the last page, render the next page
        if next_page_number < len(surveys):
            the_form = surveys[next_page_number]()

            existing_responses = redis.hget(human_survey_id, 'existing')
            if existing_responses:
                existing_responses = loads(existing_responses)
                the_form = surveys[next_page_number](data=existing_responses)

            title = phs_groups[next_page_number].name

            self.render('human_survey.html',
                        the_form=the_form,
                        skid=self.current_user,
                        TITLE=title,
                        page_number=next_page_number,
                        progress=progress)
        else:
            # only get the cookie if you complete the survey
            self.clear_cookie('human_survey_id')
            self.set_secure_cookie('completed_survey_id', human_survey_id)
            store_survey(primary_human_survey, human_survey_id)
            existing = redis.hget(human_survey_id, 'existing')
            if existing is None:
                # Send consent info email since new participant
                consent_info = ag_data.getConsent(human_survey_id)
                try:
                    message = build_consent_form(consent_info)
                    send_email(message,
                               'American Gut-Signed Consent Form(s)',
                               recipient=consent_info['participant_email'],
                               sender='*****@*****.**',
                               html=True)
                except:
                    logging.exception(
                        'Error sending signed consent form for '
                        'survey ID: %s to email: %s' %
                        (human_survey_id, consent_info['participant_email']))

            self.redirect(sitebase + '/authed/human_survey_completed/')
Example #25
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 post(self):
        # see if we're coming from an edit
        human_survey_id = self.get_argument('survey_id', None)
        page_number = int(self.get_argument('page_number'))
        sitebase = media_locale['SITEBASE']

        if human_survey_id is None:
            # we came from consent
            human_survey_id = self.get_secure_cookie('human_survey_id')
            if human_survey_id is None:
                err_msg = url_escape("There was an unexpected error.")
                self.redirect(sitebase + "/authed/portal/?errmsg=%s" % err_msg)
                return
        else:
            # we came from participant_overview
            consent = ag_data.getConsent(human_survey_id)
            # make sure is string so can be serialized
            consent['date_signed'] = str(consent['date_signed'])
            self.set_secure_cookie('human_survey_id', human_survey_id)
            data = primary_human_survey.fetch_survey(human_survey_id)
            redis.hset(human_survey_id, 'consent', dumps(consent))
            redis.hset(human_survey_id, 'existing', dumps(data))
            redis.expire(human_survey_id, 86400)

        next_page_number = page_number + 1

        if page_number >= 0:
            form_data = surveys[page_number]()
            form_data.process(data=self.request.arguments)
            data = {'questions': form_data.data}

            redis.hset(human_survey_id, page_number, dumps(data))

        progress = int(100.0 * (page_number + 2) / (len(phs_groups) + 1))

        # if this is not the last page, render the next page
        if next_page_number < len(surveys):
            the_form = surveys[next_page_number]()

            existing_responses = redis.hget(human_survey_id, 'existing')
            if existing_responses:
                existing_responses = loads(existing_responses)
                the_form = surveys[next_page_number](data=existing_responses)

            title = phs_groups[next_page_number].name

            self.render('human_survey.html', the_form=the_form,
                        skid=self.current_user, TITLE=title,
                        page_number=next_page_number,
                        progress=progress)
        else:
            # only get the cookie if you complete the survey
            self.clear_cookie('human_survey_id')
            self.set_secure_cookie('completed_survey_id', human_survey_id)
            store_survey(primary_human_survey, human_survey_id)
            existing = redis.hget(human_survey_id, 'existing')
            if existing is None:
                # Send consent info email since new participant
                consent_info = ag_data.getConsent(human_survey_id)
                try:
                    message = build_consent_form(consent_info)
                    send_email(message, 'American Gut-Signed Consent Form(s)',
                               recipient=consent_info['participant_email'],
                               sender='*****@*****.**', html=True)
                except:
                    logging.exception('Error sending signed consent form for '
                                      'survey ID: %s to email: %s' %
                                      (human_survey_id,
                                       consent_info['participant_email']))

            self.redirect(sitebase + '/authed/human_survey_completed/')
    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/")