Add route and action for uploading user avatars.

This commit is contained in:
Franz Liedke 2015-03-25 14:26:17 +01:00
parent a1f723671d
commit 100a5038bf
2 changed files with 26 additions and 0 deletions

View File

@ -0,0 +1,21 @@
<?php namespace Flarum\Api\Actions\Users;
use Flarum\Api\Actions\BaseAction;
use Flarum\Core\Commands\UploadAvatarCommand;
use Illuminate\Http\Request;
class UploadAvatarAction extends BaseAction
{
public function handle(Request $request, $routeParams = [])
{
$userId = array_get($routeParams, 'id');
$file = $request->file('avatar');
$this->dispatch(
new UploadAvatarCommand($userId, $this->actor->getUser(), $file),
$routeParams
);
return $this->respondWithoutContent(201);
}
}

View File

@ -59,6 +59,11 @@ Route::group(['prefix' => 'api', 'middleware' => 'Flarum\Api\Middleware\LoginWit
'uses' => $action('Flarum\Api\Actions\Users\DeleteAction')
]);
Route::post('users/{id}/avatar', [
'as' => 'flarum.api.users.avatar.upload',
'uses' => $action('Flarum\Api\Actions\Users\UploadAvatarAction')
]);
/*
|--------------------------------------------------------------------------
| Activity