diff --git a/discordbot/titanembeds/database/guilds.py b/discordbot/titanembeds/database/guilds.py
index a73ccb0..54dfe69 100644
--- a/discordbot/titanembeds/database/guilds.py
+++ b/discordbot/titanembeds/database/guilds.py
@@ -6,6 +6,7 @@ class Guilds(Base):
guild_id = db.Column(db.String(255)) # Discord guild id
name = db.Column(db.String(255)) # Name
unauth_users = db.Column(db.Boolean()) # If allowed unauth users
+ visitor_view = db.Column(db.Boolean()) # If users are automatically "signed in" and can view chat
chat_links = db.Column(db.Boolean()) # If users can post links
bracket_links = db.Column(db.Boolean()) # If appending brackets to links to prevent embed
mentions_limit = db.Column(db.Integer) # If there is a limit on the number of mentions in a msg
@@ -20,6 +21,7 @@ class Guilds(Base):
self.guild_id = guild_id
self.name = name
self.unauth_users = True # defaults to true
+ self.visitor_view = False
self.chat_links = True
self.bracket_links = True
self.mentions_limit = -1 # -1 = unlimited mentions
diff --git a/webapp/alembic/versions/b1124468bb2e_added_visitor_view_column_to_guilds_.py b/webapp/alembic/versions/b1124468bb2e_added_visitor_view_column_to_guilds_.py
new file mode 100644
index 0000000..f0f4d69
--- /dev/null
+++ b/webapp/alembic/versions/b1124468bb2e_added_visitor_view_column_to_guilds_.py
@@ -0,0 +1,28 @@
+"""Added visitor view column to guilds table
+
+Revision ID: b1124468bb2e
+Revises: 95ab6a63135d
+Create Date: 2017-06-08 06:31:28.953304
+
+"""
+
+# revision identifiers, used by Alembic.
+revision = 'b1124468bb2e'
+down_revision = '95ab6a63135d'
+branch_labels = None
+depends_on = None
+
+from alembic import op
+import sqlalchemy as sa
+
+
+def upgrade():
+ # ### commands auto generated by Alembic - please adjust! ###
+ op.add_column('guilds', sa.Column('visitor_view', sa.Boolean(), nullable=False))
+ # ### end Alembic commands ###
+
+
+def downgrade():
+ # ### commands auto generated by Alembic - please adjust! ###
+ op.drop_column('guilds', 'visitor_view')
+ # ### end Alembic commands ###
diff --git a/webapp/titanembeds/blueprints/api/api.py b/webapp/titanembeds/blueprints/api/api.py
index 847a613..4ba5aba 100644
--- a/webapp/titanembeds/blueprints/api/api.py
+++ b/webapp/titanembeds/blueprints/api/api.py
@@ -1,6 +1,6 @@
from titanembeds.database import db, Guilds, UnauthenticatedUsers, UnauthenticatedBans, AuthenticatedUsers, KeyValueProperties, GuildMembers, Messages, get_channel_messages, list_all_guild_members
from titanembeds.decorators import valid_session_required, discord_users_only
-from titanembeds.utils import check_guild_existance, guild_query_unauth_users_bool, get_client_ipaddr, discord_api, rate_limiter, channel_ratelimit_key, guild_ratelimit_key
+from titanembeds.utils import check_guild_existance, guild_accepts_visitors, guild_query_unauth_users_bool, get_client_ipaddr, discord_api, rate_limiter, channel_ratelimit_key, guild_ratelimit_key
from titanembeds.oauth import user_has_permission, generate_avatar_url, check_user_can_administrate_guild
from flask import Blueprint, abort, jsonify, session, request
from sqlalchemy import and_
@@ -162,8 +162,8 @@ def get_dbguild_channels(guild_id):
q = db.session.query(Guilds).filter(Guilds.guild_id == guild_id).first()
return json.loads(q.channels)
-def get_guild_channels(guild_id):
- if user_unauthenticated():
+def get_guild_channels(guild_id, force_everyone=False):
+ if user_unauthenticated() or force_everyone:
member_roles = [guild_id] #equivilant to @everyone role
else:
member_roles = get_member_roles(guild_id, session['user_id'])
@@ -177,7 +177,7 @@ def get_guild_channels(guild_id):
for channel in guild_channels:
if channel['type'] == "text":
result = {"channel": channel, "read": False, "write": False, "mention_everyone": False}
- if guild_owner == session['user_id']:
+ if guild_owner == session.get("user_id"):
result["read"] = True
result["write"] = True
result["mention_everyone"] = True
@@ -219,7 +219,7 @@ def get_guild_channels(guild_id):
# member specific
for overwrite in channel["permission_overwrites"]:
- if overwrite["type"] == "member" and overwrite["id"] == session["user_id"]:
+ if overwrite["type"] == "member" and overwrite["id"] == session.get("user_id"):
channel_perm = (channel_perm & ~overwrite['deny']) | overwrite['allow']
break
@@ -240,8 +240,8 @@ def get_guild_channels(guild_id):
result_channels.append(result)
return sorted(result_channels, key=lambda k: k['channel']['position'])
-def filter_guild_channel(guild_id, channel_id):
- channels = get_guild_channels(guild_id)
+def filter_guild_channel(guild_id, channel_id, force_everyone=False):
+ channels = get_guild_channels(guild_id, force_everyone)
for chan in channels:
if chan["channel"]["id"] == channel_id:
return chan
@@ -327,6 +327,25 @@ def fetch():
response.status_code = status_code
return response
+@api.route("/fetch_visitor", methods=["GET"])
+@rate_limiter.limit("2 per 2 second", key_func = channel_ratelimit_key)
+def fetch_visitor():
+ guild_id = request.args.get("guild_id")
+ channel_id = request.args.get('channel_id')
+ after_snowflake = request.args.get('after', None, type=int)
+ if not guild_accepts_visitors(guild_id):
+ abort(403)
+ messages = {}
+ chan = filter_guild_channel(guild_id, channel_id, True)
+ if not chan.get("read"):
+ status_code = 401
+ else:
+ messages = get_channel_messages(channel_id, after_snowflake)
+ status_code = 200
+ response = jsonify(messages=messages)
+ response.status_code = status_code
+ return response
+
@api.route("/post", methods=["POST"])
@valid_session_required(api=True)
@rate_limiter.limit("1 per 10 second", key_func = channel_ratelimit_key)
@@ -393,21 +412,36 @@ def create_unauthenticated_user():
response.status_code = 403
return response
+def process_query_guild(guild_id, visitor=False):
+ widget = discord_api.get_widget(guild_id)
+ channels = get_guild_channels(guild_id, visitor)
+ discordmembers = get_online_discord_users(guild_id, widget)
+ embedmembers = get_online_embed_users(guild_id)
+ emojis = get_guild_emojis(guild_id)
+ if visitor:
+ for channel in channels:
+ channel["write"] = False
+ return jsonify(channels=channels, discordmembers=discordmembers, embedmembers=embedmembers, emojis=emojis, instant_invite=widget.get("instant_invite"))
+
@api.route("/query_guild", methods=["GET"])
@valid_session_required(api=True)
def query_guild():
guild_id = request.args.get('guild_id')
if check_guild_existance(guild_id):
if check_user_in_guild(guild_id):
- widget = discord_api.get_widget(guild_id)
- channels = get_guild_channels(guild_id)
- discordmembers = get_online_discord_users(guild_id, widget)
- embedmembers = get_online_embed_users(guild_id)
- emojis = get_guild_emojis(guild_id)
- return jsonify(channels=channels, discordmembers=discordmembers, embedmembers=embedmembers, emojis=emojis, instant_invite=widget.get("instant_invite"))
+ return process_query_guild(guild_id)
abort(403)
abort(404)
+@api.route("/query_guild_visitor", methods=["GET"])
+def query_guild_visitor():
+ guild_id = request.args.get('guild_id')
+ if check_guild_existance(guild_id):
+ if not guild_accepts_visitors(guild_id):
+ abort(403)
+ return process_query_guild(guild_id, True)
+ abort(404)
+
@api.route("/create_authenticated_user", methods=["POST"])
@discord_users_only(api=True)
def create_authenticated_user():
diff --git a/webapp/titanembeds/blueprints/embed/embed.py b/webapp/titanembeds/blueprints/embed/embed.py
index 8d3f2dd..12560d2 100644
--- a/webapp/titanembeds/blueprints/embed/embed.py
+++ b/webapp/titanembeds/blueprints/embed/embed.py
@@ -1,5 +1,5 @@
from flask import Blueprint, render_template, abort, redirect, url_for, session, request
-from titanembeds.utils import check_guild_existance, guild_query_unauth_users_bool
+from titanembeds.utils import check_guild_existance, guild_query_unauth_users_bool, guild_accepts_visitors
from titanembeds.oauth import generate_guild_icon_url, generate_avatar_url
from titanembeds.database import db, Guilds, UserCSS
from config import config
@@ -42,6 +42,7 @@ def guild_embed(guild_id):
guild_id=guild_id, guild=guild_dict,
generate_guild_icon=generate_guild_icon_url,
unauth_enabled=guild_query_unauth_users_bool(guild_id),
+ visitors_enabled=guild_accepts_visitors(guild_id),
client_id=config['client-id'],
css=get_custom_css()
)
diff --git a/webapp/titanembeds/blueprints/user/user.py b/webapp/titanembeds/blueprints/user/user.py
index 558a3bb..21ed408 100644
--- a/webapp/titanembeds/blueprints/user/user.py
+++ b/webapp/titanembeds/blueprints/user/user.py
@@ -175,6 +175,7 @@ def administrate_guild(guild_id):
"id": db_guild.guild_id,
"name": db_guild.name,
"unauth_users": db_guild.unauth_users,
+ "visitor_view": db_guild.visitor_view,
"chat_links": db_guild.chat_links,
"bracket_links": db_guild.bracket_links,
"mentions_limit": db_guild.mentions_limit,
@@ -192,6 +193,7 @@ def update_administrate_guild(guild_id):
if not db_guild:
abort(400)
db_guild.unauth_users = request.form.get("unauth_users", db_guild.unauth_users) in ["true", True]
+ db_guild.visitor_view = request.form.get("visitor_view", db_guild.visitor_view) in ["true", True]
db_guild.chat_links = request.form.get("chat_links", db_guild.chat_links) in ["true", True]
db_guild.bracket_links = request.form.get("bracket_links", db_guild.bracket_links) in ["true", True]
db_guild.mentions_limit = request.form.get("mentions_limit", db_guild.mentions_limit)
diff --git a/webapp/titanembeds/database/guilds.py b/webapp/titanembeds/database/guilds.py
index 934bf6a..db086e9 100644
--- a/webapp/titanembeds/database/guilds.py
+++ b/webapp/titanembeds/database/guilds.py
@@ -6,6 +6,7 @@ class Guilds(db.Model):
guild_id = db.Column(db.String(255), nullable=False) # Discord guild id
name = db.Column(db.String(255), nullable=False) # Name
unauth_users = db.Column(db.Boolean(), nullable=False, default=1) # If allowed unauth users
+ visitor_view = db.Column(db.Boolean(), nullable=False, default=0) # If users are automatically "signed in" and can view chat
chat_links = db.Column(db.Boolean(), nullable=False, default=1) # If users can post links
bracket_links = db.Column(db.Boolean(), nullable=False, default=1) # If appending brackets to links to prevent embed
mentions_limit = db.Column(db.Integer, nullable=False, default=11) # If there is a limit on the number of mentions in a msg
@@ -20,6 +21,7 @@ class Guilds(db.Model):
self.guild_id = guild_id
self.name = name
self.unauth_users = True # defaults to true
+ self.visitor_view = False
self.chat_links = True
self.bracket_links = True
self.mentions_limit = -1 # -1 = unlimited mentions
diff --git a/webapp/titanembeds/static/css/embedstyle.css b/webapp/titanembeds/static/css/embedstyle.css
index 85d2382..21ede8a 100644
--- a/webapp/titanembeds/static/css/embedstyle.css
+++ b/webapp/titanembeds/static/css/embedstyle.css
@@ -233,6 +233,14 @@ a {
#nameplate {
cursor: pointer;
}
+
+#visitor_mode_message {
+ margin-right: auto;
+ margin-left: auto;
+ display: block;
+ width: 305px;
+}
+
@font-face {
font-family: Whitney;
font-style: light;
@@ -261,53 +269,79 @@ a {
src: url("../fonts/whitney_bold.woff") format("woff")
}
* {
-font-family: Whitney, Helvetica Neue, Helvetica, Arial, sans-serif;
+ font-family: Whitney, Helvetica Neue, Helvetica, Arial, sans-serif;
}
#footercontainer {
-border-radius:20px;
-border: 1px solid rgb(99,99,99);
-margin-left:-0px!important;
-padding-left:-4px!important;
+ border-radius: 20px;
+ border: 1px solid rgb(99, 99, 99);
+ margin-left: -0px!important;
+ padding-left: -4px!important;
}
#nameplate {
-background:transparent!important;
-margin-left:10px
+ background: transparent!important;
+ margin-left: 10px
}
#chatcontent > p > span.chatusername,
#curuser_discrim,
#curuser_name {
-display:block
+ display: block
}
#curuser_discrim {
-font-size:50%;
+ font-size: 50%;
}
#curuser_discrim,
#curuser_name {
-margin-top:-2px
+ margin-top: -2px
}
#currentuserimage {
-margin-top:4px;
-margin-right:4px
+ margin-top: 4px;
+ margin-right: 4px
+}
+#chatcontent > p {
+ display: table;
+}
+#chatcontent > p > span {
+ display: table-row
+}
+#chatcontent > p > span.chatusername {
+ display: table-header-group
+}
+#chatcontent > p > span.chatmessage {
+ display: table-footer-group;
+ display: inline-block!important;
+ color: rgb(195, 196, 197)
+}
+::-webkit-input-placeholder {
+ color: rgb(99, 99, 99)
+}
+:-moz-placeholder {
+ color: rgb(99, 99, 99)
+}
+::-moz-placeholder {
+ color: rgb(99, 99, 99)
+}
+:-ms-input-placeholder {
+ color: rgb(99, 99, 99)
+}
+::-ms-input-placeholder {
+ color: rgb(99, 99, 99)
}
-#chatcontent > p { display: table; }
-#chatcontent > p > span { display: table-row }
-#chatcontent > p > span.chatusername { display: table-header-group }
-#chatcontent > p > span.chatmessage { display: table-footer-group;display:inline-block!important;color:rgb(195,196,197) }
-::-webkit-input-placeholder { color:rgb(99,99,99) }
-:-moz-placeholder { color:rgb(99,99,99) }
-::-moz-placeholder { color:rgb(99,99,99) }
-:-ms-input-placeholder { color:rgb(99,99,99) }
-::-ms-input-placeholder { color:rgb(99,99,99) }
body > div.navbar-fixed > nav > div {
-background:#263238
- background: -webkit-linear-gradient(#263238, #37474f, #455a64); /* For Safari 5.1 to 6.0 */
- background: -o-linear-gradient(#263238, #37474f, #455a64); /* For Opera 11.1 to 12.0 */
- background: -moz-linear-gradient(#263238, #37474f, #455a64); /* For Firefox 3.6 to 15 */
- background: linear-gradient(#263238, #37474f, #455a64); /* Standard syntax */
+ background: #263238 background: -webkit-linear-gradient(#263238, #37474f, #455a64);
+ /* For Safari 5.1 to 6.0 */
+
+ background: -o-linear-gradient(#263238, #37474f, #455a64);
+ /* For Opera 11.1 to 12.0 */
+
+ background: -moz-linear-gradient(#263238, #37474f, #455a64);
+ /* For Firefox 3.6 to 15 */
+
+ background: linear-gradient(#263238, #37474f, #455a64);
+ /* Standard syntax */
}
div.divider {
-margin-left:10px;
-margin-right:10px;
+ margin-left: 10px;
+ margin-right: 10px;
}
#discord-members > li > a.subheader,
#members-nav > li:nth-child(1) > a,
@@ -316,21 +350,21 @@ margin-right:10px;
#members-nav > li:nth-child(4) > a,
#guest-members-count,
#members-nav > li:nth-child(6) > a {
-text-transform: uppercase;
+ text-transform: uppercase;
+}
+#members-btn > i {
+ visibility: hidden
}
-#members-btn > i { visibility:hidden }
#members-btn {
-visibility:visible;
-background-image:url(data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHdpZHRoPSIyNiIgaGVpZ2h0PSIyNiI+CiAgPGcgZmlsbD0ibm9uZSIgZmlsbC1ydWxlPSJldmVub2RkIj4KICAgIDxwYXRoIGQ9Ik0xIDFoMjR2MjRIMVYxeiIvPgogICAgPHBhdGggZmlsbD0iI0ZGRiIgZD0iTTE2Ljc3MjA3NTQgMTQuNjc5MTc3OGMtLjIyNDkwOTctLjIyNTY4ODYtLjQ3NDE1NzMtLjQzNTE2ODEtLjc0MjA3NTQtLjYyOTE3NzguMzUtLjAzLjY4LS4wNS45Ny0uMDUgMi4zMyAwIDcgMS4xNyA3IDMuNVYyMGgtNHYtMWMwLTEuODgxNjkxNC0xLjQwNzcwNTYtMy4zMjMwMTQzLTMuMjI3OTI0Ni00LjMyMDgyMjJ6bS0xLjQzODU3MzUtOC4xNzU4NTM0QzE1LjgwOTgwODIgNi4xODUyNTE3MyAxNi4zODI3ODQ1IDYgMTcgNmMxLjY2IDAgMi45OSAxLjM0IDIuOTkgM3MtMS4zMyAzLTIuOTkgM2MtLjYxNzE5MTQgMC0xLjE5MDE0NzEtLjE4NTIzNzMtMS42NjY0NDIzLS41MDMyODcyQzE1Ljc1NzQ4MzIgMTAuNzYyMTQwOTUgMTYgOS45MDk1NTYgMTYgOS4wMDAwNjY5M2MwLS45MDk1Mjg5Ni0uMjQyNTM4MS0xLjc2MjE0ODgtLjY2NjQ5ODEtMi40OTY3NDI1M3pNMTAgMTNjMi4yMSAwIDQtMS43OSA0LTRzLTEuNzktNC00LTQtNCAxLjc5LTQgNCAxLjc5IDQgNCA0em0wIDJjLTIuNjcgMC04IDEuMzQtOCA0djJoMTZ2LTJjMC0yLjY2LTUuMzMtNC04LTR6Ii8+CiAgPC9nPgo8L3N2Zz4=);
-background-repeat:no-repeat;
-margin-top:18px
+ visibility: visible;
+ background-image: url(data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHdpZHRoPSIyNiIgaGVpZ2h0PSIyNiI+CiAgPGcgZmlsbD0ibm9uZSIgZmlsbC1ydWxlPSJldmVub2RkIj4KICAgIDxwYXRoIGQ9Ik0xIDFoMjR2MjRIMVYxeiIvPgogICAgPHBhdGggZmlsbD0iI0ZGRiIgZD0iTTE2Ljc3MjA3NTQgMTQuNjc5MTc3OGMtLjIyNDkwOTctLjIyNTY4ODYtLjQ3NDE1NzMtLjQzNTE2ODEtLjc0MjA3NTQtLjYyOTE3NzguMzUtLjAzLjY4LS4wNS45Ny0uMDUgMi4zMyAwIDcgMS4xNyA3IDMuNVYyMGgtNHYtMWMwLTEuODgxNjkxNC0xLjQwNzcwNTYtMy4zMjMwMTQzLTMuMjI3OTI0Ni00LjMyMDgyMjJ6bS0xLjQzODU3MzUtOC4xNzU4NTM0QzE1LjgwOTgwODIgNi4xODUyNTE3MyAxNi4zODI3ODQ1IDYgMTcgNmMxLjY2IDAgMi45OSAxLjM0IDIuOTkgM3MtMS4zMyAzLTIuOTkgM2MtLjYxNzE5MTQgMC0xLjE5MDE0NzEtLjE4NTIzNzMtMS42NjY0NDIzLS41MDMyODcyQzE1Ljc1NzQ4MzIgMTAuNzYyMTQwOTUgMTYgOS45MDk1NTYgMTYgOS4wMDAwNjY5M2MwLS45MDk1Mjg5Ni0uMjQyNTM4MS0xLjc2MjE0ODgtLjY2NjQ5ODEtMi40OTY3NDI1M3pNMTAgMTNjMi4yMSAwIDQtMS43OSA0LTRzLTEuNzktNC00LTQtNCAxLjc5LTQgNCAxLjc5IDQgNCA0em0wIDJjLTIuNjcgMC04IDEuMzQtOCA0djJoMTZ2LTJjMC0yLjY2LTUuMzMtNC04LTR6Ii8+CiAgPC9nPgo8L3N2Zz4=);
+ background-repeat: no-repeat;
+ margin-top: 18px
}
.circle:hover {
-border-radius:20px;
-background: linear-gradient(to right, #f9f9f9 90%, #fff);
+ border-radius: 20px;
+ background: linear-gradient(to right, #f9f9f9 90%, #fff);
}
#channels-list > li:hover {
--webkit-filter: brightness(150%);
-}
-#loginmodal {
-}
+ -webkit-filter: brightness(150%);
+}
\ No newline at end of file
diff --git a/webapp/titanembeds/static/js/administrate_guild.js b/webapp/titanembeds/static/js/administrate_guild.js
index d689ceb..78c3b1b 100644
--- a/webapp/titanembeds/static/js/administrate_guild.js
+++ b/webapp/titanembeds/static/js/administrate_guild.js
@@ -7,6 +7,15 @@ $('#unauth_users').change(function() {
});
});
+$('#visitor_view').change(function() {
+ var pathname = window.location.pathname;
+ var checked = $(this).is(':checked')
+ var payload = {"visitor_view": checked}
+ $.post(pathname, payload, function(data) {
+ Materialize.toast('Updated visitor mode setting!', 2000)
+ });
+});
+
$('#chat_links').change(function() {
var pathname = window.location.pathname;
var checked = $(this).is(':checked')
diff --git a/webapp/titanembeds/static/js/embed.js b/webapp/titanembeds/static/js/embed.js
index 47cf570..8b07f20 100644
--- a/webapp/titanembeds/static/js/embed.js
+++ b/webapp/titanembeds/static/js/embed.js
@@ -5,6 +5,7 @@
/* global bot_client_id */
/* global moment */
/* global localStorage */
+/* global visitors_enabled */
(function () {
const theme_options = ["DiscordDark", "BetterTitan"]; // All the avaliable theming names
@@ -21,6 +22,7 @@
var fetch_error_count = 0; // Number of errors fetch has encountered
var priority_query_guild = false; // So you have selected a channel? Let's populate it.
var current_username_discrim; // Current username/discrim pair, eg EndenDraogn#4151
+ var visitor_mode = false; // Keep track of if using the visitor mode or authenticate mode
function element_in_view(element, fullyInView) {
var pageTop = $(window).scrollTop();
@@ -36,9 +38,13 @@
}
function query_guild() {
+ var url = "/api/query_guild";
+ if (visitor_mode) {
+ url = url += "_visitor";
+ }
var funct = $.ajax({
dataType: "json",
- url: "/api/query_guild",
+ url: url,
data: {"guild_id": guild_id}
});
return funct.promise();
@@ -65,10 +71,14 @@
}
function fetch(channel_id, after=null) {
+ var url = "/api/fetch";
+ if (visitor_mode) {
+ url += "_visitor";
+ }
var funct = $.ajax({
method: "GET",
dataType: "json",
- url: "/api/fetch",
+ url: url,
data: {"guild_id": guild_id,"channel_id": channel_id, "after": after}
});
return funct.promise();
@@ -118,6 +128,10 @@
$("#userembedmodal").modal("open");
});
+ $("#visitor_login_btn").click(function () {
+ $("#loginmodal").modal("open");
+ });
+
$( "#theme-selector" ).change(function() {
var theme = $("#theme-selector option:selected").val();
changeTheme(theme);
@@ -171,6 +185,20 @@
if (!results[2]) return '';
return decodeURIComponent(results[2].replace(/\+/g, " "));
}
+
+ function setVisitorMode(enabled) {
+ if (!visitors_enabled) {
+ return;
+ }
+ visitor_mode = enabled;
+ if (visitor_mode) {
+ $("#visitor_mode_message").show();
+ $("#messagebox").hide();
+ } else {
+ $("#visitor_mode_message").hide();
+ $("#messagebox").show();
+ }
+ }
function primeEmbed() {
$("#focusmodal").modal("close");
@@ -181,8 +209,10 @@
$("#modal_invite_btn").attr("href", data.instant_invite);
});
+ var login_modal_dismissible = visitors_enabled;
+
$("#loginmodal").modal({
- dismissible: false, // Modal can be dismissed by clicking outside of the modal
+ dismissible: login_modal_dismissible, // Modal can be dismissed by clicking outside of the modal
opacity: .5, // Opacity of modal background
inDuration: 300, // Transition in duration
outDuration: 200, // Transition out duration
@@ -196,6 +226,16 @@
var guild = query_guild();
guild.fail(function() {
unlock_login_fields();
+ if (visitors_enabled) {
+ setVisitorMode(true);
+ var guild2 = query_guild();
+ guild2.done(function(data) {
+ initialize_embed(data);
+ });
+ guild2.fail(function() {
+ setVisitorMode(false);
+ });
+ }
});
guild.done(function(data) {
@@ -375,12 +415,14 @@
setTimeout(function() {
var usr = create_authenticated_user();
usr.done(function(data) {
+ setVisitorMode(false);
initialize_embed();
return;
});
usr.fail(function(data) {
if (data.status == 403) {
Materialize.toast('Authentication error! You have been banned.', 10000);
+ setVisitorMode(true);
} else if (index < 10) {
_wait_for_discord_login(index + 1);
}
@@ -524,9 +566,13 @@
}
fet.done(function(data) {
var status = data.status;
- update_embed_userchip(status.authenticated, status.avatar, status.username, status.user_id, status.discriminator);
+ if (visitor_mode) {
+ update_embed_userchip(false, null, "Titan", "0001", null);
+ } else {
+ update_embed_userchip(status.authenticated, status.avatar, status.username, status.user_id, status.discriminator);
+ }
last_message_id = fill_discord_messages(data.messages, jumpscroll);
- if (status.manage_embed) {
+ if (!visitor_mode && status.manage_embed) {
$("#administrate_link").show();
} else {
$("#administrate_link").hide();
@@ -554,6 +600,10 @@
$('#loginmodal').modal('open');
Materialize.toast('Session expired! You have been logged out.', 10000);
}
+ setVisitorMode(true);
+ if (visitor_mode) {
+ fetchtimeout = setTimeout(run_fetch_routine, 5000);
+ }
});
fet.catch(function(data) {
if (500 <= data.status && data.status < 600) {
@@ -600,6 +650,7 @@
lock_login_fields();
var usr = create_unauthenticated_user($(this).val());
usr.done(function(data) {
+ setVisitorMode(false);
initialize_embed();
});
usr.fail(function(data) {
@@ -611,6 +662,7 @@
Materialize.toast('Illegal username provided! Only alphanumeric, spaces, dashes, and underscores allowed in usernames.', 10000);
}
unlock_login_fields();
+ setVisitorMode(true);
});
}
}
diff --git a/webapp/titanembeds/templates/administrate_guild.html.j2 b/webapp/titanembeds/templates/administrate_guild.html.j2
index 438a08d..bdc2868 100644
--- a/webapp/titanembeds/templates/administrate_guild.html.j2
+++ b/webapp/titanembeds/templates/administrate_guild.html.j2
@@ -48,6 +48,19 @@
Enable
+
+
+
+
Toggle Visitor Mode
+Visitors are able to view the channels that @everyone has access to. However, they are not able to send messages until they login using the usual methods.
+