6 커밋 ce8e378890 ... a0ea45f3f0

작성자 SHA1 메시지 날짜
  Ecconia a0ea45f3f0 Adding request for single app 7 년 전
  Ecconia 7966f286a0 Formatting 7 년 전
  Ecconia e4a77bd9d0 Backend Application getters 7 년 전
  Ecconia 5c6622de0f Adding Namespaces 7 년 전
  Ecconia a4a078cabb Adding /devblog 7 년 전
  Ecconia e0b5228f4d Check if HTTP_ORIGIN is set 7 년 전
11개의 변경된 파일451개의 추가작업 그리고 105개의 파일을 삭제
  1. 6 0
      composer.json
  2. 18 14
      dist/index.php
  3. 0 39
      handler/AuthHandler.php
  4. 0 41
      handler/MyHandler.php
  5. 70 0
      src/Application/AppPattern.php
  6. 51 0
      src/Application/Application.php
  7. 103 0
      src/DummyData.php
  8. 39 0
      src/Handler/AuthHandler.php
  9. 138 0
      src/Handler/MyHandler.php
  10. 15 11
      middleware/CorsHeader.php
  11. 11 0
      src/User.php

+ 6 - 0
composer.json

@@ -8,5 +8,11 @@
 
 	"require": {
 		"adeptoas/slim3-init": "^1.0.0"
+	},
+
+	"autoload": {
+		"psr-4": {
+			"RS\\": "src/"
+		}
 	}
 }

+ 18 - 14
dist/index.php

@@ -1,15 +1,19 @@
 <?php
-	require __DIR__ . '/../vendor/autoload.php';
-	require __DIR__ . '/../middleware/CorsHeader.php';
-
-	use Adepto\Slim3Init\{
-		SlimInit
-	};
-
-	$slim = new SlimInit();
-	$slim
-		->addHandlersFromDirectory(__DIR__ . '/../handler')
-		->addMiddleware(new CorsHeader(), 'Cors Header')
-		//One of the two preconditions to get more details on requests.
-		//->setDebugHeader('Debug', '1')
-		->run();
+
+ini_set('display_errors', 1);
+ini_set('display_startup_errors', 1);
+error_reporting(E_ALL);
+
+require __DIR__ . '/../vendor/autoload.php';
+
+use RS\Middleware\CorsHeader;
+
+use Adepto\Slim3Init\SlimInit;
+
+$slim = new SlimInit();
+$slim
+	->addHandlersFromDirectory(__DIR__ . '/../src/Handler')
+	->addMiddleware(new CorsHeader(), 'Cors Header')
+	//One of the two preconditions to get more details on requests.
+	//->setDebugHeader('Debug', '1')
+	->run();

+ 0 - 39
handler/AuthHandler.php

@@ -1,39 +0,0 @@
-<?php
-	use Adepto\Slim3Init\HandlerCaller;
-
-	use Adepto\Slim3Init\{
-		Handlers\Handler,
-		Handlers\Route
-	};
-
-	use Psr\Http\Message\{
-		ServerRequestInterface,
-		ResponseInterface
-	};
-
-	class AuthHandler extends Handler {
-		public function login(ServerRequestInterface $request, ResponseInterface $response, \stdClass $args): ResponseInterface {
-
-			$parsedBody = $request->getParsedBody();
-
-			$username = $parsedBody['username'];
-			$password = $parsedBody['password'];
-
-			//TODO: Confirm that someone is not sending garbage.
-			// - There may only be the keys username and password - optional token
-			// - None of the two/three fields may be empty.
-
-			//TODO: Check username for allowed chars and length.
-
-			$user['username'] = $username;
-			$user['appstate'] = 0;
-
-			return $response->withJson($user);
-		}
-
-		public static function getRoutes(): array {
-			return [
-				new Route('POST', '/login', 'login'),
-			];
-		}
-	}

+ 0 - 41
handler/MyHandler.php

