Beispiel #1
0
    def user_form_submitted_successfully(self, user):
        username = self.uform.data['username']
        mailer = get_mailer(self.req)
        user.generated_code = make_random_code(12)
        user.generated_code_time_stamp = datetime.utcnow()
        settings = self.settings

        # only generate the url if it's being used
        url = ''
        if "{url}" in settings['body']:
            salt = settings.get('salt', 's4lt!necracker')
            urlparts = list(urlparse(self.req.url))
            querystr = dict(parse_qsl(urlparts[4]))
            querystr['code'] = hashlib.sha256(
                "%s%s%s"%(user.id, user.generated_code, salt)) \
                .hexdigest()
            querystr['u'] = username
            querystr['rem'] = settings.get('url_remember', '0')
            querystr['rem'] = '1' if querystr['rem'] == 'True' else '0'
            urlparts[4] = urlencode(querystr)
            url = urlunparse(urlparts)

        message = {
            'recipients': [username],
            'body': settings['body'].replace('{code}', user.generated_code) \
                                    .replace('{url}', url),
            'subject': settings['subject'],
            'sender': settings['sender']
        }
        mailer.send_immediately(Message(**message))
Beispiel #2
0
 def send_code_reminder(self, user):
     mailer = get_mailer(self.req)
     code_reminder_settings = \
         self.req.registry['settings']['allowcodereminder_settings'].copy()
     username = user.username
     message = code_reminder_settings.copy()
     message['recipients'] = [username]
     appname = self.req.registry['settings']['appname']
     message['body'] = message['body'].replace(
         '{code}', get_barcode_image(username, user.secret, appname))
     mailer.send_immediately(Message(**message))
Beispiel #3
0
 def send_code_reminder(self, user):
     mailer = get_mailer(self.req)
     code_reminder_settings = \
         self.req.registry['settings']['allowcodereminder_settings'].copy()
     username = user.username
     message = code_reminder_settings.copy()
     message['recipients'] = [username]
     appname = self.req.registry['settings']['appname']
     message['body'] = message['body'].replace(
         '{code}', get_barcode_image(username, user.secret, appname))
     message['extra_headers'] = {'Message-ID': create_message_id()}
     mailer.send_immediately(Message(**message))
Beispiel #4
0
    def user_form_submitted_successfully(self, user):
        username = self.uform.data['username']
        mailer = get_mailer(self.req)
        user.generated_code = make_random_code(12)
        user.generated_code_time_stamp = datetime.utcnow()
        # save it
        self.db.save(self.req, user)
        settings = self.settings

        # only generate the url if it's being used
        url = ''
        if "{url}" in settings['body']:
            salt = settings.get('salt', 's4lt!necracker')
            urlparts = list(urlparse(self.req.url))
            querystr = dict(parse_qsl(urlparts[4]))
            querystr['code'] = hashlib.sha256(
                "%s%s%s" % (user.id, user.generated_code, salt)) \
                .hexdigest()
            querystr['u'] = username
            querystr['rem'] = settings.get('url_remember', '0')
            querystr['rem'] = '1' if querystr['rem'] == 'True' else '0'
            url = generate_url(self.req, self.req.path, querystr)

        message = {
            'recipients': [username],
            'body':
            settings['body'].replace('{code}', user.generated_code).replace(
                '{url}', url),
            'subject':
            settings['subject'],
            'sender':
            settings['sender'],
            'extra_headers': {
                'Message-ID': create_message_id()
            }
        }
        mailer.send_immediately(Message(**message))