From d24ab3a0fe68711d87ae88953991ef87ba4cf12b Mon Sep 17 00:00:00 2001 From: printempw Date: Thu, 4 Feb 2016 10:18:24 +0800 Subject: [PATCH 1/6] fix bugs --- includes/user.class.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/includes/user.class.php b/includes/user.class.php index b5faebfa..3f64127a 100644 --- a/includes/user.class.php +++ b/includes/user.class.php @@ -3,7 +3,7 @@ * @Author: printempw * @Date: 2016-01-16 23:01:33 * @Last Modified by: prpr - * @Last Modified time: 2016-02-03 21:13:05 + * @Last Modified time: 2016-02-04 10:18:01 */ class user @@ -68,9 +68,9 @@ class user } public function unRegister() { - if (is_null($this->getTexture('skin'))) + if (!is_null($this->getTexture('skin'))) utils::remove("./textures/".$this->getTexture('skin')); - if (is_null($this->getTexture('skin'))) + if (!is_null($this->getTexture('skin'))) utils::remove("./textures/".$this->getTexture('cape')); return $this->db->delete($this->uname); } From f0a07c347e4be9cedb0470b4df158eb092312d65 Mon Sep 17 00:00:00 2001 From: printempw Date: Thu, 4 Feb 2016 12:35:37 +0800 Subject: [PATCH 2/6] automatically login after registeration --- assets/js/index.utils.js | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/assets/js/index.utils.js b/assets/js/index.utils.js index 681a52ad..111bacd6 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-02-03 21:40:41 +* @Last Modified time: 2016-02-04 12:34:37 */ 'use strict'; @@ -52,17 +52,20 @@ var register = function() { showMsg("alert-info", "Registering..."); }, success: function(json) { - if (json.errno == 0) { - showAlert(json.msg + " Please log in.", function(){ + if (json.errno == 0) { + showAlert(json.msg, function(){ showMsg('hide', ""); $('[data-remodal-id=register-modal]').remodal().close(); - $('[data-remodal-id=login-modal]').remodal().open(); + // Automatically login after registeration + $("#uname").val(uname); + $("#passwd").val(passwd); + login(); }); } else { showAlert(json.msg); showMsg('hide', ""); } - } + } }); } } @@ -125,3 +128,4 @@ $("body").on("keypress", "[data-remodal-id=register-modal]", function(event){ $("body").on("keypress", "[data-remodal-id=login-modal]", function(event){ if (event.which == 13) login(); }).on("click", "#login-button", login); + From 297c634b535287028c83b7d581668934de5d307d Mon Sep 17 00:00:00 2001 From: printempw Date: Thu, 4 Feb 2016 13:49:42 +0800 Subject: [PATCH 3/6] do not use is_null to compare string --- includes/user.class.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/includes/user.class.php b/includes/user.class.php index 3f64127a..7f540e7c 100644 --- a/includes/user.class.php +++ b/includes/user.class.php @@ -3,7 +3,7 @@ * @Author: printempw * @Date: 2016-01-16 23:01:33 * @Last Modified by: prpr - * @Last Modified time: 2016-02-04 10:18:01 + * @Last Modified time: 2016-02-04 13:48:48 */ class user @@ -68,9 +68,9 @@ class user } public function unRegister() { - if (!is_null($this->getTexture('skin'))) + if ($this->getTexture('skin') != "") utils::remove("./textures/".$this->getTexture('skin')); - if (!is_null($this->getTexture('skin'))) + if ($this->getTexture('skin') != "") utils::remove("./textures/".$this->getTexture('cape')); return $this->db->delete($this->uname); } From acd28577ae35340b61787cd2af4515c217b0e54b Mon Sep 17 00:00:00 2001 From: printempw Date: Thu, 4 Feb 2016 17:19:28 +0800 Subject: [PATCH 4/6] use defined DIR to prevent relative path problem --- config.php | 15 +++++++++------ includes/utils.class.php | 8 ++++---- 2 files changed, 13 insertions(+), 10 deletions(-) diff --git a/config.php b/config.php index d3dd4418..7f062e40 100644 --- a/config.php +++ b/config.php @@ -1,18 +1,21 @@ Date: Thu, 4 Feb 2016 17:20:22 +0800 Subject: [PATCH 5/6] some style change --- admin/index.php | 111 ++++++++++++++++++++++++++++++++++++-- assets/css/user.style.css | 4 +- user/index.php | 14 ++--- user/profile.php | 12 ++++- 4 files changed, 129 insertions(+), 12 deletions(-) diff --git a/admin/index.php b/admin/index.php index ac1d2100..cad3daca 100644 --- a/admin/index.php +++ b/admin/index.php @@ -1,10 +1,115 @@ - +getToken()) { + header('Location: ../index.php?msg=Invalid token. Please login.'); + } else if (!$admin->is_admin) { + header('Location: ../index.php?msg=Looks like that you are not administrator :('); + } +} else { + header('Location: ../index.php?msg=Illegal access. Please login.'); +} +?> + + - Console - Blessing Skin Server 0.1 + + + Console - Blessing Skin Server + + + + + + + -

Console

+
+
+ Blessing Skin Server + +
+
+
+
+
+
+
+ +
+ + + + + + + + + + + + + query("SELECT * FROM users"); + while ($row = $result->fetch_array()) { ?> + + + + + + + + + +
#UsernamePreview TexturesChange TexturesOpreation
+ '; ?> + '; ?> + + Skin + Cape + + Password + Delete +
+
+ + + + + + + + + diff --git a/assets/css/user.style.css b/assets/css/user.style.css index d1029a78..b4528f84 100644 --- a/assets/css/user.style.css +++ b/assets/css/user.style.css @@ -2,7 +2,7 @@ * @Author: prpr * @Date: 2016-01-21 19:12:06 * @Last Modified by: prpr -* @Last Modified time: 2016-02-03 16:39:42 +* @Last Modified time: 2016-02-04 12:56:15 */ .home-menu-blur { @@ -66,7 +66,7 @@ body { .upload-container { color: #333; - margin-top: 35%; + margin-top: 30%; margin-right: 30%; border: #989898 1px solid; border-radius: 4px; diff --git a/user/index.php b/user/index.php index c6f6b7d5..36352309 100644 --- a/user/index.php +++ b/user/index.php @@ -49,15 +49,15 @@ if (isset($_SESSION['uname'])) {
@@ -85,10 +85,10 @@ if (isset($_SESSION['uname'])) {

Upload

Select a skin:

- +

Select a cape:

- +

Preview @@ -119,7 +119,9 @@ if (isset($_SESSION['uname'])) {

Select a cape:

-

+
+

Well, the skin server does support double layer skin of 1.8, but the preview does not. So just upload and you will get it display well in game.

+ Preview
diff --git a/user/profile.php b/user/profile.php index a90970dc..e24318ae 100644 --- a/user/profile.php +++ b/user/profile.php @@ -3,7 +3,7 @@ * @Author: prpr * @Date: 2016-02-03 16:12:45 * @Last Modified by: prpr - * @Last Modified time: 2016-02-03 23:15:41 + * @Last Modified time: 2016-02-04 12:51:07 */ session_start(); @@ -98,6 +98,16 @@ if (isset($_SESSION['uname'])) {
+ is_admin) { ?> +
+
+
Welcome, administrator.
+
+

Here manage your site: Console

+
+
+
+ From a2758c013a513b38702dbdcd8cbcf8137312986e Mon Sep 17 00:00:00 2001 From: printempw Date: Thu, 4 Feb 2016 17:21:05 +0800 Subject: [PATCH 6/6] added admin page --- admin/admin_ajax.php | 67 ++++++++++++++++++++++++++++++ assets/css/admin.style.css | 26 ++++++++++++ assets/js/admin.utils.js | 85 ++++++++++++++++++++++++++++++++++++++ 3 files changed, 178 insertions(+) create mode 100644 admin/admin_ajax.php create mode 100644 assets/css/admin.style.css create mode 100644 assets/js/admin.utils.js diff --git a/admin/admin_ajax.php b/admin/admin_ajax.php new file mode 100644 index 00000000..af1ce3c2 --- /dev/null +++ b/admin/admin_ajax.php @@ -0,0 +1,67 @@ +getToken()) { + header('Location: ../index.php?msg=Invalid token. Please login.'); + } else if (!$admin->is_admin) { + header('Location: ../index.php?msg=Looks like that you are not administrator :('); + } +} else { + header('Location: ../index.php?msg=Illegal access. Please login.'); +} + +/* + * No protection here, + * I don't think you wanna fuck yourself :( + */ +if (isset($_GET['action'])) { + $action = $_GET['action']; + $user = new user($_GET['uname']); + + if ($action == "upload") { + $type = isset($_GET['type']) ? $_GET['type'] : "skin"; + $file = isset($_FILES['file']) ? $_FILES['file'] : null; + if (!is_null($file)) { + if ($user->setTexture($type, $file)) { + $json['errno'] = 0; + $json['msg'] = "Skin uploaded successfully."; + } else { + $json['errno'] = 1; + $json['msg'] = "Uncaught error."; + } + } else { + utils::raise(1, 'No input file selected'); + } + } else if ($action == "change") { + if (user::checkValidPwd($_POST['passwd'])) { + $user->changePasswd($_POST['passwd']); + $json['errno'] = 0; + $json['msg'] = "Password of ".$_GET['uname']." changed successfully."; + } // Will raise exception if password invalid + } else if ($action == "delete") { + $user->unRegister(); + $json['errno'] = 0; + $json['msg'] = "Account successfully deleted."; + } +} + +echo json_encode($json); diff --git a/assets/css/admin.style.css b/assets/css/admin.style.css new file mode 100644 index 00000000..2a649f45 --- /dev/null +++ b/assets/css/admin.style.css @@ -0,0 +1,26 @@ +/* +* @Author: prpr +* @Date: 2016-02-04 16:47:54 +* @Last Modified by: prpr +* @Last Modified time: 2016-02-04 16:48:04 +*/ +.pure-table { + margin: 80px auto 0; + width: 100%; + background-color: #fff; +} +.pure-button { + width: inherit; + margin: 0 10px 0 0 !important; +} +.pure-button-error { + background: rgb(202, 60, 60); + color: #fff; +} +input { + width: 100%; + margin: 10px 0 20px; +} +.fw { + width: 100%; +} diff --git a/assets/js/admin.utils.js b/assets/js/admin.utils.js new file mode 100644 index 00000000..abc01778 --- /dev/null +++ b/assets/js/admin.utils.js @@ -0,0 +1,85 @@ +/* +* @Author: prpr +* @Date: 2016-02-04 16:48:42 +* @Last Modified by: prpr +* @Last Modified time: 2016-02-04 17:09:20 +*/ + +'use strict'; + +function showUpload(uname, type) { + var ply = new Ply({ + el: '

Upload new '+type+':

', + effect: "fade", + onaction: function(){ upload(uname, type, $('#file').get(0).files[0]); }, + }); + ply.open(); +} + +function upload(uname, type, file){ + var form_data = new FormData(); + if (file) { + form_data.append('file', file); + $.ajax({ + type: 'POST', + contentType: false, + url: 'admin_ajax.php?action=upload&type='+type+'&uname='+uname, + dataType: "json", + data: form_data, + processData: false, + success: function(json) { + if (json.errno == 0) { + showAlert("Successfully uploaded."); + $('#'+uname+'_'+type).attr('src', 'http://skin.fuck.io/'+type+'/'+uname+'.png?t='+Math.random()); + } else { + showAlert("Error when uploading cape:\n" + json.msg); + } + } + }); + } +} + +function showAlert(msg) { + Ply.dialog("alert", msg); +} + +function showChange(uname) { + Ply.dialog("prompt", { + title: "Type in "+uname+"'s new password", + form: { passwd: "New Password" } + }).done(function(ui){ + var passwd = ui.data.passwd; + $.ajax({ + type: "POST", + url: "admin_ajax.php?action=change&uname="+uname, + dataType: "json", + data: { "passwd": passwd }, + success: function(json) { + if (json.errno == 0) { + showAlert(json.msg); + } else { + showAlert(json.msg); + } + } + }); + }); +} + +function showDelete(uname) { + Ply.dialog("prompt", { + title: "Are you sure to delete "+uname+"?", + }).done(function(ui){ + $.ajax({ + type: "POST", + url: "admin_ajax.php?action=delete&uname="+uname, + dataType: "json", + success: function(json) { + if (json.errno == 0) { + showAlert(json.msg); + } else { + showAlert(json.msg); + } + } + }); + }); +}