Update verify_credentials endpoint

This commit is contained in:
Daniel Supernault 2019-09-26 19:52:56 -06:00
parent 0b0bf59dd9
commit be7eae8494
No known key found for this signature in database
GPG key ID: 0DEF1C662C9033F7
2 changed files with 29 additions and 1 deletions

View file

@ -89,6 +89,34 @@ class ApiV1Controller extends Controller
return $res; 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} * GET /api/v1/accounts/{id}
* *

View file

@ -77,7 +77,7 @@ Route::domain(config('pixelfed.domain.app'))->middleware(['validemail', 'twofact
Route::get('nodeinfo/2.0.json', 'FederationController@nodeinfo'); Route::get('nodeinfo/2.0.json', 'FederationController@nodeinfo');
Route::group(['prefix' => 'v1'], function () { 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::patch('accounts/update_credentials', 'Api\ApiV1Controller@accountUpdateCredentials')->middleware('auth:api');
Route::get('accounts/relationships', 'Api\ApiV1Controller@accountRelationshipsById')->middleware('auth:api'); Route::get('accounts/relationships', 'Api\ApiV1Controller@accountRelationshipsById')->middleware('auth:api');
Route::get('accounts/search', 'Api\ApiV1Controller@accountSearch')->middleware('auth:api'); Route::get('accounts/search', 'Api\ApiV1Controller@accountSearch')->middleware('auth:api');