Пример #1
0
def on_receive(message, pk):
    video = get_video(pk)
    data = get_data(message)

    if set(data.keys()) != set(('handler', 'message')):
        log.debug("Message unexpected format data")
        return
    else:
        log.debug('Chat message is ok.')

    blackList = settings.WORDS_BLACK_LIST
    wordList = re.sub("[^\w]", " ", data['message'].lower()).split()
    censured_words = list(set(blackList) & set(wordList))
    message = data['message']

    if censured_words:
        for word in censured_words:
            message = re.sub(word, '♥', message, flags=re.IGNORECASE)

    user = User.objects.get(id=decrypt(data['handler']))
    message = Message.objects.create(video=video, user=user,
                                     message=message)
    Group(video.group_chat_name).send(
        {'text': json.dumps({"hmtl": message.html_body()})}
    )
Пример #2
0
def email_complete(request, backend, *args, **kwargs):
    """Authentication complete view"""
    verification_code = decrypt(request.GET.get('verification_code', ''))
    if '||' in verification_code:
        verification_code, session_key = verification_code.split('||')
        session_key = base64.b64decode(session_key)
        session = SessionStore(session_key)
        if request.session.session_key != session_key:
            logout(request)
        request.session.update(dict(session.items()))

    url = '{0}?verification_code={1}'.format(
        reverse('social:complete', args=(backend, )), verification_code)
    return redirect(url)
Пример #3
0
def on_receive(message, pk):
    video = get_video(pk)
    data = get_data(message)

    if not video.closed_date:
        if set(data.keys()) != set(('handler', 'question', 'is_vote')):
            log.debug("Message unexpected format data")
            return
        else:
            log.debug('Question message is ok.')

        if not data['handler']:
            return

        user = User.objects.get(id=decrypt(data['handler']))
        if data['is_vote']:
            question = Question.objects.get(id=data['question'])
            if question.user != user:
                vote, created = UpDownVote.objects.get_or_create(
                    user=user, question=question, vote=True)
                if not created:
                    vote.delete()
        else:
            blackList = settings.WORDS_BLACK_LIST
            wordList = re.sub("[^\w]", " ", data['question'].lower()).split()
            censured_words = list(set(blackList) & set(wordList))
            query = data['question']

            if censured_words:
                for word in censured_words:
                    query = re.sub(word, '♥', query, flags=re.IGNORECASE)
            question = Question.objects.create(video=video,
                                               user=user,
                                               question=query)
            UpDownVote.objects.create(question=question, user=user, vote=True)

        vote_list = []
        for vote in question.votes.all():
            vote_list.append(encrypt(str(vote.user.id).rjust(10)))

        Group(video.group_questions_name).send({
            'text':
            json.dumps({
                'id': question.id,
                'user': encrypt(str(user.id).rjust(10)),
                'voteList': vote_list,
                'html': question.html_question_body(user)
            })
        })
Пример #4
0
def email_complete(request, backend, *args, **kwargs):
    """Authentication complete view"""
    verification_code = decrypt(request.GET.get('verification_code', ''))
    if '||' in verification_code:
        verification_code, session_key = verification_code.split('||')
        session_key = base64.b64decode(session_key)
        session = SessionStore(session_key)
        if request.session.session_key != session_key:
            logout(request)
        request.session.update(dict(session.items()))

    url = '{0}?verification_code={1}'.format(
        reverse('social:complete', args=(backend,)),
        verification_code
    )
    return redirect(url)
Пример #5
0
def email_change(request, *args, **kwargs):
    """Authentication complete view"""
    try:
        key = request.GET.get('activation_key', '')
        if len(key) > 1:
            activation_key = decrypt(key[:-1])
    except TypeError:
        return redirect(reverse('incorrect_key'))
    if '||' in activation_key:
        pk, email, rand_val = activation_key.split('||')
        try:
            user = User.objects.get(pk=pk)
            user.email = email
            user.save()
        except User.DoesNotExist:
            raise Http404

    return redirect(reverse('profile'))
Пример #6
0
def email_change(request, *args, **kwargs):
    """Authentication complete view"""
    try:
        key = request.GET.get('activation_key', '')
        if len(key) > 1:
            activation_key = decrypt(key[:-1])
    except TypeError:
        return redirect(reverse('incorrect_key'))
    if '||' in activation_key:
        pk, email, rand_val = activation_key.split('||')
        try:
            user = User.objects.get(pk=pk)
            user.email = email
            user.save()
        except User.DoesNotExist:
            raise Http404

    return redirect(reverse('profile'))
Пример #7
0
def on_receive(message, pk):
    room = get_room(pk)
    data = get_data(message)

    if 'heartbeat' in data.keys():
        Presence.objects.touch(message.reply_channel.name)
        return

    if not data['handler']:
        return

    blackList = [x.strip() for x in config.WORDS_BLACK_LIST.split(',')]

    if set(data.keys()) == set(('handler', 'question', 'is_vote')):
        user = User.objects.get(id=decrypt(data['handler']))
        if data['is_vote']:
            question = Question.objects.get(id=data['question'])
            if question.user != user:
                vote, created = UpDownVote.objects.get_or_create(
                    user=user, question=question, vote=True)
                if not created:
                    vote.delete()
        else:
            if len(data['question']) <= 300:
                wordList = re.sub("[^\w]", " ",
                                  data['question'].lower()).split()
                censured_words = list(set(blackList) & set(wordList))
                query = data['question']

                if censured_words:
                    for word in censured_words:
                        query = re.sub(word, '♥', query, flags=re.IGNORECASE)
                question = Question.objects.create(room=room,
                                                   user=user,
                                                   question=query)
                UpDownVote.objects.create(question=question,
                                          user=user,
                                          vote=True)
            else:
                return

        vote_list = []
        for vote in question.votes.all():
            vote_list.append(encrypt(str(vote.user.id).rjust(10)))

        Group(room.group_room_name).send({
            'text':
            json.dumps({
                'id': question.id,
                'question': True,
                'user': encrypt(str(user.id).rjust(10)),
                'groupName': question.room.legislative_body_initials,
                'voteList': vote_list,
                'answered': question.answered,
                'html': question.html_question_body(user, 'room')
            })
        })

        log.debug('Question message is ok.')

    elif set(data.keys()) == set(('handler', 'message')):
        word_list = re.sub("[^\w]", " ", data['message'].lower()).split()
        censured_words = list(set(blackList) & set(word_list))

        message = data['message']

        if message.strip():
            if censured_words:
                for word in censured_words:
                    message = re.sub(word, '♥', message, flags=re.IGNORECASE)

            user = User.objects.get(id=decrypt(data['handler']))
            message = Message.objects.create(room=room,
                                             user=user,
                                             message=message)
            Group(room.group_room_name).send({
                'text':
                json.dumps({
                    "chat": True,
                    "html": message.html_body()
                })
            })

        log.debug('Chat message is ok.')

    else:
        log.debug("Message unexpected format data")
        return