| 123456789101112131415161718192021222324252627282930313233343536373839 |
- <?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'),
- ];
- }
- }
|