diff options
Diffstat (limited to 'src/Controllers/LoginController.php')
-rw-r--r-- | src/Controllers/LoginController.php | 25 |
1 files changed, 24 insertions, 1 deletions
diff --git a/src/Controllers/LoginController.php b/src/Controllers/LoginController.php index f5ca3be..d48628b 100644 --- a/src/Controllers/LoginController.php +++ b/src/Controllers/LoginController.php @@ -2,6 +2,8 @@ namespace App\Controllers; +use App\Errors\UnknownError; +use App\Support\Parser; use App\Types\LoginFlow; use App\Types\LoginType; use Symfony\Component\HttpFoundation\Request; @@ -10,6 +12,10 @@ use Symfony\Component\HttpFoundation\JsonResponse; class LoginController { + /** + * GET /_matrix/client/r0/login + * GET /_matrix/client/v3/login + */ public function supportedLoginTypes(): Response { return new JsonResponse([ @@ -19,16 +25,33 @@ class LoginController ]); } + /** + * POST /_matrix/client/v3/login + */ public function login(): Response { $request = Request::createFromGlobals(); + $content = json_decode($request->getContent(), true); + + // validate login type + $loginType = null; + try { + $loginType = LoginType::from($content["type"]); + } catch (\ValueError $error) { + throw new UnknownError("Bad login type.", Response::HTTP_BAD_REQUEST); + } + + // get user name + $user = Parser::parseUser($content["identifier"]["user"]); + + #if ($loginType == LoginType::PASSWORD) {} return new JsonResponse([ "access_token" => "abc123", "device_id" => "ABC", "expires_in_ms" => 60000, "refresh_token" => "def456", - "user_id" => "@php:localhost", + "user_id" => "@{$user["username"]}:{$_ENV["DOMAIN"]}", #"well_known" => [], ]); } |