@@ -1,41 +0,0 @@
-<?php
-	use Adepto\Slim3Init\HandlerCaller;
-
-	use Adepto\Slim3Init\{
-		Handlers\Handler,
-		Handlers\Route
-	};
-
-	use Psr\Http\Message\{
-		ServerRequestInterface,
-		ResponseInterface
-	};
-
-	class MyHandler extends Handler {
-		public function soos(ServerRequestInterface $request, ResponseInterface $response, \stdClass $args): ResponseInterface {
-			$lel[] = 'A';
-			$lel[] = 'B';
-			$lel[] = 'C';
-
-			$lal['t'] = 'A';
-			$lal['tt'] = 'B';
-			$lal['ttt'] = 'C';
-			$lal['tttt'] = 'D';
-
-			$lol['a'] = $lel;
-			$lol['b'] = $lal;
-
-			return $response->withJson($lol);
-		}
-
-		public function error(ServerRequestInterface $request, ResponseInterface $response, \stdClass $args): ResponseInterface {
-			throw new Error('Lol', 42);
-		}
-
-		public static function getRoutes(): array {
-			return [
-				new Route('GET', '/soos', 'soos'),
-				new Route('GET', '/error', 'error'),
-			];
-		}
-	}

+ 70 - 0
src/Application/AppPattern.php

@@ -0,0 +1,70 @@
+<?php
+
+namespace RS\Application;
+
+class AppPattern {
+	public $instruction;
+	public $fields;
+
+	function __construct() {
+		$this->instruction = 'First impressions are important. Please tell us about yourself. A well-written application is likely to speed up your approval on the server, while a poorly written one might not get approved at all. 2-3 well-written sentences per question is recommended.';
+		
+		$this->fields = json_decode('[
+				{
+					"text": "Country?",
+					"hint": "Where are you from? Just the continent is fine. Please leave blank if you don\"t want to tell us!",
+					"type": "line",
+					"optional": true
+				},
+				{
+					"text": "Age?",
+					"hint": "How old are you? Please leave blank if you don\'t want to tell us!",
+					"type": "age",
+					"optional": true
+				},
+				{
+					"text": "About how often do you play Minecraft?",
+					"optional": true,
+					"type": "hours-per"
+				},
+				{
+					"text": "Why are you interested in joining this server?",
+					"hint": "Why would you like to join this server? What can you offer to others on the server? What can this server offer you that other servers can not? Please describe in detail.",
+					"optional": false,
+					"type": "text-box-limited"
+				},
+				{
+					"text": "Current Redstone knowledge",
+					"hint": "What are your current limits in redstone? Tell us anything you know concerning redstone.",
+					"optional": false,
+					"type": "text-box-limited"
+				},
+				{
+					"text": "Past Redstone Experience",
+					"hint": "Describe your best Redstone creation(s) to date. Tell us how they work and what kind of Redstone logic was used.",
+					"optional": false,
+					"type": "text-box-limited"
+				},
+				{
+					"text": "What kind of creations would you like to build on this server?",
+					"hint": "Describe what sort of creations you will try to be building on this server.",
+					"optional": false,
+					"type": "text-box"
+				},
+				{
+					"text": "Links to your work:",
+					"hint": "Include screenshots/videos of your previous work. These links will not be released to anyone but the application appraisers.",
+					"optional": true,
+					"hidden": true,
+					"type": "links"
+				},
+				{
+					"text": "Anything else you\'d like to mention",
+					"hint": "Have any opinions? Any extra information?",
+					"optional": true,
+					"type": "text-box"
+				}
+			]'
+		, true);
+	}
+}

+ 51 - 0
src/Application/Application.php

@@ -0,0 +1,51 @@
+<?php
+
+namespace RS\Application;
+
+use RS\Application\AppPattern;
+use RS\User;
+
+class Application {
+	public $user;
+	public $pattern;
+	public $answers;
+	public $state;
+	public $time;
+
+	function __construct(User $user, AppPattern $pattern, int $time, Array $answers, $state) {
+		$this->user = $user;
+		$this->pattern = $pattern;
+		$this->answers = $answers;
+		$this->time = $time;
+		$this->state = $state;
+	}
+
+	public function fullCompile() {
+		$application['username'] = $this->user->username;
+
+		for($i = 0; $i < sizeof($this->answers); $i++) {
+			$fields[$this->pattern->fields[$i]['text']] = $this->answers[$i];
+		}
+		$application['fields'] = $fields;
+
+		$application['time'] = $this->time;
+
+		if($this->state >= 0) {
+			$application['state'] = $this->state > 0 ? true : false;
+		}
+
+		return $application;
+	}
+
+	public function viewCompile() {
+		$application['username'] = $this->user->username;
+
+		$application['time'] = $this->time;
+
+		if(isset($this->state)) {
+			$application['state'] = $this->state > 0 ? true : false;
+		}
+
+		return $application;
+	}
+}

