Beispiel #1
0
def select_manage(userid):
    """Selects a user's information for display in the admin user management page.

    Args:
        userid (int): ID of user to fetch information for.

    Returns:
        Relevant user information as a dict.
    """
    query = d.execute(
        """
        SELECT
            lo.userid, lo.last_login, lo.email, lo.ip_address_at_signup,
            pr.unixtime, pr.username, pr.full_name, pr.catchphrase,
            ui.birthday, ui.gender, ui.country, pr.config
        FROM login lo
            INNER JOIN profile pr USING (userid)
            INNER JOIN userinfo ui USING (userid)
        WHERE lo.userid = %i
    """, [userid], ["single"])

    if not query:
        raise WeasylError("Unexpected")

    user_link_rows = d.engine.execute("""
        SELECT link_type, ARRAY_AGG(link_value ORDER BY link_value)
        FROM user_links
        WHERE userid = %(userid)s
        GROUP BY link_type
    """,
                                      userid=userid)

    active_user_sessions = d.engine.execute("""
        SELECT sess.created_at, sess.ip_address, ua.user_agent
        FROM login lo
            INNER JOIN sessions sess ON lo.userid = sess.userid
            INNER JOIN user_agents ua ON sess.user_agent_id = ua.user_agent_id
        WHERE lo.userid = %(userid)s
        ORDER BY sess.created_at DESC
    """,
                                            userid=userid).fetchall()

    return {
        "userid": query[0],
        "last_login": query[1],
        "email": query[2],
        "ip_address_at_signup": query[3],
        "unixtime": query[4],
        "username": query[5],
        "full_name": query[6],
        "catchphrase": query[7],
        "birthday": query[8],
        "gender": query[9],
        "country": query[10],
        "config": query[11],
        "staff_notes": shout.count(userid, staffnotes=True),
        "sorted_user_links": sort_user_links(user_link_rows),
        "user_sessions": active_user_sessions,
    }
Beispiel #2
0
def select_manage(userid):
    """Selects a user's information for display in the admin user management page.

    Args:
        userid (int): ID of user to fetch information for.

    Returns:
        Relevant user information as a dict.
    """
    query = d.execute("""
        SELECT
            lo.userid, lo.last_login, lo.email, lo.ip_address_at_signup,
            pr.unixtime, pr.username, pr.full_name, pr.catchphrase,
            ui.birthday, ui.gender, ui.country, pr.config
        FROM login lo
            INNER JOIN profile pr USING (userid)
            INNER JOIN userinfo ui USING (userid)
        WHERE lo.userid = %i
    """, [userid], ["single"])

    if not query:
        raise WeasylError("Unexpected")

    user_link_rows = d.engine.execute("""
        SELECT link_type, ARRAY_AGG(link_value ORDER BY link_value)
        FROM user_links
        WHERE userid = %(userid)s
        GROUP BY link_type
    """, userid=userid)

    active_user_sessions = d.engine.execute("""
        SELECT sess.created_at, sess.ip_address, ua.user_agent
        FROM login lo
            INNER JOIN sessions sess ON lo.userid = sess.userid
            INNER JOIN user_agents ua ON sess.user_agent_id = ua.user_agent_id
        WHERE lo.userid = %(userid)s
        ORDER BY sess.created_at DESC
    """, userid=userid).fetchall()

    return {
        "userid": query[0],
        "last_login": query[1],
        "email": query[2],
        "ip_address_at_signup": query[3],
        "unixtime": query[4],
        "username": query[5],
        "full_name": query[6],
        "catchphrase": query[7],
        "birthday": query[8],
        "gender": query[9],
        "country": query[10],
        "config": query[11],
        "staff_notes": shout.count(userid, staffnotes=True),
        "sorted_user_links": sort_user_links(user_link_rows),
        "user_sessions": active_user_sessions,
    }
Beispiel #3
0
def manageuser(userid, form):
    if userid not in staff.MODS:
        raise WeasylError("Unexpected")

    query = d.execute(
        "SELECT userid, username, config, profile_text, catchphrase FROM profile"
        " WHERE userid = (SELECT userid FROM login WHERE login_name = '%s')",
        [d.get_sysname(form.name)], ["single"])

    if not query:
        raise WeasylError("noUser")

    return {
        "userid": query[0],
        "username": query[1],
        "config": query[2],
        "profile_text": query[3],
        "catchphrase": query[4],
        "user_media": media.get_user_media(query[0]),
        "staff_notes": shout.count(query[0], staffnotes=True),
    }
Beispiel #4
0
def manageuser(userid, form):
    if userid not in staff.MODS:
        raise WeasylError("Unexpected")

    query = d.execute(
        "SELECT userid, username, config, profile_text, catchphrase FROM profile"
        " WHERE userid = (SELECT userid FROM login WHERE login_name = '%s')",
        [d.get_sysname(form.name)], ["single"])

    if not query:
        raise WeasylError("noUser")

    return {
        "userid": query[0],
        "username": query[1],
        "config": query[2],
        "profile_text": query[3],
        "catchphrase": query[4],
        "user_media": media.get_user_media(query[0]),
        "staff_notes": shout.count(query[0], staffnotes=True),
    }