Fixes for authenticated discord user check and other small fixes

This commit is contained in:
Jeremy Zhang 2017-04-05 18:43:59 +00:00
parent f5d53dd89a
commit 13e9649c10
3 changed files with 16 additions and 13 deletions

View File

@ -93,7 +93,8 @@ def check_user_in_guild(guild_id):
if user_unauthenticated(): if user_unauthenticated():
return guild_id in session['user_keys'] return guild_id in session['user_keys']
else: else:
return 200 == discord_api.get_guild_member_nocache(guild_id, session['user_id'])['code'] dbUser = db.session.query(AuthenticatedUsers).filter(and_(AuthenticatedUsers.guild_id == guild_id, AuthenticatedUsers.client_id == session['user_id'])).first()
return 200 == discord_api.get_guild_member_nocache(guild_id, session['user_id'])['code'] and dbUser is not None
def format_post_content(message): def format_post_content(message):
if (session['unauthenticated']): if (session['unauthenticated']):

View File

@ -204,12 +204,14 @@ function _wait_for_discord_login(index) {
} }
function select_channel(channel_id) { function select_channel(channel_id) {
selected_channel = channel_id; if (selected_channel != channel_id) {
last_message_id = null; selected_channel = channel_id;
$("#channels-list > li.active").removeClass("active"); last_message_id = null;
$("#channel-"+selected_channel).parent().addClass("active"); $("#channels-list > li.active").removeClass("active");
clearTimeout(fetchtimeout); $("#channel-"+selected_channel).parent().addClass("active");
run_fetch_routine(); clearTimeout(fetchtimeout);
run_fetch_routine();
}
} }
function replace_message_mentions(message) { function replace_message_mentions(message) {
@ -332,8 +334,11 @@ $("#custom_username_field").keyup(function(event){
}); });
$("#messagebox").keyup(function(event){ $("#messagebox").keyup(function(event){
$(this).val($.trim($(this).val())); if ($(this).val().length == 1) {
$(this).val($.trim($(this).val()));
}
if(event.keyCode == 13 && $(this).val().length >= 1 && $(this).val().length <= 350) { if(event.keyCode == 13 && $(this).val().length >= 1 && $(this).val().length <= 350) {
$(this).val($.trim($(this).val()));
$(this).blur(); $(this).blur();
var funct = post(selected_channel, $(this).val()); var funct = post(selected_channel, $(this).val());
funct.done(function(data) { funct.done(function(data) {

View File

@ -56,11 +56,8 @@ def check_guild_existance(guild_id):
dbGuild = Guilds.query.filter_by(guild_id=guild_id).first() dbGuild = Guilds.query.filter_by(guild_id=guild_id).first()
if not dbGuild: if not dbGuild:
return False return False
guilds = discord_api.get_all_guilds() guild = discord_api.get_guild(guild_id)
for guild in guilds: return guild['code'] == 200
if guild_id == guild['id']:
return True
return False
def guild_query_unauth_users_bool(guild_id): def guild_query_unauth_users_bool(guild_id):
dbGuild = db.session.query(Guilds).filter(Guilds.guild_id==guild_id).first() dbGuild = db.session.query(Guilds).filter(Guilds.guild_id==guild_id).first()