Example #1
0
 def index(self):
     '''
     Redirect user on tequila page in order to log him
     '''
     u = resolve_relative_url(url(), request.environ)
     res = tequila.create_request(u+'/login/auth','tequila.epfl.ch')
     redirect('https://tequila.epfl.ch/cgi-bin/tequila/requestauth?request'+res)
Example #2
0
 def start_response_wrapper(status, headers, exc_info=None):
     location_header = 'location'
     status_code = int(status.split(None,1)[0])
     if (status_code >= 301 and status_code <= 303) or status_code == 307:
         location = header_value(headers, location_header)
         if location:
             replace_header(headers, location_header, resolve_relative_url(location, environ))
     return start_response(status, headers, exc_info)
Example #3
0
 def relative_redirect(cls, dest_uri, environ, detail=None, headers=None, comment=None):
     """
     Create a redirect object with the dest_uri, which may be relative,
     considering it relative to the uri implied by the given environ.
     """
     location = resolve_relative_url(dest_uri, environ)
     headers = headers or []
     headers.append(('Location', location))
     return cls(detail=detail, headers=headers, comment=comment)
Example #4
0
    def index(self, came_from='/'):
        '''
        Redirect user on tequila page in order to log him
        '''
        if tg.config.get('authentication.disable').lower() in ['t', 'true']:
            print constants.admin_user_email()

            environ = request.environ
            authentication_plugins = environ['repoze.who.plugins']
            identifier = authentication_plugins['ticket']
            secret = identifier.secret
            cookiename = identifier.cookie_name
            remote_addr = environ['REMOTE_ADDR']
            user = DBSession.query(User).filter(
                User.email == constants.admin_user_email()).first()
            admins = tg.config.get('admin.mails')
            group_admins = DBSession.query(Group).filter(
                Group.id == constants.group_admins_id).first()
            if user.email in admins:
                user not in group_admins.users and group_admins.users.append(
                    user)
            else:
                user in group_admins.users and group_admins.users.remove(user)
            DBSession.flush()
            userdata = "%s|%s" % (user.id, user in group_admins.users)

            ticket = auth_tkt.AuthTicket(secret,
                                         user.email,
                                         remote_addr,
                                         tokens=token,
                                         user_data=userdata,
                                         time=None,
                                         cookie_name=cookiename,
                                         secure=True)

            val = ticket.cookie_value()
            # set it in the cookies
            response.set_cookie(cookiename,
                                value=val,
                                max_age=None,
                                path='/',
                                domain=None,
                                secure=False,
                                httponly=False,
                                comment=None,
                                expires=None,
                                overwrite=False)
            raise redirect(came_from)

        u = resolve_relative_url(url(), request.environ)
        res = tequila.create_request(u + '/login/auth', 'tequila.epfl.ch')
        raise redirect(
            'https://tequila.epfl.ch/cgi-bin/tequila/requestauth?request' +
            res)
 def relative_redirect(cls,
                       dest_uri,
                       environ,
                       detail=None,
                       headers=None,
                       comment=None):
     """
     Create a redirect object with the dest_uri, which may be relative, 
     considering it relative to the uri implied by the given environ.
     """
     location = resolve_relative_url(dest_uri, environ)
     headers = headers or []
     headers.append(('Location', location))
     return cls(detail=detail, headers=headers, comment=comment)
