How to use the channels.auth.channel_session_user_from_http function in channels

To help you get started, we’ve selected a few channels examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github ngageoint / voxel-globe / voxel_globe / websockets / consumers.py View on Github external
@channel_session_user_from_http
def ws_connect(message):
  if (message.content['path'] == '/'):
    Group("ws_logger").add(message.reply_channel)
    return

  prefix, user, session = message.content['path'].strip('/').split('/')
  prefix = str(prefix)

  if (prefix != "ws_logger"):
    return

  user = str(user)
  session = str(session)
  message.channel_session['user'] = user
  message.channel_session['session_key'] = session
github dduk-ddak / coding-night-live / coding_night_live / consumers.py View on Github external
@channel_session_user_from_http
def ws_connect(message):
    message.reply_channel.send({'accept': True})
    message.channel_session['room'] = []
github ploggingdev / djangochat / chatdemo / consumers.py View on Github external
@channel_session_user_from_http
def loadhistory_connect(message):
    message.reply_channel.send({"accept": True})
github sinwar / jchat / chat / consumers.py View on Github external
@channel_session_user_from_http
def ws_connect(message):
    # Initialise their session
    # like django session
    message.channel_session['rooms'] = []
github andyalam / django_instagram / feeds / consumers.py View on Github external
@channel_session_user_from_http
def ws_connect(message):
    path = message.content['path']
    room_label = path.replace('/chat/inbox/', '').replace('/', '')
    room = Room.objects.get(label=room_label)

    Group('chat-' + room_label).add(message.reply_channel)
    message.channel_session['room'] = room.label
github ilavender / sensu_drive / sensu_drive / consumers.py View on Github external
@channel_session_user_from_http
def websocket_connect_onduty(message):
    
    if not message.user.is_authenticated():
        logger.error('websocket_connect_onduty. user = %s is NOT authenticated', message.user)
        return
    
    logger.debug('websocket_connect_events. user = %s', message.user)
    Group("on-duty").add(message.reply_channel)
    Group("announcement").add(message.reply_channel)
    message.reply_channel.send({"accept": True})
github ansible / awx / awx / network_ui / consumers.py View on Github external
@channel_session_user_from_http
def ws_connect(message):
    if not message.user.is_authenticated():
        logger.error("Request user is not authenticated to use websocket.")
        message.reply_channel.send({"close": True})
        return
    else:
        message.reply_channel.send({"accept": True})

    data = urlparse.parse_qs(message.content['query_string'])
    inventory_id = parse_inventory_id(data)
    try:
        inventory = Inventory.objects.get(id=inventory_id)
    except Inventory.DoesNotExist:
        logger.error("User {} attempted connecting inventory_id {} that does not exist.".format(
            message.user.id, inventory_id)
        )
github antsmc2 / webrtc_meetings / webrtc_meetings / routing.py View on Github external
@channel_session_user_from_http
def mark_present(message):
    ip, port = message['client']
    wlogger.info('msg ip: %s, port: %s' % (ip, port))
    a = Attendant(ip=ip, port=port, channel_name=message.reply_channel.name,
                  user=message.user.username,
                  details=get_request_params(message['query_string']))
    store.hset(ONLINE, message.reply_channel.name, a.dumps())
    message.reply_channel.send({'accept': True})
github narrowfail / django-channels-chat / core / consumers.py View on Github external
@channel_session_user_from_http
def ws_add(message):
    # Accept connection
    message.reply_channel.send({"accept": True})
    # Add them to the user group
    Group('%s' % message.user.id).add(message.reply_channel)
github Cloud-CV / Fabrik / caffe_app / consumers.py View on Github external
@channel_session_user_from_http
def ws_connect(message):
    print('Connection being established...')
    message.reply_channel.send({
        'accept': True
    })
    # extracting id of network from url params
    params = urlparse.parse_qs(message.content['query_string'])
    networkId = params.get('id', ('Not Supplied',))[0]
    message.channel_session['networkId'] = networkId
    # adding socket to a group based on networkId to send updates of network
    Group('model-{0}'.format(networkId)).add(message.reply_channel)