mirror of
https://github.com/Poniverse/Pony.fm.git
synced 2024-11-22 04:58:01 +01:00
Added API to get logged in user
This commit is contained in:
parent
8c7fe0ea33
commit
b163d70e9c
2 changed files with 29 additions and 0 deletions
|
@ -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;
|
||||
|
|
|
@ -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');
|
||||
});
|
||||
|
||||
|
|
Loading…
Reference in a new issue