+ 103 - 0
src/DummyData.php

@@ -0,0 +1,103 @@
+<?php
+
+namespace RS;
+
+use RS\Application\AppPattern;
+use RS\Application\Application;
+use RS\User;
+
+class DummyData {
+	public static function dummyBase() {
+		$devPattern = new AppPattern();
+
+		$applications[] = new Application(new User('Joke'), $devPattern, 1439202084, [
+			'LalaLand', # Country
+			'69', # Age
+			'Play always', # Addiction
+			'Cause banned on all de other crap servers', # Why joining this server?
+			'I am betta den all you, i swear!', # Your current rs knowledge?
+			'm3m3g3n3r4t0r gud redstoned', # Stuff you built in the past?
+			'Betta shiet', # What you gonna build?
+			'admin@p', # Links?
+			'U all smoke ganja!', # Wanna mention something?
+		], false);
+
+		$applications[] = new Application(new User('Josh (KingTempest07)'), $devPattern, 1528202084, [
+			'', # Country
+			'11', # Age
+			'1-5 hours per day', # Addiction
+			'I love redstone, and I am not the best, at all, but I am trying to learn, so I thought maybe a server with some good redstone engineers could help! Also, I have no online friends, really, just real life, so I have been looking for servers on many different games, like: Terraria, Minecraft, etc.', # Why joining this server?
+			'Let\'s just say, I\'m terrible. I watch tons of Mumbo Jumbo, which is both entertaining and helpful, but I am still better at building than redstone. I know how to do things like: minecart systems, pulse extenders, double piston extenders, monostable circuits, some piston doors, do slab/redstone torch elevators, etc., but I can\'t really find was to compact or combine them easily!', # Your current rs knowledge?
+			'I have made 2x2 piston doors with pressure plates on both sides, and only used around a 8x3 block area with redstone torch elevators, and I can also make some simple things, like item transport systems with water and ice, hoppers, and I\'m not that good with storage systems, but I\'m getting there!', # Stuff you built in the past?
+			'Maybe some mob farms, storage systems, and minigames, but not so soon for minigames, but I might get there!', # What you gonna build?
+			'', # Links?
+			'', # Wanna mention something else?
+		], true);
+
+		$applications[] = new Application(new User('Jack'), $devPattern, 1529202084, [
+			'', # Country
+			'', # Age
+			'', # Addiction
+			'', # Why joining this server?
+			'', # Your current rs knowledge?
+			'', # Stuff you built in the past?
+			'', # What you gonna build?
+			'', # Links?
+			'', # Wanna mention something?
+		], false);
+
+		$applications[] = new Application(new User('John'), $devPattern, 1539102084, [
+			'', # Country
+			'', # Age
+			'', # Addiction
+			'', # Why joining this server?
+			'', # Your current rs knowledge?
+			'', # Stuff you built in the past?
+			'', # What you gonna build?
+			'', # Links?
+			'', # Wanna mention something?
+		], false);
+
+		$applications[] = new Application(new User('Jeff'), $devPattern, 1539202084, [
+			'', # Country
+			'', # Age
+			'', # Addiction
+			'', # Why joining this server?
+			'', # Your current rs knowledge?
+			'', # Stuff you built in the past?
+			'', # What you gonna build?
+			'', # Links?
+			'', # Wanna mention something?
+		], null);
+
+		return $applications;
+	}
+
+	public static function getDummyData() {
+		$applications = self::dummyBase();
+
+		//Add dummy ID's
+		for($i = 0; $i < sizeof($applications); $i++) {
+			$app = $applications[$i]->fullCompile();
+			$app['id'] = $i;
+
+			$compiledApps[] = $app;
+		}
+
+		return $compiledApps;
+	}
+
+	public static function getViewDummies() {
+		$applications = self::dummyBase();
+
+		//Add dummy ID's
+		for($i = 0; $i < sizeof($applications); $i++) {
+			$app = $applications[$i]->viewCompile();
+			$app['id'] = $i;
+
+			$compiledApps[] = $app;
+		}
+
+		return $compiledApps;
+	}
+}

+ 39 - 0
src/Handler/AuthHandler.php

@@ -0,0 +1,39 @@
+<?php
+
+use Adepto\Slim3Init\HandlerCaller;
+
+use Adepto\Slim3Init\Handlers\{
+	Handler,
+	Route
+};
+
+use Psr\Http\Message\{
+	ServerRequestInterface,
+	ResponseInterface
+};
+
+class AuthHandler extends Handler {
+	public function login(ServerRequestInterface $request, ResponseInterface $response, \stdClass $args): ResponseInterface {
+		$parsedBody = $request->getParsedBody();
+
+		$username = $parsedBody['username'];
+		$password = $parsedBody['password'];
+
+		//TODO: Confirm that someone is not sending garbage.
+		// - There may only be the keys username and password - optional token
+		// - None of the two/three fields may be empty.
+
+		//TODO: Check username for allowed chars and length.
+
+		$user['username'] = $username;
+		$user['appstate'] = 0;
+
+		return $response->withJson($user);
+	}
+
+	public static function getRoutes(): array {
+		return [
+			new Route('POST', '/login', 'login'),
+		];
+	}
+}

+ 138 - 0
src/Handler/MyHandler.php

@@ -0,0 +1,138 @@
+<?php
+
+use Adepto\Slim3Init\HandlerCaller;
+
+use Adepto\Slim3Init\Handlers\{
+	Handler,
+	Route
+};
+
+use Adepto\Slim3Init\Exceptions\InvalidRequestException;
+
+use Psr\Http\Message\{
+	ServerRequestInterface,
+	ResponseInterface
+};
+
+use RS\DummyData;
+
+class MyHandler extends Handler {
+	public function soos(ServerRequestInterface $request, ResponseInterface $response, \stdClass $args): ResponseInterface {
+		$lel[] = 'A';
+		$lel[] = 'B';
+		$lel[] = 'C';
+
+		$lal['t'] = 'A';
+		$lal['tt'] = 'B';
+		$lal['ttt'] = 'C';
+		$lal['tttt'] = 'D';
+
+		$lol['a'] = $lel;
+		$lol['b'] = $lal;
+
+		return $response->withJson($lol);
+	}
+
+	public function error(ServerRequestInterface $request, ResponseInterface $response, \stdClass $args): ResponseInterface {
+		throw new Error('Lol', 42);
+	}
+
+	public function devblog(ServerRequestInterface $request, ResponseInterface $response, \stdClass $args): ResponseInterface {
+		$blog = '
+			Ecconia\'s dusty server-machine
+			-	For this project the webserver owned by Ecconia has been started again and a fresh Ubuntu 18.04 has been installed.
+			-	Basic setup has been made, editing bash, setting up ssh and vim.
+
+			Sever software
+			-	Nginx shall be the server for this project, its easy to setup and all config files are at one place.
+
+			Security
+			-	All traffic will be routed over Cloudflare. The connections from and to Cloudflare are encrypted with SSL.
+			-	The connection is as secure as Cloudflare is (lets trust it...). Cloudflare mainly caches files and protects against DDOS.
+
+			Vue-Framework added to website
+			-	Vue is a framework which uses javascript to manipulate the HTML-DOM of the browser. This allows very easy web-developing.
+			-	Nice feature: Updating the website according to JS variables.
+			-	Downside: SEO may fail.
+
+			After reading millions of documentation
+			-	The first simple version of the website has been written, a single HTMl file contains the whole website.
+
+			Vue-Router
+			-	The website is using Vue-Router it allows natural page switching without actually doing so. The content will just be replaced by Vue.
+
+			The small steps
+			-	The start page as well as the application page shall function the same as on the current website. Additional this devblog has been added. An Impressum is a must have as soon as the server is located in germany.
+
+			Finally backend for frontend
+			-	Vue has "components" each mainpage is one, but later other parts of the website may be components (buttons, inputs, pager, posts etc....)
+			-	These components may be bundled and can be loaded on demand, this can be done by the frontend, by loading the components.
+			-	Webpack is a software which analyzes the source code on the server and bundles it as well as processes it. That way components can be bundled and provided. Additional this provides a fancy way to define components in single files. The code to load components will be generated by Webpack. Yay, less programming less mistakes.
+
+			Transfered everything to new backend
+			-	With the new backend a new website structure has been created. The old pages had been transfered to the correct positions in the new backend.
+			-	Now that the backend is working, the frontend may be developed.
+
+			Update for the devblog
+			-	The Development Blog got a new "design" and finally an update to its content.
+			-	One variable holds all the entries and will be parsed into a Vue entries array which are automatically visible when added.
+
+			Update introductions
+			-	Startpage and Devblog have been rewritten
+			';
+
+		$t = explode("\n", $blog);
+		$entries = [];
+		$entry['title'] = trim($t[1]);
+
+		for ($i = 2; $i < sizeof($t) - 1; $i++) {
+			$line = trim($t[$i]);
+			if($line === '') {
+				continue;
+			}
+
+			if($line[0] === '-') {
+				$line = trim(substr($line, 1));
+				$entry['paragraphs'][] = $line;
+			} else {
+				$entries[] = $entry;
+				$entry['paragraphs'] = [];
+				$entry['title'] = $line;
+			}
+		}
+
+		return $response->withJson($entries);
+	}
+
+	public function applications(ServerRequestInterface $request, ResponseInterface $response, \stdClass $args): ResponseInterface {
+		return $response->withJson(DummyData::getViewDummies());
+	}
+
+	public function dummies(ServerRequestInterface $request, ResponseInterface $response, \stdClass $args): ResponseInterface {
+		return $response->withJson(DummyData::getDummyData());
+	}
+
+	public function application(ServerRequestInterface $request, ResponseInterface $response, \stdClass $args): ResponseInterface {
+		$id = $args->id;
+
+		$a = DummyData::getDummyData();
+
+		if($id < 0 || sizeof($a) <= $id)
+		{
+			throw new InvalidRequestException('ID is Invalid', 400);
+		}
+
+		return $response->withJson($a[$id]);
+	}
+
+	public static function getRoutes(): array {
+		return [
+			new Route('GET', '/soos', 'soos'),
+			new Route('GET', '/error', 'error'),
+			new Route('GET', '/devblog', 'devblog'),
+			new Route('GET', '/applications', 'applications'),
+			new Route('GET', '/dummies', 'dummies'),
+			new Route('GET', '/application/{id:[0-9]+}', 'application'),
+		];
+	}
+}

+ 15 - 11
middleware/CorsHeader.php

@@ -1,21 +1,24 @@
 <?php
-	use \Psr\Http\Message\{
-		ServerRequestInterface,
-		ResponseInterface
-	};
 
-	class CorsHeader {
-		public function __invoke(ServerRequestInterface $request, ResponseInterface $response, callable $next) {
+namespace RS\Middleware;
 
-			$method = $_SERVER['REQUEST_METHOD'];
-			$origin = $_SERVER['HTTP_ORIGIN'];
+use \Psr\Http\Message\{
+	ServerRequestInterface,
+	ResponseInterface
+};
+
+class CorsHeader {
+	public function __invoke(ServerRequestInterface $request, ResponseInterface $response, callable $next) {
 
+		if(isset($_SERVER['HTTP_ORIGIN'])) {
+			$origin = $_SERVER['HTTP_ORIGIN'];
+			
 			if(in_array($origin, ['http://localhost:8080', 'https://vv.ecconia.de'])) {
 				header('Access-Control-Allow-Origin: ' . $origin);
 				header('Access-Control-Allow-Methods: GET, POST, OPTIONS');
 				header('Access-Control-Allow-Headers: DNT,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Range');
 
-				if($method == 'OPTIONS') {
+				if($_SERVER['REQUEST_METHOD'] == 'OPTIONS') {
 					header('Access-Control-Max-Age: 1728000');
 					header('Content-Type: text/plain charset=UTF-8');
 					header('Content-Length: 0');
@@ -23,7 +26,8 @@
 					return $response->withStatus(204);
 				}
 			}
-
-			return $next($request, $response);
 		}
+
+		return $next($request, $response);
 	}
+}

+ 11 - 0
src/User.php

@@ -0,0 +1,11 @@
+<?php
+
+namespace RS;
+
+class User {
+	public $username;
+
+	function __construct(string $username) {
+		$this->username = $username;
+	}
+}