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/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/admin/install.lock b/admin/install.lock new file mode 100644 index 00000000..85575997 --- /dev/null +++ b/admin/install.lock @@ -0,0 +1 @@ +1454430305 \ No newline at end of file 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/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/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); + } + } + }); + }); +} 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); + diff --git a/config.php b/config.php index 9cef6241..1257d022 100644 --- a/config.php +++ b/config.php @@ -1,18 +1,21 @@ 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); } diff --git a/includes/utils.class.php b/includes/utils.class.php index 96779cbd..9623f56f 100644 --- a/includes/utils.class.php +++ b/includes/utils.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 15:52:39 + * @Last Modified time: 2016-02-04 16:20:19 */ class utils @@ -29,9 +29,9 @@ class utils * @return string $hash, sha256 hash of file */ public static function upload($file) { - move_uploaded_file($file["tmp_name"], "./textures/tmp.png"); - $hash = hash_file('sha256', "./textures/tmp.png"); - rename("./textures/tmp.png", "./textures/".$hash); + move_uploaded_file($file["tmp_name"], DIR."/textures/tmp.png"); + $hash = hash_file('sha256', DIR."/textures/tmp.png"); + rename(DIR."/textures/tmp.png", DIR."/textures/".$hash); return $hash; } 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

+
+
+
+