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)
 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)
Example #3
0
    def prepare(self):
        self.id = str(uuid4())
        self.joined = False
        try:
            self.session_id = self.cookies["newparp"].value
            self.chat_id = int(self.path_args[0])
            self.user_id = int(redis.get("session:%s" % self.session_id))
        except (KeyError, TypeError, ValueError):
            self.send_error(400)
            return
        try:
            self.chat_user, self.user, self.chat = yield thread_pool.submit(
                self.get_chat_user)
        except NoResultFound:
            self.send_error(404)
            return
        # Remember the user number so typing notifications can refer to it
        # without reopening the database session.
        self.user_number = self.chat_user.number
        queue_user_meta(
            self, redis,
            self.request.headers.get("X-Forwarded-For",
                                     self.request.remote_ip))

        try:
            if self.user.group != "active":
                raise BannedException

            yield thread_pool.submit(authorize_joining, redis, self.db, self)
        except (UnauthorizedException, BannedException,
                TooManyPeopleException):
            self.send_error(403)
            return
Example #4
0
    def prepare(self):
        self.id = str(uuid4())
        self.joined = False
        try:
            self.session_id = self.cookies["newparp"].value
            self.chat_id = int(self.path_args[0])
            self.user_id = int(redis.get("session:%s" % self.session_id))
        except (KeyError, TypeError, ValueError):
            self.send_error(400)
            return
        try:
            self.chat_user, self.user, self.chat = yield thread_pool.submit(self.get_chat_user)
        except NoResultFound:
            self.send_error(404)
            return

        # Remember the user number so typing notifications can refer to it
        # without reopening the database session.
        self.user_number = self.chat_user.number
        queue_user_meta(self, redis, self.request.headers.get("X-Forwarded-For", self.request.remote_ip))

        self.user_list = UserListStore(redis_chat, self.chat_id)

        try:
            if self.user.group != "active":
                raise BannedException

            yield thread_pool.submit(authorize_joining, self.db, self)
        except (UnauthorizedException, BannedException, BadAgeException, TooManyPeopleException):
            self.send_error(403)
            return
Example #5
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)
Example #6
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)