Added API to get logged in user

This commit is contained in:
Josef Citrine 2017-01-02 03:33:21 +00:00
parent 8c7fe0ea33
commit b163d70e9c
2 changed files with 29 additions and 0 deletions

View file

@ -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;

View file

@ -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');
});