Fix #127 Move the API Key management form to a specific page

This commit is contained in:
Timothée Jaussoin 2023-10-05 15:42:15 +02:00
parent e996a9827c
commit ab6aa88b3c
6 changed files with 83 additions and 33 deletions

View file

@ -43,14 +43,6 @@ class AccountController extends Controller
]);
}
public function generateApiKey(Request $request)
{
$account = $request->user();
$account->generateApiKey();
return redirect()->back();
}
public function store(CreateAccountRequest $request)
{
$account = (new AccountService(api: false))->store($request);

View file

@ -0,0 +1,41 @@
<?php
/*
Flexisip Account Manager is a set of tools to manage SIP accounts.
Copyright (C) 2020 Belledonne Communications SARL, All rights reserved.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
namespace App\Http\Controllers\Account;
use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
class ApiKeyController extends Controller
{
public function show(Request $request)
{
return view('account.api_key', [
'account' => $request->user()
]);
}
public function update(Request $request)
{
$account = $request->user();
$account->generateApiKey();
return redirect()->back();
}
}

View file

@ -0,0 +1,26 @@
@extends('layouts.main', ['grid' => true])
@section('content')
<header>
<h1><i class="material-icons-outlined">dashboard</i> Dashboard</h1>
</header>
<div class="large">
<h2><i class="material-icons-outlined">key</i>API Key</h2>
<p>You can generate an API key and use it to request the different API endpoints, <a href="{{ route('api') }}">check
the related API documentation</a> to know how to use that key.</p>
<form method="POST" action="{{ route('account.api_key.update') }}" accept-charset="UTF-8">
@csrf
<div>
<input readonly placeholder="No key yet, press Generate"
@if ($account->apiKey) value="{{ $account->apiKey->key }}" @endif>
<label>Key</label>
</div>
<div>
<button type="submit" class="btn btn-primary">Generate</button>
</div>
</form>
</div>
@endsection

View file

@ -28,7 +28,7 @@
</p>
<p>
<i class="material-icons-outlined">lock</i>
<a href="{{ route('account.password') }}">
<a href="{{ route('account.password.show') }}">
@if ($account->passwords()->count() > 0)
Change my password
@else
@ -37,6 +37,13 @@
</a>
</p>
<p>
<i class="material-icons-outlined">key</i>
<a href="{{ route('account.api_key.show') }}">
API Key Management
</a>
</p>
<p>
<i class="material-icons-outlined">delete</i>
<a href="{{ route('account.delete') }}">Delete my account</a>
@ -75,25 +82,5 @@
</div>
<div class="large">
<h2><i class="material-icons-outlined">key</i>API Key</h2>
<p>You can generate an API key and use it to request the different API endpoints, <a href="{{ route('api') }}">check
the related API documentation</a> to know how to use that key.</p>
<form method="POST" action="{{ route('account.api_key.generate') }}" accept-charset="UTF-8">
@csrf
<div>
<input readonly placeholder="No key yet, press Generate"
@if ($account->apiKey) value="{{ $account->apiKey->key }}" @endif>
<label>Key</label>
</div>
<div>
<button type="submit" class="btn btn-primary">Generate</button>
</div>
</form>
</div>
@include('parts.account_variables', ['account' => $account])
@endsection

View file

@ -56,7 +56,7 @@ You can @if (config('app.web_panel')) [change your email address]({{ route('acco
## Change your password
Your password can also be changed from the @if (config('app.web_panel')) [password change form]({{ route('account.password') }}) @else password change form @endif. You can enable SHA-256 encrypted password when changing it (required for some clients).
Your password can also be changed from the @if (config('app.web_panel')) [password change form]({{ route('account.password.show') }}) @else password change form @endif. You can enable SHA-256 encrypted password when changing it (required for some clients).
## Delete your account

View file

@ -18,6 +18,7 @@
*/
use App\Http\Controllers\Account\AccountController;
use App\Http\Controllers\Account\ApiKeyController;
use App\Http\Controllers\Account\CreationRequestTokenController;
use App\Http\Controllers\Account\EmailController;
use App\Http\Controllers\Account\PasswordController;
@ -107,8 +108,6 @@ if (config('app.web_panel')) {
Route::controller(AccountController::class)->group(function () {
Route::get('dashboard', 'panel')->name('account.dashboard');
Route::post('api_key', 'generateApiKey')->name('account.api_key.generate');
Route::get('delete', 'delete')->name('account.delete');
Route::delete('delete', 'destroy')->name('account.destroy');
});
@ -116,10 +115,15 @@ if (config('app.web_panel')) {
Route::get('logout', 'Account\AuthenticateController@logout')->name('account.logout');
Route::prefix('password')->controller(PasswordController::class)->group(function () {
Route::get('/', 'show')->name('account.password');
Route::get('/', 'show')->name('account.password.show');
Route::post('/', 'update')->name('account.password.update');
});
Route::prefix('api_key')->controller(ApiKeyController::class)->group(function () {
Route::get('/', 'show')->name('account.api_key.show');
Route::post('/', 'update')->name('account.api_key.update');
});
Route::post('auth_tokens', 'Account\AuthTokenController@create')->name('account.auth_tokens.create');
Route::get('auth_tokens/auth/external/{token}', 'Account\AuthTokenController@authExternal')->name('auth_tokens.auth.external');