Ejemplo n.º 1
0
    def authenticate(self, req):
        """Return the name of the remote user, or `None` if the identity of the
        user is unknown."""

        # check for an authenticated user
        login_module = LoginModule(self.env)
        remote_user = login_module.authenticate(req)
        if remote_user:
            return remote_user

        # authenticate via a CAPTCHA
        if 'captchaauth' in req.args and 'captchaid' in req.args:

            # ensure CAPTCHA identification
            captcha = self.captcha(req)
            if captcha != req.args['captchaauth']:
                return

            # ensure sane identity
            name, email = self.identify(req)
            if name is None:
                return
            if AccountManager and name in AccountManager(self.env).get_users():
                return

            # delete used CAPTCHA on success
            try:
                execute_non_query(self.env, "DELETE FROM captcha WHERE id=%s",
                                  req.args['captchaid'])
            except:
                pass

            # log the user in
            req.environ['REMOTE_USER'] = name
            login_module._do_login(req)
Ejemplo n.º 2
0
    def authenticate(self, req):
        """Return the name of the remote user, or `None` if the identity of the
        user is unknown."""

        # check for an authenticated user
        login_module = LoginModule(self.env)
        remote_user = login_module.authenticate(req)
        if remote_user:
            return remote_user

        # authenticate via a CAPTCHA
        if 'captchaauth' in req.args and 'captchaid' in req.args:

            # ensure CAPTCHA identification
            captcha = self.captcha(req)
            if captcha != req.args['captchaauth']:
                return 

            # ensure sane identity
            name, email = self.identify(req)
            if name is None:
                return
            if AccountManager and name in AccountManager(self.env).get_users():
                return

            # delete used CAPTCHA on success
            try:
                execute_non_query(self.env, "DELETE FROM captcha WHERE id=%s", req.args['captchaid'])
            except:
                pass

            # log the user in
            req.environ['REMOTE_USER'] = name
            login_module._do_login(req)
Ejemplo n.º 3
0
    def set_location(self, ticket, lat, lon):
        """
        sets the ticket location in the db
        * ticket: the ticket id (int)
        * lat, lon: the lattitude and longtitude (degrees)
        """

        # determine if we need to insert or update the table
        # (SQL is retarded)
        if get_first_row(self.env, "select ticket from ticket_location where ticket='%s'" % ticket):
            execute_non_query(
                self.env,
                "update ticket_location set ticket=%s, latitude=%s, longitude=%s where ticket=%s",
                ticket,
                lat,
                lon,
                ticket,
            )
        else:
            execute_non_query(
                self.env,
                "insert into ticket_location (ticket, latitude, longitude) values (%s, %s, %s)",
                ticket,
                lat,
                lon,
            )
Ejemplo n.º 4
0
    def upgrade_environment(self, db):
        """Actually perform an environment upgrade.
        
        Implementations of this method should not commit any database
        transactions. This is done implicitly after all participants have
        performed the upgrades they need without an error being raised.
        """

        # create a table for ticket location
        ticket_location_table = Table("ticket_location", key="ticket")[
            Column("ticket", type="int"),
            Column("latitude", type="float"),
            Column("longitude", type="float"),
            Index(["ticket"]),
        ]
        create_table(self.env, ticket_location_table)

        # update ticket locations
        tickets = get_column(self.env, "ticket", "id")
        tickets = [Ticket(self.env, ticket) for ticket in tickets]
        for ticket in tickets:
            try:
                location, (lat, lon) = self.locate_ticket(ticket)
                self.set_location(ticket.id, lat, lon)
            except GeolocationException:
                pass

        # note the DB version
        execute_non_query(self.env, "insert into system (name, value) values ('geoticket.db_version', '1');")

        # add a default dashboard panel
        self.default_dashboard()
Ejemplo n.º 5
0
    def upgrade_environment(self, db):
        """Actually perform an environment upgrade.
        
        Implementations of this method should not commit any database
        transactions. This is done implicitly after all participants have
        performed the upgrades they need without an error being raised.
        """

        # create a table for ticket location
        ticket_location_table = Table(
            'ticket_location', key='ticket')[Column('ticket', type='int'),
                                             Column('latitude', type='float'),
                                             Column('longitude', type='float'),
                                             Index(['ticket'])]
        create_table(self.env, ticket_location_table)

        # update ticket locations
        tickets = get_column(self.env, 'ticket', 'id')
        tickets = [Ticket(self.env, ticket) for ticket in tickets]
        for ticket in tickets:
            try:
                location, (lat, lon) = self.locate_ticket(ticket)
                self.set_location(ticket.id, lat, lon)
            except GeolocationException:
                pass

        # note the DB version
        execute_non_query(
            self.env,
            "insert into system (name, value) values ('geoticket.db_version', '1');"
        )

        # add a default dashboard panel
        self.default_dashboard()
