def get_chat_user():
    try:
        g.chat_user, g.user, g.chat = g.db.query(
            ChatUser,
            User,
            AnyChat,
        ).join(
            User,
            ChatUser.user_id == User.id,
        ).join(
            AnyChat,
            ChatUser.chat_id == AnyChat.id,
        ).filter(
            and_(
                ChatUser.user_id == g.user_id,
                ChatUser.chat_id == int(request.form["chat_id"]),
            )).one()
    except NoResultFound:
        abort(400)
    queue_user_meta(
        g, g.redis, request.headers.get("X-Forwarded-For",
                                        request.remote_addr))
    if g.user.group != "active":
        abort(403)
    g.ip_banned = get_ip_banned(
        request.headers.get("X-Forwarded-For", request.remote_addr), g.db,
        g.redis)
    if g.ip_banned and not g.user.is_admin:
        abort(403)
Esempio n. 2
0
def get_chat_user():
    try:
        g.chat_user, g.user, g.chat = g.db.query(
            ChatUser, User, AnyChat,
        ).join(
            User, ChatUser.user_id == User.id,
        ).join(
            AnyChat, ChatUser.chat_id == AnyChat.id,
        ).filter(and_(
            ChatUser.user_id == g.user_id,
            ChatUser.chat_id == int(request.form["chat_id"]),
        )).one()
    except NoResultFound:
        abort(400)

    queue_user_meta(g, g.redis, request.headers.get("X-Forwarded-For", request.remote_addr))

    if g.user.group != "active":
        abort(403)

    g.ip_banned = get_ip_banned(request.headers.get("X-Forwarded-For", request.remote_addr), g.db, g.redis)
    if g.ip_banned and not g.user.is_admin:
        abort(403)

    g.user_list = UserListStore(NewparpRedis(connection_pool=redis_chat_pool), g.chat.id)
 def decorated_function(*args, **kwargs):
     db_connect()
     g.user = None
     if g.user_id is not None:
         try:
             g.user = g.db.query(User).filter(User.id == g.user_id).one()
         except NoResultFound:
             return f(*args, **kwargs)
         queue_user_meta(
             g, g.redis,
             request.headers.get("X-Forwarded-For", request.remote_addr))
         g.unread_chats = g.db.query(
             func.count('*')).select_from(ChatUser).join(Chat).filter(
                 and_(
                     ChatUser.user_id == g.user.id,
                     ChatUser.subscribed == True,
                     Chat.last_message > ChatUser.last_online,
                 )).scalar()
         if g.user.group == "banned":
             return redirect("http://rp.terminallycapricio.us/")
     g.ip_banned = get_ip_banned(
         request.headers.get("X-Forwarded-For", request.remote_addr), g.db,
         g.redis)
     if g.ip_banned and (g.user is None or not g.user.is_admin):
         return redirect("http://pup-king-louie.tumblr.com/")
     return f(*args, **kwargs)
Esempio n. 4
0
 def decorated_function(*args, **kwargs):
     db_connect()
     g.user = None
     if g.user_id is not None:
         try:
             g.user = g.db.query(User).filter(User.id == g.user_id).one()
         except NoResultFound:
             return f(*args, **kwargs)
         queue_user_meta(g, g.redis, request.headers.get("X-Forwarded-For", request.remote_addr))
         g.unread_chats = g.db.query(func.count('*')).select_from(ChatUser).join(Chat).filter(and_(
             ChatUser.user_id == g.user.id,
             ChatUser.subscribed == True,
             Chat.last_message > ChatUser.last_online,
         )).scalar()
         if g.user.group == "banned":
             return redirect("http://rp.terminallycapricio.us/")
     g.ip_banned = get_ip_banned(request.headers.get("X-Forwarded-For", request.remote_addr), g.db, g.redis)
     if g.ip_banned and (g.user is None or not g.user.is_admin):
         return redirect("http://pup-king-louie.tumblr.com/")
     return f(*args, **kwargs)