Переглянути джерело

Adding primitive login handler

It accepts anything, will be enhanced with more dummies and later real auth.
Ecconia 7 роки тому
батько
коміт
ce8e378890
1 змінених файлів з 39 додано та 0 видалено
  1. 39 0
      handler/AuthHandler.php

+ 39 - 0
handler/AuthHandler.php

@@ -0,0 +1,39 @@
+<?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'),
+			];
+		}
+	}