added url route

This commit is contained in:
printempw 2016-01-22 14:47:18 +08:00
parent 156d278b7a
commit 1d0e35b646
5 changed files with 185 additions and 132 deletions

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 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);
}

View File

@ -3,13 +3,14 @@
* @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;
@ -23,6 +24,7 @@ class user {
$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'];
}
}
@ -60,6 +62,12 @@ class user {
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") {
@ -74,5 +82,23 @@ class user {
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);
}
}
?>

View File

@ -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;
}
}
?>

136
index.php
View File

@ -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();
function __autoload($classname) {
$dir = dirname(__FILE__);
function __autoload($classname) {
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.');
}
function getValue($key, $array) {
if (array_key_exists($key, $array)) {
return $array[$key];
} else {
include("$dir/templates/index.inc.php");
}
return false;
}
?>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Home - Blessing Skin Server</title>
<link rel="stylesheet" href="./libs/pure/pure-min.css">
<link rel="stylesheet" href="./libs/pure/grids-responsive-min.css">
<link rel="stylesheet" href="./assets/css/style.css">
<link rel="stylesheet" href="./assets/css/index.style.css">
<link rel="stylesheet" href="./libs/remodal/remodal.css">
<link rel="stylesheet" href="./libs/ply/ply.css">
<link rel="stylesheet" href="./libs/remodal/remodal-default-theme.css">
</head>
<body>
<div class="header">
<div class="home-menu pure-menu pure-menu-horizontal pure-menu-fixed">
<a class="pure-menu-heading" href="#">Blessing Skin Server</a>
<ul class="pure-menu-list">
<li class="pure-menu-item pure-menu-selected">
<a href="#" class="pure-menu-link">Home</a>
</li>
<li class="pure-menu-item">
<?php
if ($uname = getValue('uname', $_SESSION)) { ?>
<a href="./user/index.php" class="pure-menu-link" style="color: #5e5e5e">Welcome, <?php echo $uname; ?></a>
<?php } else { ?>
<a id="login" href="javascript:;" class="pure-button pure-button-primary">Sign In</a>
<?php } ?>
</li>
</ul>
<div class="home-menu-blur">
<div class="home-menu-wrp">
<div class="home-menu-bg"></div>
</div>
</div>
</div>
</div>
<div class="container">
<div class="splash">
<h1 class="splash-head">Blessing Skin Server</h1>
<p class="splash-subhead">
Just a simple open-source Minecraft skin server
</p>
<?php
if (!getValue('uname', $_SESSION)) { ?>
<p>
<a id="register" href="javascript:;" class="pure-button pure-button-primary">Sign Up</a>
</p>
<?php } ?>
</div>
</div>
<div class="footer">
&copy; <a class="copy" href="https://prinzeugen.net">Blessing Studio</a> 2016
</div>
<div class="remodal" data-remodal-id="login-modal">
<button data-remodal-action="close" class="remodal-close"></button>
<h1 id="login-title">Sign In</h1>
<div class="pure-form">
<input class="pure-input" id="uname" type="text" placeholder="Username">
<input class="pure-input" id="passwd" type="password" placeholder="Password">
<br />
<label for="keep" id="keep-label">
<input id="keep" type="checkbox"> Remember me
</label>
<button id="login-button" class="pure-button pure-button-primary">Sign In</button>
</div>
<div id="msg" class="alert"></div>
</div>
<div class="remodal" data-remodal-id="register-modal">
<button data-remodal-action="close" class="remodal-close"></button>
<h1 id="register-title">Sign Up</h1>
<div class="pure-form">
<input class="pure-input" id="reg-uname" type="text" placeholder="Username">
<input class="pure-input" id="reg-passwd" type="password" placeholder="Password">
<input class="pure-input" id="reg-passwd2" type="password" placeholder="Comfirm Password">
<br />
<button id="register-button" class="pure-button pure-button-primary">Sign Up</button>
</div>
<div id="msg" class="alert"></div>
</div>
<script src="./libs/jquery/jquery-2.1.1.min.js"></script>
<script src="./libs/cookie.js"></script>
<script src="./libs/remodal/remodal.min.js"></script>
<script src="./libs/ply/ply.min.js"></script>
<script src="./assets/js/index.utils.js"></script>
<?php
if ($msg = getValue('msg', $_GET)) { ?>
<script type="text/javascript">
showAlert("<?php echo $msg; ?>");
</script>
<?php } ?>
</body>
</html>

117
templates/index.inc.php Normal file
View File

@ -0,0 +1,117 @@
<?php
/**
* @Author: prpr
* @Date: 2016-01-22 13:26:39
* @Last Modified by: prpr
* @Last Modified time: 2016-01-22 13:41:46
*/
session_start();
if (utils::getValue('uname', $_COOKIE) && utils::getValue('token', $_COOKIE)) {
$user = new user($_COOKIE['uname']);
if ($_COOKIE['token'] == $user -> getToken()) {
$_SESSION['uname'] = $_COOKIE['uname'];
$_SESSION['token'] = $user -> getToken();
}
}
?>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Home - Blessing Skin Server</title>
<link rel="stylesheet" href="./libs/pure/pure-min.css">
<link rel="stylesheet" href="./libs/pure/grids-responsive-min.css">
<link rel="stylesheet" href="./assets/css/style.css">
<link rel="stylesheet" href="./assets/css/index.style.css">
<link rel="stylesheet" href="./libs/remodal/remodal.css">
<link rel="stylesheet" href="./libs/ply/ply.css">
<link rel="stylesheet" href="./libs/remodal/remodal-default-theme.css">
</head>
<body>
<div class="header">
<div class="home-menu pure-menu pure-menu-horizontal pure-menu-fixed">
<a class="pure-menu-heading" href="#">Blessing Skin Server</a>
<ul class="pure-menu-list">
<li class="pure-menu-item pure-menu-selected">
<a href="#" class="pure-menu-link">Home</a>
</li>
<li class="pure-menu-item">
<?php
if ($uname = utils::getValue('uname', $_SESSION)) { ?>
<a href="./user/index.php" class="pure-menu-link" style="color: #5e5e5e">Welcome, <?php echo $uname; ?></a>
<?php } else { ?>
<a id="login" href="javascript:;" class="pure-button pure-button-primary">Sign In</a>
<?php } ?>
</li>
</ul>
<div class="home-menu-blur">
<div class="home-menu-wrp">
<div class="home-menu-bg"></div>
</div>
</div>
</div>
</div>
<div class="container">
<div class="splash">
<h1 class="splash-head">Blessing Skin Server</h1>
<p class="splash-subhead">
Just a simple open-source Minecraft skin server
</p>
<?php
if (!utils::getValue('uname', $_SESSION)) { ?>
<p>
<a id="register" href="javascript:;" class="pure-button pure-button-primary">Sign Up</a>
</p>
<?php } ?>
</div>
</div>
<div class="footer">
&copy; <a class="copy" href="https://prinzeugen.net">Blessing Studio</a> 2016
</div>
<div class="remodal" data-remodal-id="login-modal">
<button data-remodal-action="close" class="remodal-close"></button>
<h1 id="login-title">Sign In</h1>
<div class="pure-form">
<input class="pure-input" id="uname" type="text" placeholder="Username">
<input class="pure-input" id="passwd" type="password" placeholder="Password">
<br />
<label for="keep" id="keep-label">
<input id="keep" type="checkbox"> Remember me
</label>
<button id="login-button" class="pure-button pure-button-primary">Sign In</button>
</div>
<div id="msg" class="alert"></div>
</div>
<div class="remodal" data-remodal-id="register-modal">
<button data-remodal-action="close" class="remodal-close"></button>
<h1 id="register-title">Sign Up</h1>
<div class="pure-form">
<input class="pure-input" id="reg-uname" type="text" placeholder="Username">
<input class="pure-input" id="reg-passwd" type="password" placeholder="Password">
<input class="pure-input" id="reg-passwd2" type="password" placeholder="Comfirm Password">
<br />
<button id="register-button" class="pure-button pure-button-primary">Sign Up</button>
</div>
<div id="msg" class="alert"></div>
</div>
<script src="./libs/jquery/jquery-2.1.1.min.js"></script>
<script src="./libs/cookie.js"></script>
<script src="./libs/remodal/remodal.min.js"></script>
<script src="./libs/ply/ply.min.js"></script>
<script src="./assets/js/index.utils.js"></script>
<?php
if ($msg = utils::getValue('msg', $_GET)) { ?>
<script type="text/javascript">
showAlert("<?php echo $msg; ?>");
</script>
<?php } ?>
</body>
</html>