Exemplo n.º 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()
        # 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))
Exemplo n.º 2
0
def auth_chooser(req):
    auth_types = []
    settings = req.registry['settings']
    base_path = settings['base_auth_url']
    supported_types = settings['supported_auth_schemes']
    if len(supported_types) == 1:
        plugin = getFactoredPlugin(supported_types[0])
        url = generate_url(req, base_path + '/' + plugin.path,
                           {'referrer': req.params.get('referrer', '')})
        raise HTTPFound(location=url)

    for plugin in getFactoredPlugins():
        if plugin.name in supported_types:
            auth_types.append({
                'name': plugin.name,
                'url': os.path.join(base_path, plugin.path)
            })
    return dict(auth_types=auth_types, referrer=req.params.get('referrer', ''))
Exemplo n.º 3
0
def auth_chooser(req):
    auth_types = []
    settings = req.registry['settings']
    base_path = settings['base_auth_url']
    supported_types = settings['supported_auth_schemes']
    if len(supported_types) == 1:
        plugin = getFactoredPlugin(supported_types[0])
        url = generate_url(req, base_path + '/' + plugin.path,
                           {'referrer': req.params.get('referrer', '')})
        raise HTTPFound(location=url)

    for plugin in getFactoredPlugins():
        if plugin.name in supported_types:
            auth_types.append({
                'name': plugin.name,
                'url': os.path.join(base_path, plugin.path)
                })
    return dict(auth_types=auth_types,
                referrer=req.params.get('referrer', ''))
Exemplo n.º 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))
Exemplo n.º 5
0
def notfound(req):
    return HTTPFound(location="%s?%s" %
                     (req.registry['settings']['base_auth_url'],
                      urlencode({'referrer': generate_url(req, req.path)})))
Exemplo n.º 6
0
def notfound(req):
    return HTTPFound(location="%s?%s" % (
        req.registry['settings']['base_auth_url'],
        urlencode({'referrer': generate_url(req, req.path)})))