Download core/app/Http/Controllers/User/ApiKeyController.php from pnacorp/codeplus: direct link, hf CLI and curl.
- Browser
- Download file 1.27 kB
-
https://huggingface.co/pnacorp/codeplus/resolve/main/core/app/Http/Controllers/User/ApiKeyController.php
- Command line
-
hf download hf://pnacorp/codeplus/core/app/Http/Controllers/User/ApiKeyController.php
-
curl -L -o ApiKeyController.php https://huggingface.co/pnacorp/codeplus/resolve/main/core/app/Http/Controllers/User/ApiKeyController.php
1.27 kB
| namespace App\Http\Controllers\User; | |
| use App\Models\ApiKey; | |
| use App\Constants\Status; | |
| use App\Http\Controllers\Controller; | |
| class ApiKeyController extends Controller | |
| { | |
| public function index() | |
| { | |
| $pageTitle = 'Api Documentation'; | |
| $user = auth()->user(); | |
| if (!$user->is_author) { | |
| $notify[] = ['error', 'Only author can allow to access']; | |
| return back()->withNotify($notify); | |
| } | |
| $apiKey = ApiKey::where('user_id', auth()->id())->where('status', Status::ACTIVE_KEY)->first(); | |
| return view('Template::user.api_key', compact('pageTitle', 'apiKey')); | |
| } | |
| public function keyGenerate() | |
| { | |
| $user = auth()->user(); | |
| $latestKey = ApiKey::where('user_id', $user->id)->where('status', Status::ACTIVE_KEY)->first(); | |
| if (@$latestKey) { | |
| $latestKey->status = Status::INACTIVE_KEY; | |
| $latestKey->save(); | |
| } | |
| $newKey = new ApiKey(); | |
| $newKey->user_id = $user->id; | |
| $newKey->key = generateApiKey(); | |
| $newKey->status = Status::ACTIVE_KEY; | |
| $newKey->save(); | |
| $notify[] = ['success', 'API key generated successfully']; | |
| return back()->withNotify($notify); | |
| } | |
| } | |