Example #6
0
File: login.py Project: bbcf/pygdv
    def index(self, came_from='/'):
        '''
        Redirect user on tequila page in order to log him
        '''
        if tg.config.get('authentication.disable').lower() in ['t', 'true']:
            print constants.admin_user_email()

            environ = request.environ
            authentication_plugins = environ['repoze.who.plugins']
            identifier = authentication_plugins['ticket']
            secret = identifier.secret
            cookiename = identifier.cookie_name
            remote_addr = environ['REMOTE_ADDR']
            user = DBSession.query(User).filter(User.email == constants.admin_user_email()).first()
            admins = tg.config.get('admin.mails')
            group_admins = DBSession.query(Group).filter(Group.id == constants.group_admins_id).first()
            if user.email in admins:
                user not in group_admins.users and group_admins.users.append(user)
            else:
                user in group_admins.users and group_admins.users.remove(user)
            DBSession.flush()
            userdata = "%s|%s" % (user.id, user in group_admins.users)

            ticket = auth_tkt.AuthTicket(
                secret, user.email, remote_addr, tokens=token,
                user_data=userdata, time=None, cookie_name=cookiename,
                secure=True)

            val = ticket.cookie_value()
            # set it in the cookies
            response.set_cookie(
                cookiename, value=val, max_age=None, path='/', domain=None, secure=False,
                httponly=False, comment=None, expires=None, overwrite=False)
            raise redirect(came_from)

        u = resolve_relative_url(url(), request.environ)
        res = tequila.create_request(u + '/login/auth', 'tequila.epfl.ch')
        raise redirect('https://tequila.epfl.ch/cgi-bin/tequila/requestauth?request' + res)
Example #7
0
def returnHttpError(error_object, environ, start_response):
    code = error_object.code
    title = error_object.title
    explanation = error_object.explanation

    try:
        location = error_object.args[0]
    except:
        location = ""

    headers = []
    headers.append(('Content-Type', 'text/html'))
    if code == 302:
        if location != "":
            location = resolve_relative_url(location, environ)
            headers.append(('Location', location))
        else:
            code = 404
            title = 'Not Found'
            explanation = ('The resource could not be found.')

    start_response('%i %s' % (code, title), headers)
    return [explanation]
Example #8
0
 def absolute_url(self, *args, **kw):
     rel_url = self.url(*args, **kw)
     return request.resolve_relative_url(rel_url, self._environ)
Example #9
0
    def add(self, req, url=None, alias=None, Session=None):
        c = Params(code=1)
        if not url:
            c.error = 'You must provide an url'
            return c

        if len(url) > 255:
            c.error = 'Lamer !'
            return c

        scheme, netloc, path_info, dummy, qs, fragment = urlparse(url)
        if scheme not in self.valid_schemes:
            c.error = 'You must provide a valid url. Supported schemes are %s' % ', '.join(self.valid_schemes)
            return c
        elif not netloc or [a for a in netloc if a not in valid_chars + '._-']:
            c.error = 'You must provide a valid url.'
            return c

        my_host = resolve_relative_url('/', req.environ)
        if my_host.endswith('/'):
            my_host = my_host[:-1]

        if url.startswith(my_host):
            c.error = 'This is not very useful. right ?'
            return c

        #url = url.replace(' ', '%20')
        if isinstance(url, str):
            url = url.decode('utf-8')

        if alias:
            for char in '\?& ':
                alias = alias.replace(char, '-')
            if isinstance(alias, str):
                alias = alias.decode('utf-8')
            id = alias
        else:
            for i in [1,2,3]:
                id = random_alias([5,10])
                record = Session.execute(sa.select([Url.alias], Url.alias==id)).fetchone()
                if record is None:
                    break

        c.code = 0

        record = Url()
        record.alias = id
        record.url = url
        Session.add(record)
        try:
            Session.commit()
        except saexc.IntegrityError:
            c.code = 1
            if alias:
                record = meta.engine.execute(sa.select([Url.alias, Url.url], sa.or_(Url.url==url, Url.alias==id))).fetchone()
            else:
                record = meta.engine.execute(sa.select([Url.alias, Url.url], Url.url==url)).fetchone()
            if url:
                old_alias = record.alias
                old_url = record.url
                if old_url == url:
                    c.error = '%s is already bind to %s/%s' % (url, my_host, old_alias)
                    c.url = url
                    c.new_url = u'%s/%s' % (my_host, old_alias)
                elif old_alias == alias:
                    c.error = u'%s/%s is already bind to %s' % (my_host, alias, old_url)
                else:
                    c.error = url
            elif alias:
                c.error = 'This alias already exist'
            else:
                c.error = 'An error occur'
        else:
            c.url = url
            c.new_url = u'%s/%s' % (my_host, id)
        if c.error:
            c.error = c.error
        return c