diff --git a/app/Http/Controllers/Api/Web/AccountController.php b/app/Http/Controllers/Api/Web/AccountController.php index 815ecb1a..4f20726d 100644 --- a/app/Http/Controllers/Api/Web/AccountController.php +++ b/app/Http/Controllers/Api/Web/AccountController.php @@ -23,6 +23,7 @@ namespace Poniverse\Ponyfm\Http\Controllers\Api\Web; use Poniverse\Ponyfm\Http\Controllers\ApiControllerBase; use Poniverse\Ponyfm\Commands\SaveAccountSettingsCommand; use Poniverse\Ponyfm\Models\User; +use Poniverse\Ponyfm\Models\Image; use Gate; use Auth; use Request; @@ -39,6 +40,33 @@ class AccountController extends ApiControllerBase ]); } + public function getCurrentUser() { + $current_user = Auth::user(); + + if ($current_user != null) { + $user = User::where('id', $current_user->id)->whereNull('disabled_at')->first(); + + if ($user == null) { + return Response::json(['error' => 'You are not logged in'], 404); + } + + return Response::json([ + 'id' => $user->id, + 'name' => $user->display_name, + 'slug' => $user->slug, + 'url' => $user->url, + 'is_archived' => $user->is_archived, + 'avatars' => [ + 'small' => $user->getAvatarUrl(Image::SMALL), + 'normal' => $user->getAvatarUrl(Image::NORMAL) + ], + 'created_at' => $user->created_at + ], 200); + } else { + return Response::json(['error' => 'You are not logged in'], 404); + } + } + public function getSettings($slug) { $user = null; diff --git a/routes/web.php b/routes/web.php index 53d63d0c..751fc104 100644 --- a/routes/web.php +++ b/routes/web.php @@ -214,6 +214,7 @@ Route::group(['prefix' => 'api/web'], function () { Route::delete('/announcements/{id}', 'Api\Web\AnnouncementsController@deleteItem')->where('id', '\d+'); }); + Route::get('/auth/current', 'Api\Web\AccountController@getCurrentUser'); Route::post('/auth/logout', 'Api\Web\AuthController@postLogout'); });