Ecconia 7 سال پیش
والد
کامیت
7966f286a0
4فایلهای تغییر یافته به همراه170 افزوده شده و 166 حذف شده
  1. 15 10
      dist/index.php
  2. 27 27
      src/Handler/AuthHandler.php
  3. 105 106
      src/Handler/MyHandler.php
  4. 23 23
      src/Middleware/CorsHeader.php

+ 15 - 10
dist/index.php

@@ -1,14 +1,19 @@
 <?php
-	require __DIR__ . '/../vendor/autoload.php';
 
-	use RS\Middleware\CorsHeader;
+ini_set('display_errors', 1);
+ini_set('display_startup_errors', 1);
+error_reporting(E_ALL);
 
-	use Adepto\Slim3Init\SlimInit;
+require __DIR__ . '/../vendor/autoload.php';
 
-	$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();
+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();

+ 27 - 27
src/Handler/AuthHandler.php

@@ -1,39 +1,39 @@
 <?php
-	use Adepto\Slim3Init\HandlerCaller;
 
-	use Adepto\Slim3Init\Handlers\{
-		Handler,
-		Route
-	};
+use Adepto\Slim3Init\HandlerCaller;
 
-	use Psr\Http\Message\{
-		ServerRequestInterface,
-		ResponseInterface
-	};
+use Adepto\Slim3Init\Handlers\{
+	Handler,
+	Route
+};
 
-	class AuthHandler extends Handler {
-		public function login(ServerRequestInterface $request, ResponseInterface $response, \stdClass $args): ResponseInterface {
+use Psr\Http\Message\{
+	ServerRequestInterface,
+	ResponseInterface
+};
 
-			$parsedBody = $request->getParsedBody();
+class AuthHandler extends Handler {
+	public function login(ServerRequestInterface $request, ResponseInterface $response, \stdClass $args): ResponseInterface {
+		$parsedBody = $request->getParsedBody();
 
-			$username = $parsedBody['username'];
-			$password = $parsedBody['password'];
+		$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: 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.
+		//TODO: Check username for allowed chars and length.
 
-			$user['username'] = $username;
-			$user['appstate'] = 0;
+		$user['username'] = $username;
+		$user['appstate'] = 0;
 
-			return $response->withJson($user);
-		}
+		return $response->withJson($user);
+	}
 
-		public static function getRoutes(): array {
-			return [
-				new Route('POST', '/login', 'login'),
-			];
-		}
+	public static function getRoutes(): array {
+		return [
+			new Route('POST', '/login', 'login'),
+		];
 	}
+}

+ 105 - 106
src/Handler/MyHandler.php

@@ -1,123 +1,122 @@
 <?php
-	use Adepto\Slim3Init\HandlerCaller;
 
-	use Adepto\Slim3Init\Handlers\{
-		Handler,
-		Route
-	};
+use Adepto\Slim3Init\HandlerCaller;
 
-	use Psr\Http\Message\{
-		ServerRequestInterface,
-		ResponseInterface
-	};
+use Adepto\Slim3Init\Handlers\{
+	Handler,
+	Route
+};
 
-	use RS\DummyData;
+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';
+use RS\DummyData;
 
-			$lal['t'] = 'A';
-			$lal['tt'] = 'B';
-			$lal['ttt'] = 'C';
-			$lal['tttt'] = 'D';
+class MyHandler extends Handler {
+	public function soos(ServerRequestInterface $request, ResponseInterface $response, \stdClass $args): ResponseInterface {
+		$lel[] = 'A';
+		$lel[] = 'B';
+		$lel[] = 'C';
 
-			$lol['a'] = $lel;
-			$lol['b'] = $lal;
+		$lal['t'] = 'A';
+		$lal['tt'] = 'B';
+		$lal['ttt'] = 'C';
+		$lal['tttt'] = 'D';
 
-			return $response->withJson($lol);
-		}
+		$lol['a'] = $lel;
+		$lol['b'] = $lal;
 
-		public function error(ServerRequestInterface $request, ResponseInterface $response, \stdClass $args): ResponseInterface {
-			throw new Error('Lol', 42);
-		}
+		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.
 
-		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;
-				}
+			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;
 			}
 
-			return $response->withJson($entries);
+			if($line[0] === '-') {
+				$line = trim(substr($line, 1));
+				$entry['paragraphs'][] = $line;
+			} else {
+				$entries[] = $entry;
+				$entry['paragraphs'] = [];
+				$entry['title'] = $line;
+			}
 		}
 
-		public function applications(ServerRequestInterface $request, ResponseInterface $response, \stdClass $args): ResponseInterface {
-			$applications = [];
-			return $response->withJson(DummyData::getViewDummies());
-		}
+		return $response->withJson($entries);
+	}
 
-		public function dummies(ServerRequestInterface $request, ResponseInterface $response, \stdClass $args): ResponseInterface {
-			return $response->withJson(DummyData::getDummyData());
-		}
+	public function applications(ServerRequestInterface $request, ResponseInterface $response, \stdClass $args): ResponseInterface {
+		return $response->withJson(DummyData::getViewDummies());
+	}
 
-		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'),
-			];
-		}
+	public function dummies(ServerRequestInterface $request, ResponseInterface $response, \stdClass $args): ResponseInterface {
+		return $response->withJson(DummyData::getDummyData());
+	}
+
+	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'),
+		];
 	}
+}

+ 23 - 23
src/Middleware/CorsHeader.php

@@ -1,33 +1,33 @@
 <?php
 
-	namespace RS\Middleware;
-	
-	use \Psr\Http\Message\{
-		ServerRequestInterface,
-		ResponseInterface
-	};
+namespace RS\Middleware;
 
-	class CorsHeader {
-		public function __invoke(ServerRequestInterface $request, ResponseInterface $response, callable $next) {
+use \Psr\Http\Message\{
+	ServerRequestInterface,
+	ResponseInterface
+};
 
-			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');
+class CorsHeader {
+	public function __invoke(ServerRequestInterface $request, ResponseInterface $response, callable $next) {
 
-					if($_SERVER['REQUEST_METHOD'] == 'OPTIONS') {
-						header('Access-Control-Max-Age: 1728000');
-						header('Content-Type: text/plain charset=UTF-8');
-						header('Content-Length: 0');
+		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');
 
-						return $response->withStatus(204);
-					}
+				if($_SERVER['REQUEST_METHOD'] == 'OPTIONS') {
+					header('Access-Control-Max-Age: 1728000');
+					header('Content-Type: text/plain charset=UTF-8');
+					header('Content-Length: 0');
+
+					return $response->withStatus(204);
 				}
 			}
-
-			return $next($request, $response);
 		}
+
+		return $next($request, $response);
 	}
+}