Ejemplo n.º 6
0
    def delete_location(self, ticket):
        """
        deletes a ticket location in the db
        * ticket: the ticket id (int)
        """

        if get_first_row(self.env, "select ticket from ticket_location where ticket='%s'" % ticket):
            execute_non_query(self.env, "delete from ticket_location where ticket='%s'" % ticket)
    def create_db(self):
        autocomplete_table = Table('autocomplete', key='name')[ 
                                Column('name', 'text'),
                                Column('description', 'text')]
        autocomplete_values_table = Table('autocomplete_values')[
                                Column('autocomplete_name', 'text'), 
                                Column('value', 'text')]

        create_table(self.env, autocomplete_table)
        create_table(self.env, autocomplete_values_table)
        execute_non_query(self.env, """INSERT INTO system (name, value) VALUES 
                                    ('autocompleteplugin.db_version', '1');""")
Ejemplo n.º 8
0
    def delete_location(self, ticket):
        """
        deletes a ticket location in the db
        * ticket: the ticket id (int)
        """

        if get_first_row(
                self.env,
                "select ticket from ticket_location where ticket='%s'" %
                ticket):
            execute_non_query(
                self.env,
                "delete from ticket_location where ticket='%s'" % ticket)
    def create_db(self):
        repo_cache_table = Table("repository_node", key=("id"))[
            Column("id", auto_increment=True), Column("repo"), Column("filename"), Column("contents")
        ]
        create_table(self.env, repo_cache_table)

        repo_version_table = Table("repository_version", key=("id"))[
            Column("id", auto_increment=True), Column("repo"), Column("version")
        ]
        create_table(self.env, repo_version_table)

        execute_non_query(
            self.env, "insert into system (name, value) values ('multireposearch.sqlindexer.db_version', '1');"
        )
    def upgrade_environment(self, db):
        """Actually perform an environment upgrade.
        
        Implementations of this method should not commit any database
        transactions. This is done implicitly after all participants have
        performed the upgrades they need without an error being raised.
        """
        if not self.environment_needs_upgrade(db):
            return

        version = self.version()
        for version in range(self.version(), len(self.steps)):
            for step in self.steps[version]:
                step(self)
        execute_non_query(self.env, "update system set value='1' where name='multireposearch.sqlindexer.db_version';")
Ejemplo n.º 11
0
    def create_db(self):
        repo_cache_table = Table('repository_node', key=('id'))[
            Column('id', auto_increment=True),
            Column('repo'),
            Column('filename'),
            Column('contents'),
            ]
        create_table(self.env, repo_cache_table)

        repo_version_table = Table('repository_version', key=('id'))[
            Column('id', auto_increment=True),
            Column('repo'),
            Column('version'),
            ]
        create_table(self.env, repo_version_table)

        execute_non_query(self.env, "insert into system (name, value) values ('multireposearch.sqlindexer.db_version', '1');")
    def upgrade_environment(self, db):
        """Actually perform an environment upgrade.
        
        Implementations of this method don't need to commit any database
        transactions. This is done implicitly for each participant
        if the upgrade succeeds without an error being raised.

        However, if the `upgrade_environment` consists of small, restartable,
        steps of upgrade, it can decide to commit on its own after each
        successful step.
        """
        if not self.environment_needs_upgrade(db):
            return

        version = self.version()
        for version in range(self.version(), len(self.steps)):
            for step in self.steps[version]:
                step(self)
        execute_non_query(self.env, """UPDATE SYSTEM SET value='%s' WHERE 
                    name='autocompleteplugin.db_version';""" % len(self.steps))
Ejemplo n.º 13
0
    def set_location(self, ticket, lat, lon):
        """
        sets the ticket location in the db
        * ticket: the ticket id (int)
        * lat, lon: the lattitude and longtitude (degrees)
        """

        # determine if we need to insert or update the table
        # (SQL is retarded)
        if get_first_row(
                self.env,
                "select ticket from ticket_location where ticket='%s'" %
                ticket):
            execute_non_query(
                self.env,
                "update ticket_location set ticket=%s, latitude=%s, longitude=%s where ticket=%s",
                ticket, lat, lon, ticket)
        else:
            execute_non_query(
                self.env,
                "insert into ticket_location (ticket, latitude, longitude) values (%s, %s, %s)",
                ticket, lat, lon)
