Example #1
0
    def stream_via_token(cls, token):
        '''
        Set token user to online and publish presence of this user to all
        friends.
        '''
        NereidUser = Pool().get('nereid.user')

        if hasattr(current_app, 'redis_client'):
            redis_client = current_app.redis_client
        else:
            redis_client = Redis(
                CONFIG.get('redis_host', 'localhost'),
                int(CONFIG.get('redis_port', 6379))
            )

        key = 'chat:token:%s' % token
        if not redis_client.exists(key):
            abort(404)

        nereid_user = NereidUser(int(redis_client.get(key)))
        nereid_user.broadcast_presence()

        return Response(
            cls.generate_event_stream(
                nereid_user.id,
                Transaction().cursor.dbname
            ),
            mimetype='text/event-stream'
        )
 def _get_es_connection():
     """
     Return a PYES connection
     """
     return ES(
         CONFIG.get('elastic_search_server', 'localhost:9200').split(',')
     )
Example #3
0
    def token(cls):
        '''
        Generate token for current_user with TTL of 1 hr.
        '''
        if hasattr(current_app, 'redis_client'):
            redis_client = current_app.redis_client
        else:
            redis_client = Redis(
                CONFIG.get('redis_host', 'localhost'),
                int(CONFIG.get('redis_port', 6379))
            )

        token = unicode(uuid.uuid4())
        key = 'chat:token:%s' % token
        # Save token to redis and set TTL of 1 hr.
        redis_client.set(key, current_user.id)
        redis_client.expire(key, 3600)

        return jsonify({
            'token': token
        })
Example #4
0
    def stream_via_token(cls, token):
        '''
        Set token user to online and publish presence of this user to all
        friends.
        '''
        NereidUser = Pool().get('nereid.user')

        if hasattr(current_app, 'redis_client'):
            redis_client = current_app.redis_client
        else:
            redis_client = Redis(CONFIG.get('redis_host', 'localhost'),
                                 int(CONFIG.get('redis_port', 6379)))

        key = 'chat:token:%s' % token
        if not redis_client.exists(key):
            abort(404)

        nereid_user = NereidUser(int(redis_client.get(key)))
        nereid_user.broadcast_presence()

        return Response(cls.generate_event_stream(nereid_user.id,
                                                  Transaction().cursor.dbname),
                        mimetype='text/event-stream')
Example #5
0
    def start_servers(self):
        # Launch Server
        for proto, _class in protocols.PROTOCOLS.iteritems():
            if proto not in CONFIG.options or not CONFIG[proto]:
                continue
            ssl_config = CONFIG.get('ssl_%s' % proto, False)
            for hostname, port in CONFIG[proto]:
                self.servers[proto].append(_class(hostname, port, ssl_config))
                self.logger.info("starting %s%s protocol on %s:%d" %
                    (proto.upper(), ssl_config and ' SSL' or '', hostname or '*',
                        port))

        for proto, servers in self.servers.iteritems():
            for server in servers:
                server.start()
Example #6
0
from trytond.pool import PoolMeta, Pool
from trytond.modules.nereid.party import AddressForm
from trytond.config import CONFIG
from nereid import request, current_app

__metaclass__ = PoolMeta
__all__ = ['Address']

geoip = None
try:
    from pygeoip import GeoIP
except ImportError:
    logging.error("pygeoip is not installed")
else:
    path = os.environ.get('GEOIP_DATA_PATH', CONFIG.get('geoip_data_path'))
    if path:
        geoip = GeoIP(path)


class WebshopAddressForm(AddressForm):
    """Custom address form for webshop
    """
    def get_default_country(self):
        """Get the default country based on geoip data.
        """
        if not geoip:
            return None

        Country = Pool().get('country.country')
        try:
Example #7
0
 def default_servers():
     """
     Find the server from config and return
     """
     return CONFIG.get('elastic_search_server', 'localhost:9200')
 def default_servers():
     """
     Find the server from config and return
     """
     return CONFIG.get('elastic_search_server', 'localhost:9200')
Example #9
0
from trytond.pool import PoolMeta, Pool
from trytond.modules.nereid.party import AddressForm
from trytond.config import CONFIG
from nereid import request, current_app

__metaclass__ = PoolMeta
__all__ = ['Address']

geoip = None
try:
    from pygeoip import GeoIP
except ImportError:
    logging.error("pygeoip is not installed")
else:
    path = os.environ.get('GEOIP_DATA_PATH', CONFIG.get('geoip_data_path'))
    if path:
        geoip = GeoIP(path)


class WebshopAddressForm(AddressForm):
    """Custom address form for webshop
    """
    def get_default_country(self):
        """Get the default country based on geoip data.
        """
        if not geoip:
            return None

        Country = Pool().get('country.country')
        try: