-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
f6d5127
commit 36ba833
Showing
3 changed files
with
73 additions
and
0 deletions.
There are no files selected for viewing
64 changes: 64 additions & 0 deletions
64
app/Http/Controllers/API/Settings/AccessTokenController.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
<?php | ||
|
||
namespace App\Http\Controllers\API\Settings; | ||
|
||
use App\Http\Controllers\Controller; | ||
use App\Models\AccessToken; | ||
use Illuminate\Http\JsonResponse; | ||
use Illuminate\Http\Request; | ||
use Illuminate\Support\Str; | ||
|
||
class AccessTokenController extends Controller | ||
{ | ||
/** | ||
* List users access tokens | ||
* | ||
* @return JsonResponse | ||
*/ | ||
public function index() | ||
{ | ||
return auth('api')->user() | ||
->accessTokens() | ||
->get(); | ||
} | ||
|
||
/** | ||
* Create access tokens | ||
* | ||
* @return JsonResponse | ||
*/ | ||
public function create(Request $request) | ||
{ | ||
$token = Str::uuid(); | ||
AccessToken::create([ | ||
'user_id' => auth('api')->user()->id, | ||
'name' => $request->name, | ||
'token' => $token, | ||
'ip_range' => $request->ip_range, | ||
]); | ||
|
||
return response()->json([ | ||
'token' => $token | ||
]); | ||
} | ||
|
||
/** | ||
* Revoke access tokens | ||
* | ||
* @return JsonResponse | ||
*/ | ||
public function delete(Request $request) | ||
{ | ||
$token = AccessToken::find($request->token_id); | ||
if (! $token || $token->user_id != user()->id) { | ||
return response()->json([ | ||
'message' => 'Anahtar bulunamadı.' | ||
], 404); | ||
} | ||
$token->delete(); | ||
|
||
return response()->json([ | ||
'message' => 'Anahtar başarıyla silindi.' | ||
]); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,4 +21,6 @@ class AccessToken extends Model | |
'last_used_ip', | ||
'ip_range', | ||
]; | ||
|
||
protected $hidden = ["token"]; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters