diff --git a/admin/index.php b/admin/index.php index d1d0ede8..2b62a500 100644 --- a/admin/index.php +++ b/admin/index.php @@ -3,7 +3,7 @@ * @Author: prpr * @Date: 2016-02-03 14:39:50 * @Last Modified by: prpr - * @Last Modified time: 2016-02-04 23:45:06 + * @Last Modified time: 2016-02-05 16:05:42 */ session_start(); @@ -32,7 +32,7 @@ if (isset($_SESSION['uname'])) {
--+-----------------------------------------------------------------------------------+-----------------+ -| uid | username | password | ip | preference | skin_hash | cape_hash | last_modofied | -+-----------------------------------------------------------------------------------+-----------------+ -| 1 | admin | 123456 | * | default | * | * | * | -+-----------------------------------------------------------------------------------+-----------------+ ++-------------------------------------------------------------------------------------------------+-----------------+ +| uid | username | password | ip | preference | hash_steve | hash_alex | hash_cape | last_modofied | ++-------------------------------------------------------------------------------------------------+-----------------+ +| 1 | admin | 123456 | * | default | * | * | * | * | ++-------------------------------------------------------------------------------------------------+-----------------+"; diff --git a/ajax.php b/ajax.php index b1da2cea..bcc4f497 100644 --- a/ajax.php +++ b/ajax.php @@ -3,7 +3,7 @@ * @Author: printempw * @Date: 2016-01-16 23:01:33 * @Last Modified by: prpr - * @Last Modified time: 2016-02-04 18:48:30 + * @Last Modified time: 2016-02-05 15:35:31 * * - login, register, logout * - upload, change, delete @@ -20,7 +20,12 @@ require "$dir/includes/autoload.inc.php"; database::checkConfig(); if (isset($_POST['uname'])) { - $user = new user($_POST['uname']); + $uname = $_POST['uname']; + if (user::checkValidUname($uname)) { + $user = new user($_POST['uname']); + } else { + utils::raise(1, 'Invalid username. Only letters, numbers and _ is allowed.'); + } } else { utils::raise('1', 'Empty username.'); } @@ -29,7 +34,6 @@ $json = null; /** * Handle requests from index.php - * @var [type] */ if ($action == "login") { if (checkPost()) { @@ -59,7 +63,7 @@ if ($action == "login") { } else { $ip = $_SERVER['REMOTE_ADDR']; } - // If amout of registered accounts of IP is more than allowed mounts, + // If amount of registered accounts of IP is more than allowed mounts, // then reject the registration. if ($user->db->getNumRows('ip', $ip) < REGS_PER_IP) { // use once md5 to encrypt password @@ -99,7 +103,8 @@ if ($action == "upload") { if (utils::getValue('token', $_SESSION) == $user->getToken()) { if (checkFile()) { if ($file = utils::getValue('skin_file', $_FILES)) { - if ($user->setTexture('skin', $file)) { + $model = (isset($_GET['model']) && $_GET['model'] == "steve") ? "steve" : "alex"; + if ($user->setTexture($model, $file)) { $json['skin']['errno'] = 0; $json['skin']['msg'] = "Skin uploaded successfully."; } else { @@ -121,14 +126,15 @@ if ($action == "upload") { $json['errno'] = 1; $json['msg'] = "Invalid token."; } -} else if ($action == "logout") { - if (utils::getValue('token', $_SESSION)) { - session_destroy(); +} else if ($action == "model") { + if (utils::getValue('token', $_SESSION) == $user->getToken()) { + $new_model = ($user->getPreference() == "default") ? "slim" : "default"; + $user->setPreference($new_model); $json['errno'] = 0; - $json['msg'] = 'Session destroyed.'; + $json['msg'] = "Preferred model successfully changed to ".$user->getPreference()."."; } else { $json['errno'] = 1; - $json['msg'] = 'No available session.'; + $json['msg'] = "Invalid token."; } } @@ -221,6 +227,15 @@ if ($action == "change") { $json['errno'] = 1; $json['msg'] = "Invalid token."; } +} else if ($action == "logout") { + if (utils::getValue('token', $_SESSION)) { + session_destroy(); + $json['errno'] = 0; + $json['msg'] = 'Session destroyed.'; + } else { + $json['errno'] = 1; + $json['msg'] = 'No available session.'; + } } if (!$action) { diff --git a/assets/css/index.style.css b/assets/css/index.style.css index 0f9cf8bc..275e3ceb 100644 --- a/assets/css/index.style.css +++ b/assets/css/index.style.css @@ -2,7 +2,7 @@ * @Author: prpr * @Date: 2016-01-21 20:07:47 * @Last Modified by: prpr -* @Last Modified time: 2016-02-03 22:06:53 +* @Last Modified time: 2016-02-05 11:23:43 */ .home-menu-blur { position: absolute; @@ -109,7 +109,7 @@ } #msg { width: 50%; - margin: 3.5em auto 0; + margin: 4.3em auto 0; } .alert { padding: 15px 0; diff --git a/assets/css/user.style.css b/assets/css/user.style.css index 627c9f81..69b86e89 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-04 22:57:13 +* @Last Modified time: 2016-02-05 15:13:00 */ .home-menu-blur { @@ -84,7 +84,7 @@ span { display: inline !important; } .alert { - margin: 20px 0 0; + margin: 20px 0 10px; } input[type=radio] { margin: 20px 0 0; @@ -100,3 +100,6 @@ input[type=radio] { .container { position: initial !important; } +#skinpreview > p { + margin: 20px 0; +} diff --git a/assets/js/admin.utils.js b/assets/js/admin.utils.js index 1116f79e..386bd619 100644 --- a/assets/js/admin.utils.js +++ b/assets/js/admin.utils.js @@ -2,11 +2,23 @@ * @Author: prpr * @Date: 2016-02-04 16:48:42 * @Last Modified by: prpr -* @Last Modified time: 2016-02-04 18:27:44 +* @Last Modified time: 2016-02-05 15:52:32 */ 'use strict'; +function uploadSkin(uname) { + Ply.dialog("confirm", { + text: "Which model do you want to change?", + ok: "Steve", + cancel: "Alex" + }).done(function(){ + uploadTexture(uname, 'steve'); + }).fail(function(){ + uploadTexture(uname, 'alex'); + }); +} + function uploadTexture(uname, type) { var ply = new Ply({ el: '
Skin for Steve model:
').append($('Skin for Alex model:
').append($('Cape:
').append($('Just a simple open-source Minecraft skin server
diff --git a/user/index.php b/user/index.php index 7c75ac75..3dffdd19 100644 --- a/user/index.php +++ b/user/index.php @@ -30,7 +30,7 @@ if (isset($_SESSION['uname'])) { -Select a cape:
Your preference model is getPreference(); ?>. Change?
+