AuthHandler.php 929 B

123456789101112131415161718192021222324252627282930313233343536373839
  1. <?php
  2. use Adepto\Slim3Init\HandlerCaller;
  3. use Adepto\Slim3Init\{
  4. Handlers\Handler,
  5. Handlers\Route
  6. };
  7. use Psr\Http\Message\{
  8. ServerRequestInterface,
  9. ResponseInterface
  10. };
  11. class AuthHandler extends Handler {
  12. public function login(ServerRequestInterface $request, ResponseInterface $response, \stdClass $args): ResponseInterface {
  13. $parsedBody = $request->getParsedBody();
  14. $username = $parsedBody['username'];
  15. $password = $parsedBody['password'];
  16. //TODO: Confirm that someone is not sending garbage.
  17. // - There may only be the keys username and password - optional token
  18. // - None of the two/three fields may be empty.
  19. //TODO: Check username for allowed chars and length.
  20. $user['username'] = $username;
  21. $user['appstate'] = 0;
  22. return $response->withJson($user);
  23. }
  24. public static function getRoutes(): array {
  25. return [
  26. new Route('POST', '/login', 'login'),
  27. ];
  28. }
  29. }