From be7eae8494128ca8f4465a02c4333e7b4bd290dc Mon Sep 17 00:00:00 2001 From: Daniel Supernault Date: Thu, 26 Sep 2019 19:52:56 -0600 Subject: [PATCH] Update verify_credentials endpoint --- app/Http/Controllers/Api/ApiV1Controller.php | 28 ++++++++++++++++++++ routes/web.php | 2 +- 2 files changed, 29 insertions(+), 1 deletion(-) diff --git a/app/Http/Controllers/Api/ApiV1Controller.php b/app/Http/Controllers/Api/ApiV1Controller.php index d758a959..ac6090e5 100644 --- a/app/Http/Controllers/Api/ApiV1Controller.php +++ b/app/Http/Controllers/Api/ApiV1Controller.php @@ -89,6 +89,34 @@ class ApiV1Controller extends Controller return $res; } + /** + * GET /api/v1/accounts/verify_credentials + * + * + * @return \App\Transformer\Api\AccountTransformer + */ + public function verifyCredentials(Request $request) + { + abort_if(!$request->user(), 403); + $id = $request->user()->id; + + $res = Cache::remember('mastoapi:user:account:id:'.$id, now()->addHours(6), function() use($id) { + $profile = Profile::whereNull('status')->whereUserId($id)->firstOrFail(); + $resource = new Fractal\Resource\Item($profile, new AccountTransformer()); + $res = $this->fractal->createData($resource)->toArray(); + $res['source'] = [ + 'privacy' => $profile->is_private ? 'private' : 'public', + 'sensitive' => $profile->cw ? true : false, + 'language' => 'en', + 'note' => '', + 'fields' => [] + ]; + return $res; + }); + + return response()->json($res); + } + /** * GET /api/v1/accounts/{id} * diff --git a/routes/web.php b/routes/web.php index 3803c930..2dd34256 100644 --- a/routes/web.php +++ b/routes/web.php @@ -77,7 +77,7 @@ Route::domain(config('pixelfed.domain.app'))->middleware(['validemail', 'twofact Route::get('nodeinfo/2.0.json', 'FederationController@nodeinfo'); Route::group(['prefix' => 'v1'], function () { - Route::get('accounts/verify_credentials', 'ApiController@verifyCredentials')->middleware('auth:api'); + Route::get('accounts/verify_credentials', 'Api\ApiV1Controller@verifyCredentials')->middleware('auth:api'); Route::patch('accounts/update_credentials', 'Api\ApiV1Controller@accountUpdateCredentials')->middleware('auth:api'); Route::get('accounts/relationships', 'Api\ApiV1Controller@accountRelationshipsById')->middleware('auth:api'); Route::get('accounts/search', 'Api\ApiV1Controller@accountSearch')->middleware('auth:api');