model = $model; } /** * From given email address and password, authenticate the user and respond with its authorization token. * @return HttpResponse */ public function authorize(): HttpResponse { return Control::runChecked([ "email" => [DefaultValidators::email(), DefaultValidators::lenBetween(5, 256)], "password" => [DefaultValidators::lenBetween(6, 256)], ], function (HttpRequest $req) { $failures = []; $account = $this->model->login($req["email"], $req["password"], $failures); if (!empty($failures)) { return new JsonHttpResponse($failures, HttpCodes::UNAUTHORIZED); } return new JsonHttpResponse(["authorization" => $account->getToken()]); }); } }