Prevent duplicate ip hashes from showing up the unauth list, Set unauth table to default horizontal

This commit is contained in:
Jeremy Zhang 2017-04-22 23:55:03 -07:00
parent 4899c6d2d9
commit 13b69d7e2d
5 changed files with 113 additions and 5 deletions

View File

@ -4,6 +4,8 @@ from titanembeds.decorators import discord_users_only
from titanembeds.utils import discord_api
from titanembeds.database import db, Guilds, UnauthenticatedUsers, UnauthenticatedBans
from titanembeds.oauth import authorize_url, token_url, make_authenticated_session, get_current_authenticated_user, get_user_managed_servers, check_user_can_administrate_guild, check_user_permission, generate_avatar_url, generate_guild_icon_url, generate_bot_invite_url
import time
import datetime
user = Blueprint("user", __name__)
@ -90,7 +92,6 @@ def administrate_guild(guild_id):
all_members = db.session.query(UnauthenticatedUsers).filter(UnauthenticatedUsers.guild_id == guild_id).order_by(UnauthenticatedUsers.last_timestamp).all()
all_bans = db.session.query(UnauthenticatedBans).filter(UnauthenticatedBans.guild_id == guild_id).all()
users = prepare_guild_members_list(all_members, all_bans)
users.reverse()
dbguild_dict = {"unauth_users": db_guild.unauth_users}
return render_template("administrate_guild.html.j2", guild=guild['content'], dbguild=dbguild_dict, members=users, permissions=permissions)
@ -120,6 +121,8 @@ def me():
def prepare_guild_members_list(members, bans):
all_users = []
ip_pool = []
members = sorted(members, key=lambda k: datetime.datetime.strptime(str(k.last_timestamp), "%Y-%m-%d %H:%M:%S"), reverse=True)
for member in members:
user = {
"id": member.id,
@ -133,6 +136,7 @@ def prepare_guild_members_list(members, bans):
"banned_by": None,
"banned_reason": None,
"ban_lifted_by": None,
"aliases": [],
}
for banned in bans:
if banned.ip_address == member.ip_address:
@ -143,7 +147,16 @@ def prepare_guild_members_list(members, bans):
user['banned_reason'] = banned.reason
user['ban_lifted_by'] = banned.lifter_id
continue
if user["ip"] not in ip_pool:
all_users.append(user)
ip_pool.append(user["ip"])
else:
for usr in all_users:
if user["ip"] == usr["ip"]:
alias = user["username"]+"#"+str(user["discrim"])
if len(usr["aliases"]) < 5 and alias not in usr["aliases"]:
usr["aliases"].append(alias)
continue
return all_users
@user.route("/ban", methods=["POST"])

View File

@ -0,0 +1,77 @@
/* Responsive table CSS, directly from materializecss - slightly modified */
/* Used to accomplish having permanent horizontal table */
table.responsive-table {
width: 100%;
border-collapse: collapse;
border-spacing: 0;
display: block;
position: relative;
table-layout: fixed;
/* sort out borders */
}
table.responsive-table td:empty:before {
content: '\00a0';
}
table.responsive-table th,
table.responsive-table td {
margin: 0;
vertical-align: top;
}
table.responsive-table th {
text-align: left;
}
table.responsive-table thead {
display: block;
float: left;
}
table.responsive-table thead tr {
display: block;
padding: 0 10px 0 0;
}
table.responsive-table thead tr th::before {
content: "\00a0";
}
table.responsive-table tbody {
display: block;
width: auto;
position: relative;
overflow-x: auto;
white-space: nowrap;
}
table.responsive-table tbody tr {
display: inline-block;
vertical-align: top;
}
table.responsive-table th {
display: block;
text-align: right;
}
table.responsive-table td {
display: block;
min-height: 1.25em;
text-align: left;
padding: 13px 5px;
}
table.responsive-table tr {
padding: 0 10px;
}
table.responsive-table thead {
border: 0;
border-right: 1px solid #d0d0d0;
}
table.responsive-table.bordered th {
border-bottom: 0;
border-left: 0;
}
table.responsive-table.bordered td {
border-left: 0;
border-right: 0;
border-bottom: 0;
}
table.responsive-table.bordered tr {
border: 0;
}
table.responsive-table.bordered tbody tr {
border-right: 1px solid #d0d0d0;
}

View File

@ -1,6 +1,10 @@
{% extends 'site_layout.html.j2' %}
{% block title %}Administrate Guild: {{ guild['name'] }}{% endblock %}
{% block additional_head_elements %}
<link type="text/css" rel="stylesheet" href="{{ url_for('static', filename='css/administrate_guild.css') }}">
{% endblock %}
{% block content %}
<h1>Administrating: {{ guild['name'] }}</h1>
<p class="flow-text">For this server, you are allowed the following actions:
@ -72,6 +76,7 @@
<th>Banned by</th>
<th>Banned Reason</th>
<th>Ban Lifted by</th>
<th>Recent Aliases</th>
</tr>
</thead>
<tbody>
@ -91,11 +96,22 @@
<td>{{ member['banned_by'] }}</td>
<td>{{ member['banned_reason'] }}</td>
<td>{{ member['ban_lifted_by'] }}</td>
<td>
<ul>
{% if member['aliases']|length > 0 %}
{% for alias in member['aliases'] %}
<li>{{ alias }}</li>
{% endfor %}
{% else %}
<li>None</li>
{% endif %}
</ul>
</td>
</tr>
{% endfor %}
</tbody>
</table>
<p>Note that all bans are by IP. Seeing duplicates? It is because users are generated a unique session on each browser load.</p>
<p>Note that all bans are by IP. Seeing duplicates? It is because users are generated a unique session on each browser load. (Though we try to remove/concat any duplicates IP hashes)</p>
</div>
</div>

View File

@ -12,6 +12,8 @@
<title>{% block title %}{% endblock %} - Titan Embeds for Discord</title>
{% block additional_head_elements %}{% endblock %}
{% include 'google_analytics.html.j2' %}
</head>
<body>