diff --git a/assets/js/index.utils.js b/assets/js/index.utils.js index dafee983..68be07e8 100644 --- a/assets/js/index.utils.js +++ b/assets/js/index.utils.js @@ -2,7 +2,7 @@ * @Author: prpr * @Date: 2016-01-21 13:55:44 * @Last Modified by: prpr -* @Last Modified time: 2016-01-21 18:47:03 +* @Last Modified time: 2016-01-22 10:34:42 */ 'use strict'; @@ -43,6 +43,7 @@ $("body").on("click", "#login-button", function(){ } showMsg("alert-success", "Logging succeed!"); window.setTimeout("$('[data-remodal-id=login-modal]').remodal().close(); window.location = './user/index.php'", 1000); + } else { showMsg("alert-danger", json.msg); } diff --git a/assets/js/skin_utils.js b/assets/js/skin_utils.js deleted file mode 100755 index 0fea4872..00000000 --- a/assets/js/skin_utils.js +++ /dev/null @@ -1,129 +0,0 @@ -$("body").on("change", "#skininput", function(){ - var files = $("#skininput").prop("files"); - handleFiles(files, "skin"); -}); - -$("body").on("change", "#capeinput", function(){ - var files = $("#capeinput").prop("files"); - handleFiles(files, "cape"); -}); - -function showMsg(type, msg) { - $("#msg").removeClass().addClass("alert").addClass(type).html(msg); -} - -var handleFiles = function (files, type) { - if(files.length > 0) { - var file = files[0]; - if(file.type === 'image/png') { - var fr = new FileReader(); - fr.onload = function (e) { - var img = new Image(); - img.onload = function () { - if (type == "skin") { - MSP.changeSkin(img.src); - } else { - MSP.changeCape(img.src); - } - }; - img.onerror = function () { - alert("Error: Not an image or unknown file format"); - }; - img.src = this.result; - }; - fr.readAsDataURL(file); - } else { - alert("Error: This is not a PNG image!"); - } - } -}; - -var canvas = MSP.get3dSkinCanvas(500, 500); -$("#skinpreview").append($(canvas).prop("id", "canvas3d")); - -$("[title='Movements']").click(function(){ - if (MSP.getStatus("movements")) { - MSP.setStatus("movements", false); - } else { - MSP.setStatus("movements", true); - } -}); - -$("[title='Running']").click(function(){ - if (MSP.getStatus("running")) { - MSP.setStatus("running", false); - } else { - MSP.setStatus("running", true); - } -}); - -$("[title='Rotation']").click(function(){ - if (MSP.getStatus("rotation")) { - MSP.setStatus("rotation", false); - } else { - MSP.setStatus("rotation", true); - } -}); - -$("#logout").click(function(){ - $.ajax({ - type: "POST", - url: "../ajax.php?action=logout", - dataType: "json", - data: {"uname": docCookies.getItem('uname')}, - success: function(json) { - var path = "/" + document.URL.split("/").slice(-3)[0]; - docCookies.removeItem("uname", path); - docCookies.removeItem("token", path); - showMsg('alert-success', json.msg); - window.setTimeout(function(){ - window.location = "./index.php"; - }, 1000); - } - }); -}); - -$("#upload").click(function(){ - var skin_file = $("#skininput").get(0).files[0]; - var cape_file = $("#capeinput").get(0).files[0]; - - var form_data = new FormData(); - if (skin_file) { - form_data.append('skin_file', skin_file); - } - if (cape_file) { - form_data.append('cape_file', cape_file); - } - form_data.append('uname', docCookies.getItem('uname')); - if (skin_file || cape_file) { - $.ajax({ - type: 'POST', - url: '../ajax.php?action=upload', - contentType: false, - dataType: "json", - data: form_data, - processData: false, - beforeSend: function() { - showMsg("alert-info", "Uploading..."); - }, - success: function(json) { - console.log(json); - if (json[0].errno == 0 && json[1].errno == 0) { - showMsg("alert-success", "Successfully uploaded."); - } - if (json[0].errno != 0) { - showMsg("alert-danger", "Error when uploading skin:\n"+json[0].msg); - } - if (json[1].errno != 0) { - showMsg("alert-danger", "Error when uploading cape:\n"+json[1].msg); - } - } - }); - } else { - showMsg("alert-warning", "No input file selected"); - } - -}); - - - diff --git a/assets/js/user.utils.js b/assets/js/user.utils.js index 8f3f4179..c54dfcb0 100644 --- a/assets/js/user.utils.js +++ b/assets/js/user.utils.js @@ -2,76 +2,76 @@ * @Author: prpr * @Date: 2016-01-21 13:56:40 * @Last Modified by: prpr -* @Last Modified time: 2016-01-21 21:56:09 +* @Last Modified time: 2016-01-21 22:58:32 */ 'use strict'; $("body").on("change", "#skininput", function(){ - var files = $("#skininput").prop("files"); - handleFiles(files, "skin"); + var files = $("#skininput").prop("files"); + handleFiles(files, "skin"); }); $("body").on("change", "#capeinput", function(){ - var files = $("#capeinput").prop("files"); - handleFiles(files, "cape"); + var files = $("#capeinput").prop("files"); + handleFiles(files, "cape"); }); function showMsg(type, msg) { - $("#msg").removeClass().addClass("alert").addClass(type).html(msg); + $("#msg").removeClass().addClass("alert").addClass(type).html(msg); } var handleFiles = function (files, type) { - if(files.length > 0) { - var file = files[0]; - if(file.type === 'image/png') { - var fr = new FileReader(); - fr.onload = function (e) { - var img = new Image(); - img.onload = function () { - if (type == "skin") { - MSP.changeSkin(img.src); - } else { - MSP.changeCape(img.src); - } - }; - img.onerror = function () { - alert("Error: Not an image or unknown file format"); - }; - img.src = this.result; - }; - fr.readAsDataURL(file); - } else { - alert("Error: This is not a PNG image!"); - } - } + if(files.length > 0) { + var file = files[0]; + if(file.type === 'image/png') { + var fr = new FileReader(); + fr.onload = function (e) { + var img = new Image(); + img.onload = function () { + if (type == "skin") { + MSP.changeSkin(img.src); + } else { + MSP.changeCape(img.src); + } + }; + img.onerror = function () { + alert("Error: Not an image or unknown file format"); + }; + img.src = this.result; + }; + fr.readAsDataURL(file); + } else { + alert("Error: This is not a PNG image!"); + } + } }; var canvas = MSP.get3dSkinCanvas(500, 500); $("#skinpreview").append($(canvas).prop("id", "canvas3d")); $("[title='Movements']").click(function(){ - if (MSP.getStatus("movements")) { - MSP.setStatus("movements", false); - } else { - MSP.setStatus("movements", true); - } + if (MSP.getStatus("movements")) { + MSP.setStatus("movements", false); + } else { + MSP.setStatus("movements", true); + } }); $("[title='Running']").click(function(){ - if (MSP.getStatus("running")) { - MSP.setStatus("running", false); - } else { - MSP.setStatus("running", true); - } + if (MSP.getStatus("running")) { + MSP.setStatus("running", false); + } else { + MSP.setStatus("running", true); + } }); $("[title='Rotation']").click(function(){ - if (MSP.getStatus("rotation")) { - MSP.setStatus("rotation", false); - } else { - MSP.setStatus("rotation", true); - } + if (MSP.getStatus("rotation")) { + MSP.setStatus("rotation", false); + } else { + MSP.setStatus("rotation", true); + } }); $("#logout").click(function(){ @@ -86,7 +86,7 @@ $("#logout").click(function(){ docCookies.removeItem("token", path); showMsg('alert-success', json.msg); window.setTimeout(function(){ - window.location = "./index.php"; + window.location = "../index.php?msg=Successfully logged out."; }, 1000); } }); @@ -113,8 +113,8 @@ $("#upload").click(function(){ data: form_data, processData: false, beforeSend: function() { - showMsg("alert-info", "Uploading..."); - }, + showMsg("alert-info", "Uploading..."); + }, success: function(json) { console.log(json); if (json[0].errno == 0 && json[1].errno == 0) { diff --git a/index.php b/index.php index 5bf477db..063ad4c6 100755 --- a/index.php +++ b/index.php @@ -3,7 +3,7 @@ * @Author: printempw * @Date: 2016-01-17 13:55:20 * @Last Modified by: prpr - * @Last Modified time: 2016-01-21 23:08:45 + * @Last Modified time: 2016-01-22 10:33:36 */ session_start(); function __autoload($classname) { @@ -36,6 +36,7 @@ function getValue($key, $array) { +
@@ -114,13 +115,13 @@ function getValue($key, $array) { + -