Ejemplo n.º 14
0
    def pre_process_request(self, req, handler):
        """Called after initial handler selection, and can be used to change
        the selected handler or redirect request.
        
        Always returns the request handler, even if unchanged.
        """

        if req.method == 'GET':
            if req.path_info.strip('/') in ['register', 'login'] and req.authname != 'anonymous':
                login_module = LoginModule(self.env)
                login_module._do_logout(req)
                req.redirect(req.href(req.path_info))


        if req.method == 'POST':

            realm = self.realm(req)

            # set the session data for name and email if CAPTCHA-authenticated
            if 'captchaauth' in req.args:
                name, email = self.identify(req)
                for field in 'name', 'email':
                    value = locals()[field]
                    if value:
                        req.session[field] = value
                req.session.save()
                if req.authname != 'anonymous' and realm == 'newticket':
                    req.args['author'] = name
                    if email:
                        req.args['author'] += ' <%s>' % email

            # redirect anonymous user posts that are not CAPTCHA-identified
            if req.authname == 'anonymous' and realm in self.realms:
                
                if 'captchaauth' in req.args and 'captchaid' in req.args:
                    # add warnings from CAPTCHA authentication
                    captcha = self.captcha(req)
                    if req.args['captchaauth'] != captcha:
                        add_warning(req, "You typed the wrong word. Please try again.")
                        try:
                            # delete used CAPTCHA
                            execute_non_query(self.env, "DELETE FROM captcha WHERE id=%s", req.args['captchaid'])
                        except:
                            pass

                    name, email = self.identify(req)
                    if not name:
                        add_warning(req, 'Please provide your name')
                    if AccountManager and name in AccountManager(self.env).get_users():
                        add_warning(req, '%s is already taken as by a registered user.  Please login or use a different name' % name)

                # redirect to previous location
                location = req.get_header('referer')
                if location:
                    location, query = urllib.splitquery(location)
                    
                    if realm == 'newticket':
                        args = [(key.split('field_',1)[-1], value)
                                for key, value in req.args.items()
                                if key.startswith('field_')]
                        location += '?%s' % urllib.urlencode(args)
                else:
                    location =  req.href()
                req.redirect(location)

        return handler
Ejemplo n.º 15
0
    def pre_process_request(self, req, handler):
        """Called after initial handler selection, and can be used to change
        the selected handler or redirect request.
        
        Always returns the request handler, even if unchanged.
        """

        if req.method == 'GET':
            if req.path_info.strip('/') in ['register', 'login'
                                            ] and req.authname != 'anonymous':
                login_module = LoginModule(self.env)
                login_module._do_logout(req)
                req.redirect(req.href(req.path_info))

        if req.method == 'POST':

            realm = self.realm(req)

            # set the session data for name and email if CAPTCHA-authenticated
            if 'captchaauth' in req.args:
                name, email = self.identify(req)
                for field in 'name', 'email':
                    value = locals()[field]
                    if value:
                        req.session[field] = value
                req.session.save()
                if req.authname != 'anonymous' and realm == 'newticket':
                    req.args['author'] = name
                    if email:
                        req.args['author'] += ' <%s>' % email

            # redirect anonymous user posts that are not CAPTCHA-identified
            if req.authname == 'anonymous' and realm in self.realms:

                if 'captchaauth' in req.args and 'captchaid' in req.args:
                    # add warnings from CAPTCHA authentication
                    captcha = self.captcha(req)
                    if req.args['captchaauth'] != captcha:
                        add_warning(
                            req, "You typed the wrong word. Please try again.")
                        try:
                            # delete used CAPTCHA
                            execute_non_query(
                                self.env, "DELETE FROM captcha WHERE id=%s",
                                req.args['captchaid'])
                        except:
                            pass

                    name, email = self.identify(req)
                    if not name:
                        add_warning(req, 'Please provide your name')
                    if AccountManager and name in AccountManager(
                            self.env).get_users():
                        add_warning(
                            req,
                            '%s is already taken as by a registered user.  Please login or use a different name'
                            % name)

                # redirect to previous location
                location = req.get_header('referer')
                if location:
                    location, query = urllib.splitquery(location)

                    if realm == 'newticket':
                        args = [(key.split('field_', 1)[-1], value)
                                for key, value in req.args.items()
                                if key.startswith('field_')]
                        location += '?%s' % urllib.urlencode(args)
                else:
                    location = req.href()
                req.redirect(location)

        return handler
Ejemplo n.º 16
0
 def shapefile_delete(self, req):
     """remove shapefile database"""
     execute_non_query(self.env, "DROP TABLE georegions")
     execute_non_query(self.env, "DELETE FROM geometry_columns WHERE f_table_name='georegions'")