From f544815d3800729d363396682f8b3bc9f22f45ae Mon Sep 17 00:00:00 2001 From: Francis Veilleux-Gaboury Date: Tue, 28 Jul 2015 20:53:26 -0400 Subject: [PATCH 01/19] extract connection_test.js from main login page --- login/connection_test.js | 88 ++++++++++++++++++++++++++++++++++++ login/login.html | 98 +--------------------------------------- 2 files changed, 90 insertions(+), 96 deletions(-) create mode 100644 login/connection_test.js diff --git a/login/connection_test.js b/login/connection_test.js new file mode 100644 index 0000000..3fc1bb1 --- /dev/null +++ b/login/connection_test.js @@ -0,0 +1,88 @@ +loginInformation = document.login_information; + +loginInformation.elements.test_websocket.addEventListener("click", init); + +var server + , username + , testMessage + , websocketOutput; + +function init() { + + server = document.getElementById("server").value.toString(); + if (server === "other") { + server = document.getElementById("server_other_input").value.toString(); + } + username = document.getElementById("username").value.toString(); + testMessage = document.getElementById("test_message").value.toString(); + if (!testMessage) { + testMessage = '{ "command": "login", "username": "' + username + '" }'; + } + + websocketOutput = document.getElementById("websocket_output"); + + testWebSocket(); +} + +function testWebSocket() { + + // Message to append input values to document prior to printing test results + var wsHeader = document.createElement("h3"); + wsHeader.innerHTML = "Testing WebSocket connection..."; + websocketOutput.appendChild(wsHeader); + + var wsInput = document.createElement("p"); + wsInput.innerHTML = + "Server: " + server + "
" + + "Username: " + username + "
" + + "Message: " + testMessage; + + websocketOutput.appendChild(wsInput); + + // Begin WebSocket test + + websocket = new WebSocket(server); + websocket.onopen = function(evt) { + onOpen(evt) + }; + websocket.onclose = function(evt) { + onClose(evt) + }; + websocket.onmessage = function(evt) { + onMessage(evt) + }; + websocket.onerror = function(evt) { + onError(evt) + }; +} + +function onOpen(evt) { + writeToScreen("CONNECTED"); + doSend(testMessage); +} + +function onClose(evt) { + writeToScreen("DISCONNECTED"); +} + +function onMessage(evt) { + writeToScreen('RESPONSE: ' + evt.data + ''); + websocket.close(); +} + +function onError(evt) { + writeToScreen('ERROR: ' + evt.data); +} + +function doSend(message) { + writeToScreen("SENT: " + message); + websocket.send(message); +} + +function writeToScreen(message) { + + var pre = document.createElement("p"); + pre.style.wordWrap = "break-word"; + pre.innerHTML = message; + websocketOutput.appendChild(pre); +} diff --git a/login/login.html b/login/login.html index b4d73c9..faaf2e1 100644 --- a/login/login.html +++ b/login/login.html @@ -20,7 +20,7 @@

Cardshifter login


- +
@@ -40,102 +40,8 @@

Cardshifter login

- - login_information = document.login_information; - - login_information.elements.test_websocket.addEventListener("click", init); - - //var server = "ws://echo.websocket.org/"; - //var username = document.getElementsByName("username").value.toString(); - - var server - , username - , test_message - , websocket_output; - - function init() { - - server = document.getElementById("server").value.toString(); - if (server === "other") { - server = document.getElementById("server_other").value.toString(); - } - username = document.getElementById("username").value.toString(); - test_message = document.getElementById("test_message").value.toString(); - if (!test_message) { - test_message = '{ "command": "login", "username": "' + username + '" }'; - } - - websocket_output = document.getElementById("websocket_output"); - - testWebSocket(); - } - - function testWebSocket() { - - // Message to append input values to document prior to printing test results - var wsHeader = document.createElement("h3"); - wsHeader.innerHTML = "Testing WebSocket connection..."; - websocket_output.appendChild(wsHeader); - - var wsInput = document.createElement("p"); - wsInput.innerHTML = - "Server: " + server + "
" + - "Username: " + username + "
" + - "Message: " + test_message; - - websocket_output.appendChild(wsInput); - - // Begin WebSocket test - - websocket = new WebSocket(server); - websocket.onopen = function(evt) { - onOpen(evt) - }; - websocket.onclose = function(evt) { - onClose(evt) - }; - websocket.onmessage = function(evt) { - onMessage(evt) - }; - websocket.onerror = function(evt) { - onError(evt) - }; - } - - function onOpen(evt) { - writeToScreen("CONNECTED"); - doSend(test_message); - } - - function onClose(evt) { - writeToScreen("DISCONNECTED"); - } - - function onMessage(evt) { - writeToScreen('RESPONSE: ' + evt.data + ''); - websocket.close(); - } - - function onError(evt) { - writeToScreen('ERROR: ' + evt.data); - } - - function doSend(message) { - writeToScreen("SENT: " + message); - websocket.send(message); - } - - function writeToScreen(message) { - - var pre = document.createElement("p"); - pre.style.wordWrap = "break-word"; - pre.innerHTML = message; - websocket_output.appendChild(pre); - } - -
From 79a1405b6e14f22ac3ce6a9aefa167dbbe3fd64f Mon Sep 17 00:00:00 2001 From: Francis Veilleux-Gaboury Date: Thu, 30 Jul 2015 08:57:05 -0400 Subject: [PATCH 02/19] fix an error in JS testMessage condition --- login/connection_test.js | 82 ++++++++++++++++++++-------------------- 1 file changed, 41 insertions(+), 41 deletions(-) diff --git a/login/connection_test.js b/login/connection_test.js index 3fc1bb1..e60f18d 100644 --- a/login/connection_test.js +++ b/login/connection_test.js @@ -9,51 +9,51 @@ var server function init() { - server = document.getElementById("server").value.toString(); - if (server === "other") { - server = document.getElementById("server_other_input").value.toString(); - } - username = document.getElementById("username").value.toString(); - testMessage = document.getElementById("test_message").value.toString(); - if (!testMessage) { - testMessage = '{ "command": "login", "username": "' + username + '" }'; - } - - websocketOutput = document.getElementById("websocket_output"); - - testWebSocket(); + server = document.getElementById("server").value.toString(); + if (server === "other") { + server = document.getElementById("server_other_input").value.toString(); + } + username = document.getElementById("username").value.toString(); + testMessage = document.getElementById("test_message").value.toString(); + if (!testMessage) { + testMessage = '{ "command": "login", "username": "' + username + '" }'; + } + + websocketOutput = document.getElementById("websocket_output"); + + testWebSocket(); } function testWebSocket() { - // Message to append input values to document prior to printing test results - var wsHeader = document.createElement("h3"); - wsHeader.innerHTML = "Testing WebSocket connection..."; - websocketOutput.appendChild(wsHeader); - - var wsInput = document.createElement("p"); - wsInput.innerHTML = - "Server: " + server + "
" + - "Username: " + username + "
" + - "Message: " + testMessage; - - websocketOutput.appendChild(wsInput); - - // Begin WebSocket test - - websocket = new WebSocket(server); - websocket.onopen = function(evt) { - onOpen(evt) - }; - websocket.onclose = function(evt) { - onClose(evt) - }; - websocket.onmessage = function(evt) { - onMessage(evt) - }; - websocket.onerror = function(evt) { - onError(evt) - }; + // Message to append input values to document prior to printing test results + var wsHeader = document.createElement("h3"); + wsHeader.innerHTML = "Testing WebSocket connection..."; + websocketOutput.appendChild(wsHeader); + + var wsInput = document.createElement("p"); + wsInput.innerHTML = + "Server: " + server + "
" + + "Username: " + username + "
" + + "Message: " + testMessage; + + websocketOutput.appendChild(wsInput); + + // Begin WebSocket test + + websocket = new WebSocket(server); + websocket.onopen = function(evt) { + onOpen(evt) + }; + websocket.onclose = function(evt) { + onClose(evt) + }; + websocket.onmessage = function(evt) { + onMessage(evt) + }; + websocket.onerror = function(evt) { + onError(evt) + }; } function onOpen(evt) { From 442749e39d3507ad4831c02f6ea042b845fb0a03 Mon Sep 17 00:00:00 2001 From: Francis Veilleux-Gaboury Date: Fri, 31 Jul 2015 18:04:02 -0400 Subject: [PATCH 03/19] Update connection_test.js Disconnect made manual instead of auto. --- login/connection_test.js | 59 +++++++++++++++++++++++++--------------- 1 file changed, 37 insertions(+), 22 deletions(-) diff --git a/login/connection_test.js b/login/connection_test.js index e60f18d..3debb5b 100644 --- a/login/connection_test.js +++ b/login/connection_test.js @@ -1,11 +1,12 @@ loginInformation = document.login_information; loginInformation.elements.test_websocket.addEventListener("click", init); +loginInformation.elements.disconnect_websocket.addEventListener("click", closeWebsocket); -var server - , username - , testMessage - , websocketOutput; +var server, + username, + testMessage, + websocketOutput; function init() { @@ -20,13 +21,13 @@ function init() { } websocketOutput = document.getElementById("websocket_output"); - testWebSocket(); } function testWebSocket() { - // Message to append input values to document prior to printing test results + // Append input values to document prior to printing test results + var wsHeader = document.createElement("h3"); wsHeader.innerHTML = "Testing WebSocket connection..."; websocketOutput.appendChild(wsHeader); @@ -34,7 +35,7 @@ function testWebSocket() { var wsInput = document.createElement("p"); wsInput.innerHTML = "Server: " + server + "
" + - "Username: " + username + "
" + + "Username: " + username + "
" + "Message: " + testMessage; websocketOutput.appendChild(wsInput); @@ -45,44 +46,58 @@ function testWebSocket() { websocket.onopen = function(evt) { onOpen(evt) }; - websocket.onclose = function(evt) { + /*websocket.onclose = function(evt) { onClose(evt) - }; + };*/ websocket.onmessage = function(evt) { onMessage(evt) }; websocket.onerror = function(evt) { onError(evt) }; + + /* Close websocket if page is closed or refreshed */ + window.onbeforeunload = function() { + websocket.onclose = function () {}; // disable onclose handler + websocket.close() + }; +} + +function closeWebsocket() { + websocket.onclose = function(evt) { + onClose(evt) + }; + websocket.close(); + //writeToScreen("DISCONNECTED"); } + + function onOpen(evt) { - writeToScreen("CONNECTED"); - doSend(testMessage); + writeToScreen("CONNECTED"); + doSend(testMessage); } function onClose(evt) { - writeToScreen("DISCONNECTED"); + writeToScreen("DISCONNECTED"); } function onMessage(evt) { - writeToScreen('RESPONSE: ' + evt.data + ''); - websocket.close(); + writeToScreen('RESPONSE: ' + evt.data + ''); } function onError(evt) { - writeToScreen('ERROR: ' + evt.data); + writeToScreen('ERROR: ' + evt.data); } function doSend(message) { - writeToScreen("SENT: " + message); - websocket.send(message); + writeToScreen("SENT: " + message); + websocket.send(message); } function writeToScreen(message) { - - var pre = document.createElement("p"); - pre.style.wordWrap = "break-word"; - pre.innerHTML = message; - websocketOutput.appendChild(pre); + var pre = document.createElement("p"); + //pre.style.wordWrap = "break-word"; + pre.innerHTML = message; + websocketOutput.appendChild(pre); } From 70686f32e33443bdfa441c9f9e1cd033fe64a3f3 Mon Sep 17 00:00:00 2001 From: Francis Veilleux-Gaboury Date: Tue, 4 Aug 2015 11:47:26 -0400 Subject: [PATCH 04/19] Update login.html Add manual disconnect for websocket --- login/login.html | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/login/login.html b/login/login.html index faaf2e1..2302883 100644 --- a/login/login.html +++ b/login/login.html @@ -19,7 +19,7 @@

Cardshifter login


- +
@@ -33,8 +33,11 @@

Cardshifter login



- - + +
+
+ + From b736dcebed323365aef79f221e6c508175d75bda Mon Sep 17 00:00:00 2001 From: Francis Veilleux-Gaboury Date: Tue, 4 Aug 2015 12:13:33 -0400 Subject: [PATCH 05/19] Update login.js Rename `login_information` to `loginInformation`; add a bit of documentation. --- login/login.js | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/login/login.js b/login/login.js index 0c17ad7..ae9fdf6 100644 --- a/login/login.js +++ b/login/login.js @@ -1,21 +1,27 @@ (function(window, undefined) { - var login_information = document.login_information; + + /* Login information data obtained from user input in HTML form */ + var loginInformation = document.login_information; var server = login_information.server; - var serverOther = login_information.server_other; - var serverOtherContainer = document.getElementById("server_other"); - var username = login_information.username; - var isSecure = login_information.secure; - var submit = login_information.submit; + var serverOther = loginInformation.server_other_input; + var serverOtherContainer = document.getElementById("server_other_input"); + var username = loginInformation.username; + var isSecure = loginInformation.secure; + var submit = loginInformation.submit; var isOther = false; + submit.onclick = function() { + /* Verify if user selected one of the provided servers, or entered another server of their choosing */ var finalServer = (isOther ? serverOther.value : server.value); console.log(finalServer); } + server.onclick = function() { console.log(this.value); + /* Display a text input field if user select "other" as server so that server can be entered manually */ if(this.value === "other") { serverOtherContainer.style.display = "block"; isOther = true; From 89e3c4e9303baf2d0c32480c05097dbd1312a66a Mon Sep 17 00:00:00 2001 From: Francis Veilleux-Gaboury Date: Tue, 4 Aug 2015 14:33:43 -0400 Subject: [PATCH 06/19] Update login.js Added temporary checks to print input values to console and append into document --- login/login.js | 31 +++++++++++++++++++++++++++---- 1 file changed, 27 insertions(+), 4 deletions(-) diff --git a/login/login.js b/login/login.js index ae9fdf6..9fc8183 100644 --- a/login/login.js +++ b/login/login.js @@ -8,20 +8,43 @@ var serverOtherContainer = document.getElementById("server_other_input"); var username = loginInformation.username; var isSecure = loginInformation.secure; + var testMessage = loginInformation.test_message; var submit = loginInformation.submit; var isOther = false; submit.onclick = function() { - /* Verify if user selected one of the provided servers, or entered another server of their choosing */ + // Verify if user selected one of the provided servers, or entered another server of their choosing var finalServer = (isOther ? serverOther.value : server.value); - console.log(finalServer); + + // For testing print values to console + console.log("Final server: " + finalServer); + console.log("Username: " + username.value); + console.log("Is Secure: " + isSecure.value); + console.log("Test message: " + testMessage.value); + + // Append input values to document prior to printing test results + + websocketOutput = document.getElementById("websocket_output"); + + var wsHeader = document.createElement("h3"); + wsHeader.innerHTML = "Testing WebSocket connection..."; + websocketOutput.appendChild(wsHeader); + + var printTestMessage = (testMessage.value ? testMessage.value : "No test message"); + + var wsInput = document.createElement("p"); + wsInput.innerHTML = + "Server: " + finalServer + "
" + + "Username: " + username.value + "
" + + "Message: " + printTestMessage; + websocketOutput.appendChild(wsInput); } server.onclick = function() { - console.log(this.value); - /* Display a text input field if user select "other" as server so that server can be entered manually */ + console.log("Select server:" + this.value); + // Display a text input field if user select "other" as server so that server can be entered manually if(this.value === "other") { serverOtherContainer.style.display = "block"; isOther = true; From c01862517bca770d1e895869a25d8c9510544e46 Mon Sep 17 00:00:00 2001 From: Francis Veilleux-Gaboury Date: Tue, 4 Aug 2015 15:28:08 -0400 Subject: [PATCH 07/19] Update connection_test.js Removed superfluous toString conversions --- login/connection_test.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/login/connection_test.js b/login/connection_test.js index 3debb5b..8f77c34 100644 --- a/login/connection_test.js +++ b/login/connection_test.js @@ -10,12 +10,12 @@ var server, function init() { - server = document.getElementById("server").value.toString(); + server = document.getElementById("server").value; if (server === "other") { - server = document.getElementById("server_other_input").value.toString(); + server = document.getElementById("server_other_input").value; } - username = document.getElementById("username").value.toString(); - testMessage = document.getElementById("test_message").value.toString(); + username = document.getElementById("username").value; + testMessage = document.getElementById("test_message").value; if (!testMessage) { testMessage = '{ "command": "login", "username": "' + username + '" }'; } From 67472942ec3fb3108070f6a47492ce48c12d1454 Mon Sep 17 00:00:00 2001 From: Francis Veilleux-Gaboury Date: Tue, 4 Aug 2015 17:53:22 -0400 Subject: [PATCH 08/19] Update login.html Add interface_server.js script link --- login/login.html | 1 + 1 file changed, 1 insertion(+) diff --git a/login/login.html b/login/login.html index 2302883..6b7828a 100644 --- a/login/login.html +++ b/login/login.html @@ -40,6 +40,7 @@

Cardshifter login

+ From 10d037915143fa51a2fb0b02807a6069b1a73edb Mon Sep 17 00:00:00 2001 From: Francis Veilleux-Gaboury Date: Tue, 4 Aug 2015 17:54:27 -0400 Subject: [PATCH 09/19] Update login.js Started on actual websocket connection and login message, but need to correct a problem still --- login/login.js | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/login/login.js b/login/login.js index 9fc8183..7cc537f 100644 --- a/login/login.js +++ b/login/login.js @@ -39,8 +39,23 @@ "Username: " + username.value + "
" + "Message: " + printTestMessage; websocketOutput.appendChild(wsInput); + + // attempt connection to websocket server using input values + + connect(finalServer, username.value, isSecure.value, testMessage.value); } + function connect(server, username, isSecure, testMessage) { + CardshifterServerAPI.init(server, isSecure); + webSocket = new WebSocket(server); + + var loginMessage = new CardshifterServerAPI.messageTypes.LoginMessage(username); + CardshifterServerAPI.sendMessage(loginMessage); + if (!testMessage) { + testMessage = "Hello, Cardshifter!"; + } + CardshifterServerAPI.sendMessage(testMessage); + } server.onclick = function() { console.log("Select server:" + this.value); From 111067a9055a2edd7abbaa0f7805393e28e7912a Mon Sep 17 00:00:00 2001 From: Francis Veilleux-Gaboury Date: Tue, 4 Aug 2015 18:50:08 -0400 Subject: [PATCH 10/19] merge in API changes from master --- server_interface/server_interface.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/server_interface/server_interface.js b/server_interface/server_interface.js index 9ce3cd4..64f1d53 100644 --- a/server_interface/server_interface.js +++ b/server_interface/server_interface.js @@ -67,7 +67,7 @@ } }, init: function(server, isSecure) { - var types = this.types; + var types = this.messageTypes; types.LoginMessage.prototype = new Message("login"); types.RequestTargetsMessage.prototype = new Message("requestTargets"); From 70d8bfabb65d46b4eedc6008a65e3536cbecd102 Mon Sep 17 00:00:00 2001 From: Francis Veilleux-Gaboury Date: Wed, 5 Aug 2015 09:08:00 -0400 Subject: [PATCH 11/19] add try/catch to connect function --- login/connection_test.js | 8 ++++ login/login.js | 16 +++++-- server_interface/server_interface.js | 64 +++++++++++++++++----------- 3 files changed, 61 insertions(+), 27 deletions(-) diff --git a/login/connection_test.js b/login/connection_test.js index 8f77c34..5ae0ec0 100644 --- a/login/connection_test.js +++ b/login/connection_test.js @@ -8,6 +8,10 @@ var server, testMessage, websocketOutput; +/** + * Get elements from web form to connect to WebSocket. + * @deprecated See login.js + */ function init() { server = document.getElementById("server").value; @@ -24,6 +28,10 @@ function init() { testWebSocket(); } +/** + * Pass elements from web form to WebSocket and append messages to document. + * @deprecated See login.js + */ function testWebSocket() { // Append input values to document prior to printing test results diff --git a/login/login.js b/login/login.js index fad3a4e..ce9cc1f 100644 --- a/login/login.js +++ b/login/login.js @@ -11,6 +11,7 @@ var testMessage = loginInformation.test_message; var submit = loginInformation.submit; var isOther = false; + var websocketOutput; submit.onclick = function() { @@ -46,15 +47,24 @@ } function connect(server, username, isSecure, testMessage) { + CardshifterServerAPI.init(server, isSecure); - webSocket = new WebSocket(server); var loginMessage = new CardshifterServerAPI.messageTypes.LoginMessage(username); - CardshifterServerAPI.sendMessage(loginMessage); + try { + CardshifterServerAPI.sendMessage(loginMessage); + } catch (e) { + console.log(e); + } + if (!testMessage) { testMessage = "Hello, Cardshifter!"; } - CardshifterServerAPI.sendMessage(testMessage); + try { + CardshifterServerAPI.sendMessage(testMessage); + } catch(e) { + console.log(e); + } } server.onclick = function() { diff --git a/server_interface/server_interface.js b/server_interface/server_interface.js index 009c3f7..fce8cff 100644 --- a/server_interface/server_interface.js +++ b/server_interface/server_interface.js @@ -1,40 +1,49 @@ (function(window, undefined) { // checks if the string begins with either ws:// or wss:// - var wsProtocolFinder = /ws(s)*:\/\//; + var wsProtocolFinder = /ws(s)*:\/\//; + var SOCKET_OPEN = 1; function Message(command) { this.command = command; } + function NotInitializedException(message) { this.name = "NotInitializedException"; this.message = message; } + function SocketNotReadyException(message, readyState) { + this.name = "SocketNotReadyException" + this.message = message; + this.readyState = readyState; + } + window.CardshifterServerAPI = { socket: null, messageTypes: { - /** - * Incoming login message. - *

- * A login message from a client to add a user to the available users on the server. - * This login message is required before any other action or message can be performed between a client and a server. - * @constructor - * @param username the incoming user name passed from client to server, not null - * @example Message: { "command":"login","username":"JohnDoe" } - */ + /** + * Incoming login message. + *

+ * A login message from a client to add a user to the available users on the server. + * This login message is required before any other action or message can be performed between a client and a server. + * @constructor + * @param username the incoming user name passed from client to server, not null + * @example Message: { "command":"login","username":"JohnDoe" } + */ LoginMessage: function(username) { this.username = username; }, - /** - * Request available targets for a specific action to be performed by an entity. - *

- * These in-game messages request a list of al available targets for a given action and entity. - * The client uses this request in order to point out targets (hopefully with a visual aid such as highlighting targets) - * that an entity (such as a creature card, or a player) can perform an action on (for example attack or enchant a card. - * @constructor - * @param gameId The Id of this game currently being played - * @param id The Id of this entity which requests to perform an action - * @param action The name of this action requested to be performed - */ + + /** + * Request available targets for a specific action to be performed by an entity. + *

+ * These in-game messages request a list of al available targets for a given action and entity. + * The client uses this request in order to point out targets (hopefully with a visual aid such as highlighting targets) + * that an entity (such as a creature card, or a player) can perform an action on (for example attack or enchant a card. + * @constructor + * @param gameId The Id of this game currently being played + * @param id The Id of this entity which requests to perform an action + * @param action The name of this action requested to be performed + */ RequestTargetsMessage: function(gameId, id, action) { this.gamdId = gameId; this.id = id; @@ -207,6 +216,8 @@ // if the protocol is not found in the string, store the correct protocol (is secure?) var protocolAddon = (wsProtocolFinder.test(server) ? "" : "ws" + secureAddon + "://"); var socket = new WebSocket(protocolAddon + server); + + this.socket = socket; }, @@ -219,11 +230,16 @@ * This will use websocket setup by `this.init` to send a message to the server. */ sendMessage: function(message) { - if(this.socket) { - this.socket.send(JSON.stringify(message)); + var socket = this.socket; + if(socket) { + if(socket.readyState === SOCKET_OPEN) { + this.socket.send(JSON.stringify(message)); + } else { + throw new SocketNotReadyException("The Websocket is not yet ready to be used", socket.readyState); + } } else { throw new NotInitializedException("The API has not yet been initialized."); } } }; -})(Function("return this")()); +})(Function("return this")()); \ No newline at end of file From a7b7fb28afc95a6bc0049a64768470df0ff2b920 Mon Sep 17 00:00:00 2001 From: Francis Veilleux-Gaboury Date: Wed, 5 Aug 2015 10:12:14 -0400 Subject: [PATCH 12/19] Update login.html Add CDN for Bootstrap CSS, FontAwesome, AngularJS and AngulerJS route --- login/login.html | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/login/login.html b/login/login.html index 633de80..00cf0bc 100644 --- a/login/login.html +++ b/login/login.html @@ -4,6 +4,14 @@ Cardshifter -- Login + + + + + + + + @@ -32,7 +40,9 @@

Cardshifter login



- +
From bc82f626ba83d1ec0a133cfd0e67ad705fcc4e6a Mon Sep 17 00:00:00 2001 From: Francis Veilleux-Gaboury Date: Wed, 5 Aug 2015 10:41:20 -0400 Subject: [PATCH 13/19] Update login.css Add CSS classes from main Cardshifter website --- login/login.css | 213 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 213 insertions(+) diff --git a/login/login.css b/login/login.css index ce82d90..62b79b1 100644 --- a/login/login.css +++ b/login/login.css @@ -1,3 +1,216 @@ +body { + font-size: 120%; + font-family: Verdana, Geneva, sans-serif; +} + +/* FORMATTING SPECIFIC TO LOGIN FORM */ + #server_other { display: none; } + + +/* FORMATTING FOR TOP NAV BAR */ + +.csh-top-link { + font-family: Georgia, Times, "Times New Roman", serif; + color: #FFFFFF; + font-size: 2em; +} + +.csh-twitter-top-bar { + list-style: none; + margin: 0; +} + +.csh-twitter-top-bar > li { + display: inline-block !important; +} + +.twitter-logo { + height: 25px; + width: 30px; + margin-top: 10px; + -left: 5px; +} + + +/* FORMATTING FOR LEFT SIDE NAV MENU */ + +.csh-left-menu-main { + font-size: 1.4em; + font-weight: bold; + padding-top: 3px; + color: #000000; + margin: 0px; +} + +.csh-left-menu-sub { + font-size: 1.2em; + font-weight: normal; + padding-left: 15px; + padding-top: 3px; + color: #000000; + margin: 0px; +} + + +.csh-nav-link { + color: #000000; +} + +.csh-nav-link:hover +.csh-nav-link:active { + color: #000000; + text-decoration: underline; +} + +.csh-side-nav { + margin-top: 25px; + background-color: #EEEEEE; + padding-bottom: 5px; +} + + +.csh-margin-top { + margin-top: 50px; +} + +/* FORMATTING FOR PAGE BODY */ + +.csh-body { + padding-left: 15px; +} + +/* FORMATTING FOR FOOTER */ + +html { + position: relative; + min-height: 100%; +} +body { + margin-bottom: 60px; +} + +.footer { + position: absolute; + bottom: 0; + margin-top: 15px; + padding: 5px 0 5px 15px; + border-top: 1px solid #eaeaea; + color: #777; + width: 100%; + text-align: center; + /* Set the fixed height of the footer here */ + height: 30px; + background-color: #f5f5f5; + position: absolute; + bottom: 0px; +} + +/* FORMATTING FOR COMMON PAGE ELEMENTS */ + +.header-border { + border-bottom: 1px solid #eee; +} + +h1, h2, h3, blockquote { + font-family: Georgia, Times, "Times New Roman", serif; +} + +p, span, table, ul, ol { + font-size: 1.2em; + font-weight: normal; +} + +pre { + font-family: Consolas, Monaco, "Courier New", monospace; + font-size: 1.1em; + font-weight: normal; +} + +code { + font-family: Consolas, Monaco, "Courier New", monospace; + font-size: 1.1em; + color: #336699; + background-color: #EEEEEE; +} + +blockquote { + font-size: 1.4em; +} + +div.contributor { + margin-bottom: 10px; + margin-top: 10px; + width: 350px; +} + +/* FORMATTING FOR ARTICLES */ + +article {} + +h2.csh-article { + font-size: 2.4em; + text-decoration: underline; +} + +h3.csh-article { + font-size: 2.0em; +} + +a.csh-article { + text-decoration: underline; +} + +section.csh-article { + padding-left: 5px; +} + +p.csh-article-header { + font-size: 1.2em; + font-style: italic; + font-family: Georgia, Times, "Times New Roman", serif; +} + +p.csh-article-content { + padding-left: 10px; + font-size: 1.2em; +} + +p.csh-article-footer { + font-size: 1.2em; + padding-left: 5px; + font-style: italic; + font-family: Georgia, Times, "Times New Roman", serif; +} + +ul.csh-article-list, +ol.csh-article-list { + font-size: 1.2em; +} + + +/* FORMATTING FOR TABLES */ + +table, th, td { + border: 1px solid black; + border-collapse: collapse; +} + +th, td { + padding: 5px; +} + +th { + background-color: #EEEEEE; + color: #000000; +} + +/* FORMATTING FOR BUTTONS, ALERTS, ETC. */ + +.csh-button { + font-size: 1.1em; + font-weight: normal; +} + From 9e17c6b5946c3b99b91204dffbe3ba7afe4444af Mon Sep 17 00:00:00 2001 From: Francis Veilleux-Gaboury Date: Wed, 5 Aug 2015 12:45:24 -0400 Subject: [PATCH 14/19] Update login.css Some adjustments to CSS login form classes --- login/login.css | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/login/login.css b/login/login.css index 62b79b1..ae1e07c 100644 --- a/login/login.css +++ b/login/login.css @@ -9,6 +9,24 @@ body { display: none; } +.login-form { + font-size: 1.2em; + font-weight: normal; + width: 50%; +} + +label { + font-size: 1.0em; +} + +button, input, select, textarea { + font-size: 1.0em; + font-family: Verdana, Geneva, sans-serif; + padding-bottom; 0px; +} + + + /* FORMATTING FOR TOP NAV BAR */ From af981b259e059780e37aadcf7bc24460accb7c45 Mon Sep 17 00:00:00 2001 From: Francis Veilleux-Gaboury Date: Wed, 5 Aug 2015 12:48:01 -0400 Subject: [PATCH 15/19] Update login.html Refactor login form to use Bootstrap CSS elements --- login/login.html | 46 +++++++++++++++++++++++++++------------------- 1 file changed, 27 insertions(+), 19 deletions(-) diff --git a/login/login.html b/login/login.html index 00cf0bc..4ee4dba 100644 --- a/login/login.html +++ b/login/login.html @@ -2,11 +2,13 @@ - Cardshifter -- Login - + Cardshifter Login + - - + + + + @@ -15,40 +17,46 @@ +

Cardshifter login

-
- - -
+
+
- +

+
+
- -
+ +
+
-
- -
- - + +
+
+ + + +
- + From b38c94cbcab352290c7d0835e114aa15151da23e Mon Sep 17 00:00:00 2001 From: Francis Veilleux-Gaboury Date: Wed, 5 Aug 2015 13:52:30 -0400 Subject: [PATCH 16/19] Create login_alt.html Alternate top navbar menu with login form --- login/login_alt.html | 108 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 108 insertions(+) create mode 100644 login/login_alt.html diff --git a/login/login_alt.html b/login/login_alt.html new file mode 100644 index 0000000..df0bef6 --- /dev/null +++ b/login/login_alt.html @@ -0,0 +1,108 @@ +Enter file contents here + + + + Cardshifter Login + + + + + + + + + + + + + + + + + +
+ + + + + +
+ + + From 6d1ee0a233358a68a0556f0e56c5dfe2ee0e3833 Mon Sep 17 00:00:00 2001 From: Francis Veilleux-Gaboury Date: Wed, 5 Aug 2015 21:17:01 -0400 Subject: [PATCH 17/19] deleted old login.js --- login/login.js | 82 -------------------------------------------------- 1 file changed, 82 deletions(-) delete mode 100644 login/login.js diff --git a/login/login.js b/login/login.js deleted file mode 100644 index ce9cc1f..0000000 --- a/login/login.js +++ /dev/null @@ -1,82 +0,0 @@ -(function(window, undefined) { - - /* Login information data obtained from user input in HTML form */ - var loginInformation = document.login_information; - - var server = login_information.server; - var serverOther = loginInformation.server_other_input; - var serverOtherContainer = document.getElementById("server_other_input"); - var username = loginInformation.username; - var isSecure = loginInformation.secure; - var testMessage = loginInformation.test_message; - var submit = loginInformation.submit; - var isOther = false; - var websocketOutput; - - - submit.onclick = function() { - // Verify if user selected one of the provided servers, or entered another server of their choosing - var finalServer = (isOther ? serverOther.value : server.value); - - // For testing print values to console - console.log("Final server: " + finalServer); - console.log("Username: " + username.value); - console.log("Is Secure: " + isSecure.value); - console.log("Test message: " + testMessage.value); - - // Append input values to document prior to printing test results - - websocketOutput = document.getElementById("websocket_output"); - - var wsHeader = document.createElement("h3"); - wsHeader.innerHTML = "Testing WebSocket connection..."; - websocketOutput.appendChild(wsHeader); - - var printTestMessage = (testMessage.value ? testMessage.value : "No test message"); - - var wsInput = document.createElement("p"); - wsInput.innerHTML = - "Server: " + finalServer + "
" + - "Username: " + username.value + "
" + - "Message: " + printTestMessage; - websocketOutput.appendChild(wsInput); - - // attempt connection to websocket server using input values - - connect(finalServer, username.value, isSecure.value, testMessage.value); - } - - function connect(server, username, isSecure, testMessage) { - - CardshifterServerAPI.init(server, isSecure); - - var loginMessage = new CardshifterServerAPI.messageTypes.LoginMessage(username); - try { - CardshifterServerAPI.sendMessage(loginMessage); - } catch (e) { - console.log(e); - } - - if (!testMessage) { - testMessage = "Hello, Cardshifter!"; - } - try { - CardshifterServerAPI.sendMessage(testMessage); - } catch(e) { - console.log(e); - } - } - - server.onclick = function() { - console.log("Select server:" + this.value); - // Display a text input field if user select "other" as server so that server can be entered manually - if(this.value === "other") { - serverOtherContainer.style.display = "block"; - isOther = true; - } else { - serverOtherContainer.style.display = "none"; - isOther = false; - } - } - -})(Function("return this")()); From 1c9416dc0610fcda59138159a96eba9bfcf9d88d Mon Sep 17 00:00:00 2001 From: Francis Veilleux-Gaboury Date: Wed, 5 Aug 2015 21:20:06 -0400 Subject: [PATCH 18/19] add try/catch to send login, uncommented that --- login/login_controller.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/login/login_controller.js b/login/login_controller.js index 8df26ee..23b9de6 100644 --- a/login/login_controller.js +++ b/login/login_controller.js @@ -4,6 +4,10 @@ CardshifterApp.controller("LoginController", function($scope) { CardshifterServerAPI.init(finalServer, $scope.is_secure); var login = new CardshifterServerAPI.messageTypes.LoginMessage($scope.username); - //CardshifterServerAPI.sendMessage(login); + try { + CardshifterServerAPI.sendMessage(login); + } catch (e) { + console.log(e); + } } }); \ No newline at end of file From 5c6e86b6c8febc6b809ee7d003a013ca5ec75dbe Mon Sep 17 00:00:00 2001 From: Francis Veilleux-Gaboury Date: Wed, 5 Aug 2015 21:27:03 -0400 Subject: [PATCH 19/19] Commented out login send message, added TODO --- login/login_controller.js | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/login/login_controller.js b/login/login_controller.js index 23b9de6..8c941a2 100644 --- a/login/login_controller.js +++ b/login/login_controller.js @@ -4,10 +4,13 @@ CardshifterApp.controller("LoginController", function($scope) { CardshifterServerAPI.init(finalServer, $scope.is_secure); var login = new CardshifterServerAPI.messageTypes.LoginMessage($scope.username); - try { + + // TODO: Need to find a way to make this work; + // As written it tries to sendMessage the instant that the socket is created, in which case the socket is not ready +/* try { CardshifterServerAPI.sendMessage(login); } catch (e) { console.log(e); - } + }*/ } }); \ No newline at end of file