diff --git a/framework/core/src/Api/Actions/TokenAction.php b/framework/core/src/Api/Actions/TokenAction.php index 96ac6108f..bc2ad3f2d 100644 --- a/framework/core/src/Api/Actions/TokenAction.php +++ b/framework/core/src/Api/Actions/TokenAction.php @@ -1,15 +1,17 @@ users = $users; @@ -19,21 +21,25 @@ class TokenAction extends BaseAction /** * Log in and return a token. * - * @return Response + * @param \Flarum\Api\Request $request + * @return \Flarum\Api\Response */ - public function run(ApiParams $params) + public function handle(Request $request) { - $identification = $params->get('identification'); - $password = $params->get('password'); + $identification = $request->get('identification'); + $password = $request->get('password'); $user = $this->users->findByIdentification($identification); if (! $user || ! $user->checkPassword($password)) { - return $this->respondWithError('invalidCredentials', 401); + return; + // throw an exception + // return $this->respondWithError('invalidCredentials', 401); } - $command = new GenerateAccessTokenCommand($user->id); - $token = $this->dispatch($command, $params); + $token = $this->bus->dispatch( + new GenerateAccessTokenCommand($user->id) + ); return new JsonResponse([ 'token' => $token->id, diff --git a/framework/core/src/Api/Request.php b/framework/core/src/Api/Request.php index d5579226a..e6a754822 100644 --- a/framework/core/src/Api/Request.php +++ b/framework/core/src/Api/Request.php @@ -11,7 +11,7 @@ class Request public $http; - public function __construct(array $input, Actor $actor, IlluminateRequest $http = null) + public function __construct(array $input, Actor $actor = null, IlluminateRequest $http = null) { $this->input = $input; $this->actor = $actor; diff --git a/framework/core/src/Forum/Actions/LoginAction.php b/framework/core/src/Forum/Actions/LoginAction.php index f4f55a7f3..b245bdd60 100644 --- a/framework/core/src/Forum/Actions/LoginAction.php +++ b/framework/core/src/Forum/Actions/LoginAction.php @@ -3,6 +3,7 @@ use Illuminate\Http\Request; use Flarum\Forum\Events\UserLoggedIn; use Flarum\Core\Repositories\UserRepositoryInterface; +use Flarum\Api\Request as ApiRequest; class LoginAction extends BaseAction { @@ -17,7 +18,8 @@ class LoginAction extends BaseAction public function handle(Request $request, $routeParams = []) { - $response = $this->callAction('Flarum\Api\Actions\TokenAction', $request->only('identification', 'password')); + $response = app('Flarum\Api\Actions\TokenAction') + ->handle(new ApiRequest($request->only('identification', 'password'))); $data = $response->getData(); if (! empty($data->token)) {