fix some bugs

This commit is contained in:
printempw 2016-02-02 21:52:53 +08:00
parent 844e67b4bc
commit b323675bdf
7 changed files with 34 additions and 174 deletions

View File

@ -3,48 +3,35 @@
* @Author: printempw
* @Date: 2016-01-16 23:01:33
* @Last Modified by: prpr
* @Last Modified time: 2016-01-21 18:20:46
* @Last Modified time: 2016-02-02 21:50:54
*
* All ajax requests will be handled here
*/
header('Access-Control-Allow-Origin: *');
session_start();
$dir = dirname(__FILE__);
require "$dir/includes/autoload.inc.php";
function __autoload($classname) {
$dir = dirname(__FILE__);
$filename = "$dir/includes/". $classname .".class.php";
include_once($filename);
}
function getValue($key, $array) {
if (array_key_exists($key, $array)) {
return $array[$key];
}
return false;
}
if ($uname = getValue('uname', $_POST)) {
if (isset($_POST['uname'])) {
$user = new user($uname);
} else {
utils::raise('1', 'Empty username.');
}
if (!($action = getValue('action', $_GET))) {
$action = "login";
}
$action = isset($_GET['action']) ? $_GET['action'] : "login";
$json = null;
if ($action == "login") {
if (checkInput()) {
if (!$user -> is_registered) {
if (!$user->is_registered) {
$json['errno'] = 1;
$json['msg'] = "Non-existent user.";
} else {
if ($user -> checkPasswd($_POST['passwd'])) {
if ($user->checkPasswd($_POST['passwd'])) {
$json['errno'] = 0;
$json['msg'] = 'Logging in succeed!';
$json['token'] = $user -> getToken();
$_SESSION['token'] = $user -> getToken();
$json['token'] = $user->getToken();
$_SESSION['token'] = $user->getToken();
} else {
$json['errno'] = 1;
$json['msg'] = "Incorrect usename or password.";
@ -53,7 +40,7 @@ if ($action == "login") {
}
} else if ($action == "register") {
if (checkInput()) {
if (!$user -> is_registered) {
if (!$user->is_registered) {
if (!empty($_SERVER['HTTP_CLIENT_IP'])) {
$ip = $_SERVER['HTTP_CLIENT_IP'];
} elseif (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) {
@ -64,7 +51,7 @@ if ($action == "login") {
if (!utils::select('ip', $ip)) {
// use once md5 to encrypt password
if ($user -> register(md5($_POST['passwd']), $ip)) {
if ($user->register(md5($_POST['passwd']), $ip)) {
$json['errno'] = 0;
$json['msg'] = "Registered successfully.";
} else {
@ -82,10 +69,10 @@ if ($action == "login") {
}
}
} else if ($action == "upload") {
if ($_SESSION['token'] == $user -> getToken()) {
if ($_SESSION['token'] == $user->getToken()) {
if (checkFile()) {
if ($file = getValue('skin_file', $_FILES)) {
if ($user -> setTexture('skin', $file)) {
if ($file = utils::getValue('skin_file', $_FILES)) {
if ($user->setTexture('skin', $file)) {
$json[0]['errno'] = 0;
$json[0]['msg'] = "Skin uploaded successfully.";
} else {
@ -93,8 +80,8 @@ if ($action == "login") {
$json[0]['msg'] = "Uncaught error.";
}
}
if ($file = getValue('cape_file', $_FILES)) {
if ($user -> setTexture('cape', $file)) {
if ($file = utils::getValue('cape_file', $_FILES)) {
if ($user->setTexture('cape', $file)) {
$json[1]['errno'] = 0;
$json[1]['msg'] = "Cape uploaded successfully.";
} else {
@ -108,7 +95,7 @@ if ($action == "login") {
$json['msg'] = "Invalid token.";
}
} else if ($action == "logout") {
if (getValue('token', $_SESSION)) {
if (utils::getValue('token', $_SESSION)) {
session_destroy();
$json['errno'] = 0;
$json['msg'] = 'Session destroyed.';
@ -136,7 +123,7 @@ function checkInput() {
function checkFile() {
global $json;
if (!(getValue('skin_file', $_FILES) || getValue('cape_file', $_FILES))) {
if (!(utils::getValue('skin_file', $_FILES) || utils::getValue('cape_file', $_FILES))) {
$json['errno'] = 1;
$json['msg'] = "No input file selected.";
return false;
@ -144,15 +131,15 @@ function checkFile() {
/**
* Check for skin_file
*/
if ((getValue('skin_file', $_FILES)["type"] == "image/png") || (getValue('skin_file', $_FILES)["type"] == "image/x-png")) {
if ((utils::getValue('skin_file', $_FILES)["type"] == "image/png") || (utils::getValue('skin_file', $_FILES)["type"] == "image/x-png")) {
// if error occured while uploading file
if (getValue('skin_file', $_FILES)["error"] > 0) {
if (utils::getValue('skin_file', $_FILES)["error"] > 0) {
$json['errno'] = 1;
$json['msg'] = getValue('skin_file', $_FILES)["error"];
$json['msg'] = utils::getValue('skin_file', $_FILES)["error"];
return false;
}
} else {
if (getValue('skin_file', $_FILES)) {
if (utils::getValue('skin_file', $_FILES)) {
$json['errno'] = 1;
$json['msg'] = 'Skin file type error.';
return false;
@ -165,15 +152,15 @@ function checkFile() {
/**
* Check for cape_file
*/
if ((getValue('cape_file', $_FILES)["type"] == "image/png") || (getValue('cape_file', $_FILES)["type"] == "image/x-png")) {
if ((utils::getValue('cape_file', $_FILES)["type"] == "image/png") || (utils::getValue('cape_file', $_FILES)["type"] == "image/x-png")) {
// if error occured while uploading file
if (getValue('cape_file', $_FILES)["error"] > 0) {
if (utils::getValue('cape_file', $_FILES)["error"] > 0) {
$json['errno'] = 1;
$json['msg'] = getValue('cape_file', $_FILES)["error"];
$json['msg'] = utils::getValue('cape_file', $_FILES)["error"];
return false;
}
} else {
if (getValue('cape_file', $_FILES)) {
if (utils::getValue('cape_file', $_FILES)) {
$json['errno'] = 1;
$json['msg'] = 'Cape file type error.';
return false;

View File

@ -2,7 +2,7 @@
* @Author: prpr
* @Date: 2016-01-21 20:07:47
* @Last Modified by: prpr
* @Last Modified time: 2016-01-21 21:09:54
* @Last Modified time: 2016-02-02 21:44:58
*/
.home-menu-blur {
position: absolute;
@ -17,7 +17,7 @@
background-color: rgba(255,255,255,0.4);
}
.home-menu-bg {
background-image: url("http://ww4.sinaimg.cn/large/823186a6gw1enwts09sbrj21hc0u016u.jpg");
background-image: url("../images/bg.jpg");
background-position: center 0;
background-size: auto 800px;
position: absolute;
@ -34,8 +34,7 @@
.container {
background-image:
url("http://ww4.sinaimg.cn/large/823186a6gw1enwts09sbrj21hc0u016u.jpg");
/* background-size: cover; */
url("../images/bg.jpg");
background-size: auto 800px;
background-repeat: no-repeat;
background-position: center 0;

View File

@ -1,123 +0,0 @@
@font-face {
font-family: 'Minecraft';
src: url('../fonts/minecraft.eot');
src: url('../fonts/minecraft.eot') format('embedded-opentype'),
url('../fonts/minecraft.woff2') format('woff2'),
url('../fonts/minecraft.woff') format('woff'),
url('../fonts/minecraft.ttf') format('truetype'),
url('../fonts/minecraft.svg#minecraft') format('svg');
}
body {
background-image: url(../images/bg_stone.png);
background-repeat: repeat;
}
.copy {
color: #FFFFFF;
}
img.l {
width: 44%;
margin-left: 10%;
}
.navbar {
border-radius: 0;
}
.navbar-default {
background-color: rgba(255,255,255,.9);
border-color: transparent;
box-shadow: rgba(0,0,0,0.1) 0 1px 2px;
}
.l {
float: left;
}
.r {
float: right;
margin-top: 20px;
}
.login-container, .upload-container {
margin-top: 8%;
margin-right: 10%;
border: #989898 1px solid;
border-radius: 4px;
width: 300px;
padding: 40px 40px 40px 40px;
background: rgba(255,255,255,.9);
}
.input-group {
margin: 20px 0 20px 0;
}
.login-group {
height: 40px;
}
div .keep {
float: left;
}
#login {
float: right;
}
#login-form {
margin-top: 10px;
}
.login-title, .upload-title {
font-family: Minecraft;
margin: 5px 0 30px 0;
}
.checkbox-wrapper {
float: left;
position: relative;
top: 15%;
}
.checkbox {
display: none;
}
label {
width: 18px;
height: 18px;
background: #fff;
border: 1px solid #e5e6e7;
margin-bottom: -3px;
border-radius: 2px;
cursor: pointer;
display: inline-block;
}
.checkbox:checked+label {
background: url(../images/check.png);
}
footer {
text-align: center;
color: #FFFFFF;
position: absolute;
width: 100%;
top: 95%;
}
.hide {
display: none;
}
.alert {
margin-bottom: 0px;
margin-top: 10px;
}
#canvas3d {
margin-left: 30%;
}

BIN
assets/images/bg.jpg Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 518 KiB

View File

@ -2,7 +2,7 @@
* @Author: prpr
* @Date: 2016-01-21 13:55:44
* @Last Modified by: prpr
* @Last Modified time: 2016-01-22 15:03:08
* @Last Modified time: 2016-02-02 21:41:26
*/
'use strict';
@ -66,6 +66,7 @@ $("body").on("click", "#register-button", function(){
$('[data-remodal-id=register-modal]').remodal().close();
showMsg('hide', "");
} else {
showMsg('hide', "");
showAlert(json.msg);
}
}

View File

@ -3,7 +3,7 @@
* @Author: printempw
* @Date: 2016-01-16 23:01:33
* @Last Modified by: prpr
* @Last Modified time: 2016-02-02 21:31:36
* @Last Modified time: 2016-02-02 21:38:22
*/
class user {
@ -73,6 +73,7 @@ class user {
$data = fread(fopen($filename, 'r'), filesize($filename));
return $data;
} else {
header('Content-type: application/json');
utils::raise(-1, 'Texture no longer exists.');
}
}

View File

@ -7,12 +7,7 @@
*/
session_start();
$dir = dirname(dirname(__FILE__));
function __autoload($classname) {
global $dir;
$filename = "$dir/includes/". $classname .".class.php";
include_once($filename);
}
require "$dir/includes/autoload.inc.php";
$action = utils::getValue('action', $_GET);