Permalink
Browse files

Discord auth for tournaments

  • Loading branch information...
Manuel-777 committed Jan 7, 2019
1 parent 544f812 commit 6b0eff1d9f0cd859356f8f6acfb8bcc61ab2a5ed
Binary file not shown.
@@ -95,6 +95,8 @@ function httpBasic() {
if (parsedResult.ok) {
if (_headers.method == 'auth') {
tokenAuth = parsedResult.token;

ipc_send('set_discord_tag', parsedResult.discord_tag);
//ipc_send("auth", parsedResult.arenaids);
if (rememberMe) {
rstore.set("token", tokenAuth);
@@ -111,9 +113,19 @@ function httpBasic() {
}
if (_headers.method == 'heartbeat') {
parsedResult.notifications.forEach((str) => {
let notif = new Notification('MTG Arena Tool', {
body: str
})
console.log("typeof:", typeof str);
if (typeof str == "string") {
console.log("Notification string:", str);
let notif = new Notification('MTG Arena Tool', {
body: str
})
}
else if (typeof str == "object") {
console.log("Notification object:", str);
if (str.task) {
ipc_send(str.task, str.value);
}
}
});
}
if (_headers.method == 'tou_join' || _headers.method == 'tou_drop') {
@@ -2246,6 +2246,50 @@ a:hover {
-webkit-transition: all .25s cubic-bezier(0.2, 0.5, 0.35, 1);
}

.auth_label {
width: 100%;
margin-top: 32px;
margin-bottom: 20px;
color: #FAE5D2;
font-size: 20px;
text-align: center;
}

.discord_icon {
background-image:url(../images/discord_logo.png);
width: 32px;
background-size: cover;
height: 32px;
}

.discord_message {
margin-left: 32px;
margin-top: 10px;
line-height: 16px;
font-style: italic;
opacity: 0.8;
color: #fae5d2;
}

.discord_but {
position: relative;
cursor: pointer;
margin: 0 auto;
width: 210px;
border-radius: 4px;
height: 40px;
background-size: 120px;
background-color: #7289DA;
background-position: center;
background-repeat: no-repeat;
background-image: url(../images/discord_button.png);
-webkit-transition: all .25s cubic-bezier(0.2, 0.5, 0.35, 1);
}

.discord_but:hover {
background-color: #4e5d94;
}

.tournament_list_cont {
margin: 16px;
overflow: auto;
@@ -2318,12 +2362,12 @@ a:hover {
display: flex;
font-size: 18px;
text-align: center;
margin: 16px auto 4px auto;
margin-bottom: 6px;
}

.tou_opp_sub {
font-size: 16px;
margin: 0px 0px 12px 0px;
margin-bottom: 16px;
}

.copy_button {
@@ -2485,8 +2529,8 @@ a:hover {

.tournament_title {
color: rgba(250, 229, 210, 0.85);
margin-left: 30px;
margin-top: 8px;
text-align: center;
margin-top: 16px;
font-family: Beleren;
font-size: 18px;
}
@@ -91,6 +91,8 @@ let season_starts = new Date();
let season_ends = new Date();

let tags_colors = {};
let authToken = null;
let discordTag = null;

const sha1 = require('js-sha1');
const fs = require("fs");
@@ -134,6 +136,7 @@ ipc.on('clear_pwd', function () {

//
ipc.on('auth', function (event, arg) {
authToken = arg.token;
if (arg.ok) {
$('.message_center').css('display', 'flex');
$('.authenticate').hide();
@@ -144,6 +147,13 @@ ipc.on('auth', function (event, arg) {
}
});

ipc.on('set_discord_tag', (event, arg) => {
discordTag = arg;
if (sidebarActive == -1) {
ipc_send('request_tou_list', true);
}
});

//
ipc.on('too_slow', function () {
pop('Loading is taking too long, please read our <a class="trouble_link">troubleshooting guide</a>.', 0);
@@ -516,7 +526,7 @@ ipc.on('initialize', function () {

$(".top_rank").css("background-position", (rankOffset*-48)+"px 0px").attr("title", rankTitle);
sidebarActive = 0;//-1;
ipc_send('request_tou_list', true);
//ipc_send('request_tou_list', true);
$('.top_nav').removeClass('hidden');
$('.overflow_ux').removeClass('hidden');
$('.message_center').css('display', 'none');
@@ -742,7 +752,13 @@ $(document).ready(function() {
if ($(this).hasClass("ith")) {
sidebarActive = -1;
$("#ux_0").html('<div class="loading_bar ux_loading"><div class="loading_color loading_w"></div><div class="loading_color loading_u"></div><div class="loading_color loading_b"></div><div class="loading_color loading_r"></div><div class="loading_color loading_g"></div></div>');
ipc_send('request_tou_list', true);

if (discordTag == null) {
open_tournaments_tab(null, true);
}
else {
ipc_send('request_tou_list', true);
}
}
if ($(this).hasClass("it0")) {
sidebarActive = 0;
@@ -11,6 +11,9 @@ global
addCardTile,
get_deck_export,
makeId,
authToken,
discordTag,
shell,
pop
*/

@@ -23,25 +26,47 @@ let listInterval = [];

// Should separate these two into smaller functions
function open_tournaments_tab(arg, opentab = true) {
let mainDiv = document.getElementById("ux_0");
mainDiv.classList.remove("flex_item");
mainDiv.innerHTML = '';

if (discordTag == null) {
let label = $('<div class="auth_label">Authorize to proceed:</div>');
let but = $('<div class="discord_but"></div>');

but.click(() => {
let url = 'https://discordapp.com/api/oauth2/authorize?client_id=531626302004789280&redirect_uri=http%3A%2F%2Fmtgatool.com%2Fdiscord%2F&response_type=code&scope=identify%20email&state='+authToken;
shell.openExternal(url);
});

label.appendTo(mainDiv);
but.appendTo(mainDiv);

return false;
}
if (arg != null) {
tournaments_list = arg;
if (!opentab) return
}

let mainDiv = document.getElementById("ux_0");
mainDiv.classList.remove("flex_item");
mainDiv.innerHTML = '';

let d = document.createElement("div");
d.classList.add("list_fill");
mainDiv.appendChild(d);

let fl = document.createElement("div");
fl.classList.add("flex_item");
fl.style.margin = "auto";
fl.style.width = "fit-content";
let dname = discordTag.split("#")[0];
fl.innerHTML = `<div class="discord_icon"></div><div class="top_username">${dname}</div><div class="discord_message">Your discord tag will be visible to your opponents.</div>`;
mainDiv.appendChild(fl);

let title = document.createElement("div");
title.classList.add("tournament_title");
title.innerHTML = "Tournaments List:";
mainDiv.appendChild(title);

cont = document.createElement("div");
let cont = document.createElement("div");
cont.classList.add("tournament_list_cont");

listInterval.forEach((_id) => {
@@ -261,7 +286,8 @@ function open_tournament(t) {
else {
if (joined) {
$(`<div class="tou_record green">${record}</div>`).appendTo(mainDiv);
$(`<div class="tou_opp"><span>Your opponent: </span><span style="margin-left: 10px; color: rgb(250, 229, 210);">${tou.current_opponent}</span><div class="copy_button"></div></div>`).appendTo(mainDiv);
$(`<div class="tou_opp"><span>On MTGA: </span><span style="margin-left: 10px; color: rgb(250, 229, 210);">${tou.current_opponent}</span><div class="copy_button copy_mtga"></div></div>`).appendTo(mainDiv);
$(`<div class="tou_opp"><span>On Discord: </span><span style="margin-left: 10px; color: rgb(250, 229, 210);">${tou.current_opponent_discord}</span><div class="copy_button copy_discord"></div></div>`).appendTo(mainDiv);

$(`<div class="tou_opp tou_opp_sub"><span class="last_seen_clock"></span></div></div>`).appendTo(mainDiv);

@@ -274,10 +300,15 @@ function open_tournament(t) {
}, 250);
}

$('.copy_button').click(() => {
$('.copy_mtga').click(() => {
pop("Copied to clipboard", 1000);
ipc_send('set_clipboard', tou.current_opponent);
});

$('.copy_discord').click(() => {
pop("Copied to clipboard", 1000);
ipc_send('set_clipboard', tou.current_opponent_discord);
});
}

let tabs = $('<div class="tou_tabs_cont"></div>');

0 comments on commit 6b0eff1

Please sign in to comment.