Esempio n. 1
0
def privacy_user(user, client):
    if 'password' in user:
        del user['password']
    u_id = redis_conn.get(get_w_key(client))
    user.update(redis_conn.hgetall(get_user_key(u_id)))
    if 'topic' in user:
        user['topic'] = eval(user['topic'])
    return user
Esempio n. 2
0
 def current_user(client):
     u_id = redis_conn.get(get_w_key(client))
     user_info = conn.get(
         'select rolename, sex, avatar from user_info where u_id="%s"' %
         u_id)
     if user_info:
         return privacy_user(user_info, client)
     else:
         return privacy_user(dict(), client)
Esempio n. 3
0
    def update_user(client, r_id=None, p_id=None, status=None, topic=None):
        u_id = redis_conn.get(get_w_key(client))
        u_key = get_user_key(u_id)

        if r_id is not None:
            redis_conn.hset(u_key, 'r_id', r_id)
        if p_id is not None:
            redis_conn.hset(u_key, 'p_id', p_id)
        if status is not None:
            redis_conn.hset(u_key, 'status', status)
        if topic is not None:
            redis_conn.hset(u_key, 'topic', topic)

        return UserTool.current_user(client)
Esempio n. 4
0
    def quit(client, clients):

        room = RoomTool.leave_room(client)

        user = UserTool.current_user(client)
        w_key = get_w_key(client)
        u_id = redis_conn.get(w_key)
        u_key = get_user_key(u_id)

        if w_key is None or u_key is None:
            return None

        redis_conn.delete(w_key)
        redis_conn.delete(u_key)

        del clients[str(id(client))]

        if user:
            Packet(header='user.leave', data=user,
                   msg=None).write_message_to(clients=clients)
        if room:
            Packet(header='rooms.info', data=room,
                   msg=None).write_message_to(clients=clients)
Esempio n. 5
0
 def is_login(client):
     result = True if redis_conn.get(get_w_key(client)) else False
     return result