From 1d0e35b6465e1034bfc33065bdd66b83752ba636 Mon Sep 17 00:00:00 2001 From: printempw Date: Fri, 22 Jan 2016 14:47:18 +0800 Subject: [PATCH] added url route --- assets/js/index.utils.js | 3 +- includes/user.class.php | 56 +++++++++++----- includes/utils.class.php | 3 +- index.php | 138 +++++++-------------------------------- templates/index.inc.php | 117 +++++++++++++++++++++++++++++++++ 5 files changed, 185 insertions(+), 132 deletions(-) create mode 100644 templates/index.inc.php diff --git a/assets/js/index.utils.js b/assets/js/index.utils.js index 4c1046f2..759884ce 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-22 11:14:09 +* @Last Modified time: 2016-01-22 14:32:22 */ 'use strict'; @@ -63,6 +63,7 @@ $("body").on("click", "#register-button", function(){ success: function(json) { if (json.errno == 0) { showAlert(json.msg + " Please log in."); + $('[data-remodal-id=register-modal]').remodal().close(); } else { showAlert(json.msg); } diff --git a/includes/user.class.php b/includes/user.class.php index d8274eb0..6e8ce34f 100644 --- a/includes/user.class.php +++ b/includes/user.class.php @@ -3,31 +3,33 @@ * @Author: printempw * @Date: 2016-01-16 23:01:33 * @Last Modified by: prpr - * @Last Modified time: 2016-01-21 22:33:37 + * @Last Modified time: 2016-01-22 14:31:18 */ class user { private $uname = ""; private $passwd = ""; private $token = ""; + private $preference = ""; public $is_registered = false; public $is_admin = false; function __construct($uname) { - $this -> uname = utils::convertString($uname); - if (utils::select('username', $this -> uname)['uid'] == 1) { - $this -> is_admin = true; + $this->uname = utils::convertString($uname); + if (utils::select('username', $this->uname)['uid'] == 1) { + $this->is_admin = true; } - if (utils::select('username', $this -> uname)['password'] != "") { - $this -> passwd = utils::select('username', $this -> uname)['password']; - $this -> is_registered = true; - $this -> token = md5($this -> uname.$this -> passwd.SALT); + if (utils::select('username', $this->uname)['password'] != "") { + $this->passwd = utils::select('username', $this->uname)['password']; + $this->is_registered = true; + $this->token = md5($this->uname . $this->passwd.SALT); + $this->preference = utils::select('username', $this->uname)['preference']; } } public function checkPasswd($raw_passwd) { - if (md5($raw_passwd) == $this -> passwd) { + if (md5($raw_passwd) == $this->passwd) { return true; } else { return false; @@ -35,12 +37,12 @@ class user { } public function getToken() { - return $this -> token; + return $this->token; } public function register($passwd, $ip) { if (utils::insert(array( - "uname" => $this -> uname, + "uname" => $this->uname, "passwd" => $passwd, "ip" => $ip ))) @@ -53,26 +55,50 @@ class user { public function getTexture($type) { if ($type == "skin") { - return utils::select('username', $this -> uname)['skin_hash']; + return utils::select('username', $this->uname)['skin_hash']; } else if ($type == "cape") { - return utils::select('username', $this -> uname)['cape_hash']; + return utils::select('username', $this->uname)['cape_hash']; } return false; } + public function getBinaryTexture($type) { + $filename = "./textures/".$this->getTexture($type); + $data = fread(fopen($filename, 'r'), filesize($filename)); + return $data; + } + public function setTexture($type, $file) { $hash = utils::upload($file); if ($type == "skin") { // remove the original texture first utils::remove("./textures/".$this->getTexture('skin')); - return utils::update($this -> uname, 'skin_hash', $hash); + return utils::update($this->uname, 'skin_hash', $hash); echo "shit"; } else if ($type == "cape") { utils::remove("./textures/".$this->getTexture('cape')); - return utils::update($this -> uname, 'cape_hash', $hash); + return utils::update($this->uname, 'cape_hash', $hash); } return false; } + public function getJsonProfile() { + if ($this->is_registered) { + $json['player_name'] = $this->uname; + if ($this->preference == "slim") { + $json['model_preference'] = ['slim','default']; + $json['skins']['slim'] = $this->getTexture('skin'); + } else { + $json['model_preference'] = ['default']; + $json['skins']['default'] = $this->getTexture('skin'); + } + $json['cape'] = $this->getTexture('cape'); + } else { + $json['errno'] = 1; + $json['msg'] = "Non-existent user."; + } + return json_encode($json); + } + } ?> diff --git a/includes/utils.class.php b/includes/utils.class.php index 7fd65ca6..1c87fad4 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-01-21 22:26:07 + * @Last Modified time: 2016-01-22 14:11:23 */ $dir = dirname(dirname(__FILE__)); require "$dir/config.php"; @@ -141,5 +141,6 @@ class utils { } return false; } + } ?> diff --git a/index.php b/index.php index db1d5560..18b50261 100755 --- a/index.php +++ b/index.php @@ -3,125 +3,33 @@ * @Author: printempw * @Date: 2016-01-17 13:55:20 * @Last Modified by: prpr - * @Last Modified time: 2016-01-22 11:14:35 + * @Last Modified time: 2016-01-22 14:42:56 */ -session_start(); + +$dir = dirname(__FILE__); + function __autoload($classname) { - $dir = dirname(__FILE__); + global $dir; $filename = "$dir/includes/". $classname .".class.php"; include_once($filename); } -if (getValue('uname', $_COOKIE) && getValue('token', $_COOKIE)) { - $user = new user($_COOKIE['uname']); - if ($_COOKIE['token'] == $user -> getToken()) { - $_SESSION['uname'] = $_COOKIE['uname']; - $_SESSION['token'] = $user -> getToken(); + +if ($_GET['action'] == "get") { + if ($_GET['type'] && $_GET['uname']) { + $user = new user($_GET['uname']); + if ($_GET['type'] == "skin") { + header('Content-Type: image/png'); + echo $user->getBinaryTexture('skin'); + } else if ($_GET['type'] == "cape") { + header('Content-Type: image/png'); + echo $user->getBinaryTexture('cape'); + } else { + header('Content-type: application/json'); + echo $user->getJsonProfile(); + } + } else { + utils::raise(1, 'Illegal parameters.'); } +} else { + include("$dir/templates/index.inc.php"); } -function getValue($key, $array) { - if (array_key_exists($key, $array)) { - return $array[$key]; - } - return false; -} -?> - - - - - - Home - Blessing Skin Server - - - - - - - - - - -
-
- Blessing Skin Server - -
-
-
-
-
-
-
- -
-
-

Blessing Skin Server

-

- Just a simple open-source Minecraft skin server -

- -

- Sign Up -

- -
-
- - - -
- -

Sign In

-
- - -
- - -
-
-
- -
- -

Sign Up

-
- - - -
- -
-
-
- - - - - - - - - - - diff --git a/templates/index.inc.php b/templates/index.inc.php new file mode 100644 index 00000000..a4a6eb62 --- /dev/null +++ b/templates/index.inc.php @@ -0,0 +1,117 @@ + getToken()) { + $_SESSION['uname'] = $_COOKIE['uname']; + $_SESSION['token'] = $user -> getToken(); + } +} +?> + + + + + + Home - Blessing Skin Server + + + + + + + + + + +
+
+ Blessing Skin Server + +
+
+
+
+
+
+
+ +
+
+

Blessing Skin Server

+

+ Just a simple open-source Minecraft skin server +

+ +

+ Sign Up +

+ +
+
+ + + +
+ +

Sign In

+
+ + +
+ + +
+
+
+ +
+ +

Sign Up

+
+ + + +
+ +
+
+
+ + + + + + + + + + +